| [9091] | 1 | /* | 
|---|
|  | 2 | *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
|  | 3 | *                    > www.orxonox.net < | 
|---|
|  | 4 | * | 
|---|
|  | 5 | * | 
|---|
|  | 6 | *   License notice: | 
|---|
|  | 7 | * | 
|---|
|  | 8 | *   This program is free software; you can redistribute it and/or | 
|---|
|  | 9 | *   modify it under the terms of the GNU General Public License | 
|---|
|  | 10 | *   as published by the Free Software Foundation; either version 2 | 
|---|
|  | 11 | *   of the License, or (at your option) any later version. | 
|---|
|  | 12 | * | 
|---|
|  | 13 | *   This program is distributed in the hope that it will be useful, | 
|---|
|  | 14 | *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 15 | *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 16 | *   GNU General Public License for more details. | 
|---|
|  | 17 | * | 
|---|
|  | 18 | *   You should have received a copy of the GNU General Public License | 
|---|
|  | 19 | *   along with this program; if not, write to the Free Software | 
|---|
|  | 20 | *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
|  | 21 | * | 
|---|
|  | 22 | *   Author: | 
|---|
|  | 23 | *      Johannes Ritz | 
|---|
|  | 24 | *   Co-authors: | 
|---|
|  | 25 | *      ... | 
|---|
|  | 26 | * | 
|---|
|  | 27 | */ | 
|---|
|  | 28 |  | 
|---|
|  | 29 | /** | 
|---|
|  | 30 | @file TetrisScore.cc | 
|---|
|  | 31 | @brief Implementation of the TetrisScore class. | 
|---|
| [9092] | 32 | @ingroup Tetris | 
|---|
| [9091] | 33 | */ | 
|---|
|  | 34 |  | 
|---|
|  | 35 | #include "TetrisScore.h" | 
|---|
|  | 36 |  | 
|---|
|  | 37 | #include "core/CoreIncludes.h" | 
|---|
|  | 38 | #include "core/XMLPort.h" | 
|---|
|  | 39 | #include "util/Convert.h" | 
|---|
|  | 40 |  | 
|---|
|  | 41 | #include "infos/PlayerInfo.h" | 
|---|
|  | 42 |  | 
|---|
|  | 43 | #include "Tetris.h" | 
|---|
|  | 44 |  | 
|---|
|  | 45 | namespace orxonox | 
|---|
|  | 46 | { | 
|---|
| [9667] | 47 | RegisterClass(TetrisScore); | 
|---|
| [9091] | 48 |  | 
|---|
|  | 49 | /** | 
|---|
|  | 50 | @brief | 
|---|
|  | 51 | Constructor. Registers and initializes the object. | 
|---|
| [9092] | 52 | @ingroup Tetris | 
|---|
| [9091] | 53 | */ | 
|---|
| [9667] | 54 | TetrisScore::TetrisScore(Context* context) : OverlayText(context) | 
|---|
| [9091] | 55 | { | 
|---|
|  | 56 | RegisterObject(TetrisScore); | 
|---|
|  | 57 |  | 
|---|
|  | 58 | this->owner_ = 0; | 
|---|
|  | 59 | this->player_ = NULL; | 
|---|
|  | 60 | } | 
|---|
|  | 61 |  | 
|---|
|  | 62 | /** | 
|---|
|  | 63 | @brief | 
|---|
|  | 64 | Destructor. | 
|---|
|  | 65 | */ | 
|---|
|  | 66 | TetrisScore::~TetrisScore() | 
|---|
|  | 67 | { | 
|---|
|  | 68 | } | 
|---|
|  | 69 |  | 
|---|
|  | 70 | /** | 
|---|
|  | 71 | @brief | 
|---|
|  | 72 | Method to create a TetrisScore through XML. | 
|---|
|  | 73 | */ | 
|---|
|  | 74 | void TetrisScore::XMLPort(Element& xmlelement, XMLPort::Mode mode) | 
|---|
|  | 75 | { | 
|---|
|  | 76 | SUPER(TetrisScore, XMLPort, xmlelement, mode); | 
|---|
|  | 77 | } | 
|---|
|  | 78 |  | 
|---|
|  | 79 | /** | 
|---|
|  | 80 | @brief | 
|---|
|  | 81 | Is called each tick. | 
|---|
|  | 82 | Creates and sets the caption to be displayed by the TetrisScore. | 
|---|
|  | 83 | @param dt | 
|---|
|  | 84 | The time that has elapsed since the last tick. | 
|---|
|  | 85 | */ | 
|---|
|  | 86 | void TetrisScore::tick(float dt) | 
|---|
|  | 87 | { | 
|---|
|  | 88 | SUPER(TetrisScore, tick, dt); | 
|---|
|  | 89 |  | 
|---|
|  | 90 | // If the owner is set. The owner being a Tetris game. | 
|---|
|  | 91 | if (this->owner_ != NULL) | 
|---|
|  | 92 | { | 
|---|
|  | 93 | std::string score("0"); | 
|---|
| [9945] | 94 | if(!this->owner_->hasEnded()) | 
|---|
| [9091] | 95 | { | 
|---|
|  | 96 | //get the player | 
|---|
|  | 97 | player_ = this->owner_->getPlayer(); | 
|---|
|  | 98 | } | 
|---|
|  | 99 |  | 
|---|
|  | 100 | if(this->owner_->hasStarted()) | 
|---|
|  | 101 | { | 
|---|
|  | 102 | // Save the name and score of each player as a string. | 
|---|
|  | 103 | if (player_ != NULL) | 
|---|
|  | 104 | score = multi_cast<std::string>(this->owner_->getScore(player_)); | 
|---|
|  | 105 | } | 
|---|
|  | 106 | this->setCaption(score); | 
|---|
|  | 107 | } | 
|---|
|  | 108 | } | 
|---|
|  | 109 |  | 
|---|
|  | 110 | /** | 
|---|
|  | 111 | @brief | 
|---|
|  | 112 | Is called when the owner changes. | 
|---|
|  | 113 | Sets the owner to NULL, if it is not a pointer to a Tetris game. | 
|---|
|  | 114 | */ | 
|---|
|  | 115 | void TetrisScore::changedOwner() | 
|---|
|  | 116 | { | 
|---|
|  | 117 | SUPER(TetrisScore, changedOwner); | 
|---|
|  | 118 |  | 
|---|
|  | 119 | if (this->getOwner() != NULL && this->getOwner()->getGametype()) | 
|---|
|  | 120 | this->owner_ = orxonox_cast<Tetris*>(this->getOwner()->getGametype().get()); | 
|---|
|  | 121 | else | 
|---|
|  | 122 | this->owner_ = 0; | 
|---|
|  | 123 | } | 
|---|
|  | 124 | } | 
|---|