[12177] | 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 | * Leo Merholz |
---|
| 24 | * Pascal Schärli |
---|
| 25 | * |
---|
| 26 | * Co-authors: |
---|
| 27 | * ... |
---|
| 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->bShowPoints_ = false; |
---|
| 47 | this->bShowMessage_ = false; |
---|
| 48 | this->messageID = 0; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | void FlappyOrxHUDinfo::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 52 | { |
---|
| 53 | SUPER(FlappyOrxHUDinfo, XMLPort, xmlelement, mode); |
---|
| 54 | |
---|
| 55 | XMLPortParam(FlappyOrxHUDinfo, "showpoints", setShowPoints, getShowPoints, xmlelement, mode).defaultValues(false); |
---|
| 56 | XMLPortParam(FlappyOrxHUDinfo, "showmessage", setShowMessage, getShowMessage, xmlelement, mode).defaultValues(false); |
---|
| 57 | XMLPortParam(FlappyOrxHUDinfo, "messageID", setMessageID, getMessageID, xmlelement, mode).defaultValues(0); |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void FlappyOrxHUDinfo::tick(float dt) |
---|
| 63 | { |
---|
| 64 | SUPER(FlappyOrxHUDinfo, tick, dt); |
---|
| 65 | |
---|
| 66 | if (this->FlappyOrxGame) |
---|
| 67 | { |
---|
| 68 | if(not this->FlappyOrxGame->isDead()){ |
---|
| 69 | if(this->bShowPoints_){ |
---|
| 70 | const std::string& points = "Score: "+multi_cast<std::string>(this->FlappyOrxGame->getPoints()); |
---|
| 71 | setTextSize(0.04); |
---|
| 72 | this->setCaption(points); |
---|
| 73 | } |
---|
| 74 | else if(this->bShowMessage_){ |
---|
| 75 | setTextSize(0); |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | else{ |
---|
| 79 | if(this->bShowPoints_){ |
---|
| 80 | setTextSize(0); |
---|
| 81 | } |
---|
| 82 | else if(this->bShowMessage_){ |
---|
| 83 | if(this->FlappyOrxGame->firstGame){ |
---|
| 84 | if(messageID==3){ |
---|
| 85 | setTextSize(0.05); |
---|
| 86 | this->setCaption("First click, then press space to start"); |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | else{ |
---|
| 90 | std::string message; |
---|
| 91 | setTextSize(0.05); |
---|
| 92 | switch(messageID){ |
---|
| 93 | case 0: |
---|
| 94 | message = "Game Over"; |
---|
| 95 | setTextSize(0.1); |
---|
| 96 | this->setCaption(message); |
---|
| 97 | break; |
---|
| 98 | case 1: |
---|
| 99 | message = this->FlappyOrxGame->sDeathMessage; |
---|
| 100 | break; |
---|
| 101 | case 2: |
---|
| 102 | message = "Your Score: "+multi_cast<std::string>(this->FlappyOrxGame->getPoints())+ |
---|
| 103 | " Local High Score: "+multi_cast<std::string>(Highscore::getInstance().getHighestScoreOfGame("Flappy Orx")); |
---|
| 104 | break; |
---|
| 105 | case 3: |
---|
| 106 | time_t time = this->FlappyOrxGame->getPlayer()->timeUntilRespawn(); |
---|
| 107 | if(time<=0) |
---|
| 108 | message = "Press space to restart."; |
---|
| 109 | else |
---|
| 110 | message = "Please wait "+multi_cast<std::string>(time)+" seconds."; |
---|
| 111 | break; |
---|
| 112 | } |
---|
| 113 | this->setCaption(message); |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | void FlappyOrxHUDinfo::changedOwner() |
---|
| 121 | { |
---|
| 122 | SUPER(FlappyOrxHUDinfo, changedOwner); |
---|
| 123 | |
---|
| 124 | if (this->getOwner() && this->getOwner()->getGametype()) |
---|
| 125 | { |
---|
| 126 | this->FlappyOrxGame = orxonox_cast<FlappyOrx*>(this->getOwner()->getGametype()); |
---|
| 127 | } |
---|
| 128 | else |
---|
| 129 | { |
---|
| 130 | this->FlappyOrxGame = nullptr; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|