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 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file JumpScore.cc |
---|
31 | @brief Implementation of the JumpScore class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "JumpScore.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/XMLPort.h" |
---|
38 | #include "util/Convert.h" |
---|
39 | |
---|
40 | #include "infos/PlayerInfo.h" |
---|
41 | |
---|
42 | #include "Jump.h" |
---|
43 | #include "sound/WorldSound.h" ///////////////////////////// |
---|
44 | |
---|
45 | namespace orxonox |
---|
46 | { |
---|
47 | RegisterClass(JumpScore); |
---|
48 | |
---|
49 | /** |
---|
50 | @brief |
---|
51 | Constructor. Registers and initializes the object. |
---|
52 | */ |
---|
53 | JumpScore::JumpScore(Context* context) : OverlayText(context) |
---|
54 | { |
---|
55 | RegisterObject(JumpScore); |
---|
56 | |
---|
57 | this->owner_ = NULL; |
---|
58 | |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | @brief |
---|
63 | Destructor. |
---|
64 | */ |
---|
65 | JumpScore::~JumpScore() |
---|
66 | { |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | @brief |
---|
72 | Method to create a JumpScore through XML. |
---|
73 | */ |
---|
74 | void JumpScore::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
75 | { |
---|
76 | SUPER(JumpScore, XMLPort, xmlelement, mode); |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | @brief |
---|
81 | Is called each tick. |
---|
82 | Creates and sets the caption to be displayed by the JumpScore. |
---|
83 | @param dt |
---|
84 | The time that has elapsed since the last tick. |
---|
85 | */ |
---|
86 | void JumpScore::tick(float dt) |
---|
87 | { |
---|
88 | SUPER(JumpScore, tick, dt); |
---|
89 | |
---|
90 | // If the owner is set. The owner being a Jump game. |
---|
91 | |
---|
92 | if (this->owner_ != NULL) |
---|
93 | { |
---|
94 | /* |
---|
95 | if (!this->owner_->hasEnded()) |
---|
96 | { |
---|
97 | // Get the two players. |
---|
98 | player1_ = this->owner_->getPlayer(); |
---|
99 | } |
---|
100 | |
---|
101 | std::string name1; |
---|
102 | |
---|
103 | std::string score1("0"); |
---|
104 | |
---|
105 | // Save the name and score of each player as a string. |
---|
106 | if (player1_ != NULL) |
---|
107 | { |
---|
108 | name1 = player1_->getName(); |
---|
109 | score1 = multi_cast<std::string>(this->owner_->getScore(player1_)); |
---|
110 | } |
---|
111 | |
---|
112 | // Assemble the strings, depending on what should all be displayed. |
---|
113 | std::string output1; |
---|
114 | if (this->bShowLeftPlayer_) |
---|
115 | { |
---|
116 | if (this->bShowName_ && this->bShowScore_ && player1_ != NULL) |
---|
117 | output1 = name1 + " - " + score1; |
---|
118 | else if (this->bShowScore_) |
---|
119 | output1 = score1; |
---|
120 | else if (this->bShowName_) |
---|
121 | output1 = name1; |
---|
122 | } |
---|
123 | |
---|
124 | std::string output("JUMP"); |
---|
125 | if (this->bShowName_ || this->bShowScore_) |
---|
126 | { |
---|
127 | if (this->bShowLeftPlayer_ && this->bShowRightPlayer_) |
---|
128 | output = output1 + ':' + output2; |
---|
129 | else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_) |
---|
130 | output = output1 + output2; |
---|
131 | } |
---|
132 | |
---|
133 | this->setCaption(output);*/ |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | if (!owner_->hasEnded()) |
---|
139 | { |
---|
140 | player_ = owner_->getPlayer(); |
---|
141 | |
---|
142 | if (player_ != NULL) |
---|
143 | { |
---|
144 | int score = owner_->getScore(player_); |
---|
145 | |
---|
146 | std::string str = multi_cast<std::string>(score); |
---|
147 | setCaption(str); |
---|
148 | } |
---|
149 | } |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | @brief |
---|
155 | Is called when the owner changes. |
---|
156 | Sets the owner to NULL, if it is not a pointer to a Jump game. |
---|
157 | */ |
---|
158 | void JumpScore::changedOwner() |
---|
159 | { |
---|
160 | SUPER(JumpScore, changedOwner); |
---|
161 | |
---|
162 | if (this->getOwner() != NULL && this->getOwner()->getGametype()) |
---|
163 | { |
---|
164 | this->owner_ = orxonox_cast<Jump*>(this->getOwner()->getGametype().get()); |
---|
165 | } |
---|
166 | else |
---|
167 | { |
---|
168 | this->owner_ = NULL; |
---|
169 | } |
---|
170 | } |
---|
171 | } |
---|