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