[11503] | 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: |
---|
[11624] | 23 | * Leo Merholz |
---|
| 24 | * Pascal Schärli |
---|
[11503] | 25 | * |
---|
[11624] | 26 | * Co-authors: |
---|
| 27 | * ... |
---|
[11503] | 28 | */ |
---|
| 29 | |
---|
| 30 | #include "FlappyOrxHUDinfo.h" |
---|
| 31 | |
---|
| 32 | #include "core/CoreIncludes.h" |
---|
| 33 | #include "core/XMLPort.h" |
---|
| 34 | #include "util/Convert.h" |
---|
| 35 | #include "FlappyOrx.h" |
---|
| 36 | |
---|
| 37 | namespace orxonox |
---|
| 38 | { |
---|
| 39 | RegisterClass(FlappyOrxHUDinfo); |
---|
| 40 | |
---|
| 41 | FlappyOrxHUDinfo::FlappyOrxHUDinfo(Context* context) : OverlayText(context) |
---|
| 42 | { |
---|
| 43 | RegisterObject(FlappyOrxHUDinfo); |
---|
| 44 | |
---|
| 45 | this->FlappyOrxGame = nullptr; |
---|
| 46 | this->bShowLives_ = false; |
---|
[11533] | 47 | this->bShowLevel_ = true; |
---|
[11503] | 48 | this->bShowPoints_ = false; |
---|
| 49 | this->bShowMultiplier_ = false; |
---|
[11563] | 50 | this->bShowGameOver_ = false; |
---|
| 51 | this->sGameOverMessage_ = ""; |
---|
[11503] | 52 | } |
---|
| 53 | |
---|
| 54 | void FlappyOrxHUDinfo::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 55 | { |
---|
| 56 | SUPER(FlappyOrxHUDinfo, XMLPort, xmlelement, mode); |
---|
| 57 | |
---|
[11563] | 58 | XMLPortParam(FlappyOrxHUDinfo, "showpoints", setShowPoints, getShowPoints, xmlelement, mode).defaultValues(false); |
---|
| 59 | XMLPortParam(FlappyOrxHUDinfo, "showmessage", setShowMessage, getShowMessage, xmlelement, mode).defaultValues(false); |
---|
[11576] | 60 | XMLPortParam(FlappyOrxHUDinfo, "messageID", setMessageID, getMessageID, xmlelement, mode).defaultValues(0); |
---|
[11533] | 61 | |
---|
| 62 | |
---|
[11503] | 63 | } |
---|
| 64 | |
---|
| 65 | void FlappyOrxHUDinfo::tick(float dt) |
---|
| 66 | { |
---|
| 67 | SUPER(FlappyOrxHUDinfo, tick, dt); |
---|
| 68 | |
---|
| 69 | if (this->FlappyOrxGame) |
---|
| 70 | { |
---|
[11565] | 71 | if(not this->FlappyOrxGame->isDead()){ |
---|
| 72 | if(this->bShowPoints_){ |
---|
[11566] | 73 | const std::string& points = "Score: "+multi_cast<std::string>(this->FlappyOrxGame->getPoints()); |
---|
[11503] | 74 | setTextSize(0.04); |
---|
| 75 | this->setCaption(points); |
---|
| 76 | } |
---|
[11565] | 77 | else if(this->bShowGameOver_){ |
---|
| 78 | setTextSize(0); |
---|
| 79 | } |
---|
[11503] | 80 | } |
---|
[11565] | 81 | else{ |
---|
[11566] | 82 | if(this->bShowPoints_){ |
---|
| 83 | setTextSize(0); |
---|
| 84 | } |
---|
| 85 | else if(this->bShowGameOver_){ |
---|
[11589] | 86 | if(this->FlappyOrxGame->firstGame){ |
---|
| 87 | if(messageID==3){ |
---|
| 88 | setTextSize(0.05); |
---|
[11630] | 89 | this->setCaption("First click, then press space to start"); |
---|
[11589] | 90 | } |
---|
[11576] | 91 | } |
---|
[11589] | 92 | else{ |
---|
| 93 | std::string message; |
---|
| 94 | setTextSize(0.05); |
---|
| 95 | switch(messageID){ |
---|
| 96 | case 0: |
---|
| 97 | message = "Game Over"; |
---|
| 98 | setTextSize(0.1); |
---|
| 99 | this->setCaption(message); |
---|
| 100 | break; |
---|
| 101 | case 1: |
---|
| 102 | message = this->FlappyOrxGame->sDeathMessage; |
---|
| 103 | break; |
---|
| 104 | case 2: |
---|
| 105 | message = "Your Score: "+multi_cast<std::string>(this->FlappyOrxGame->getPoints())+ |
---|
| 106 | " Local High Score: "+multi_cast<std::string>(Highscore::getInstance().getHighestScoreOfGame("Flappy Orx")); |
---|
| 107 | break; |
---|
| 108 | case 3: |
---|
[11595] | 109 | int time = this->FlappyOrxGame->getPlayer()->timeUntilRespawn(); |
---|
| 110 | if(time<=0) |
---|
| 111 | message = "Press space to restart."; |
---|
| 112 | else |
---|
| 113 | message = "Please wait "+multi_cast<std::string>(time)+" seconds."; |
---|
[11589] | 114 | break; |
---|
| 115 | } |
---|
| 116 | this->setCaption(message); |
---|
| 117 | } |
---|
[11563] | 118 | } |
---|
[11565] | 119 | } |
---|
[11503] | 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | void FlappyOrxHUDinfo::changedOwner() |
---|
| 124 | { |
---|
| 125 | SUPER(FlappyOrxHUDinfo, changedOwner); |
---|
| 126 | |
---|
| 127 | if (this->getOwner() && this->getOwner()->getGametype()) |
---|
| 128 | { |
---|
| 129 | this->FlappyOrxGame = orxonox_cast<FlappyOrx*>(this->getOwner()->getGametype()); |
---|
| 130 | } |
---|
| 131 | else |
---|
| 132 | { |
---|
| 133 | this->FlappyOrxGame = nullptr; |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | } |
---|