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 OrxoBlox.cc |
---|
31 | @brief Implementation of the OrxoBlox class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "OrxoBlox.h" |
---|
35 | #include "Highscore.h" |
---|
36 | |
---|
37 | #include "core/CoreIncludes.h" |
---|
38 | #include "core/EventIncludes.h" |
---|
39 | #include "core/command/Executor.h" |
---|
40 | |
---|
41 | |
---|
42 | #include "core/config/ConfigValueIncludes.h"//Remove?? |
---|
43 | |
---|
44 | #include "gamestates/GSLevel.h" |
---|
45 | |
---|
46 | |
---|
47 | #include "chat/ChatManager.h"//Remove? |
---|
48 | |
---|
49 | #include "OrxoBloxCenterpoint.h" |
---|
50 | #include "OrxoBloxStones.h" |
---|
51 | #include "OrxoBloxWall.h" |
---|
52 | #include "OrxoBloxShip.h" |
---|
53 | |
---|
54 | namespace orxonox |
---|
55 | { |
---|
56 | |
---|
57 | |
---|
58 | RegisterUnloadableClass(OrxoBlox); |
---|
59 | |
---|
60 | /** |
---|
61 | @brief |
---|
62 | Constructor. Registers and initializes the object. |
---|
63 | */ |
---|
64 | OrxoBlox::OrxoBlox(Context* context) : Deathmatch(context) |
---|
65 | { |
---|
66 | RegisterObject(OrxoBlox); |
---|
67 | |
---|
68 | this->center_ = nullptr; |
---|
69 | //this->ball_ = nullptr; |
---|
70 | this->futureWall_ = nullptr; |
---|
71 | this->player_ = nullptr; |
---|
72 | level_ = 0; |
---|
73 | |
---|
74 | this->setHUDTemplate("OrxoBloxHUD"); |
---|
75 | //Error when specified |
---|
76 | |
---|
77 | // Pre-set the timer, but don't start it yet. |
---|
78 | this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&OrxoBlox::LevelUp, this))); |
---|
79 | this->starttimer_.stopTimer(); |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | @brief |
---|
87 | Destructor. Cleans up, if initialized. |
---|
88 | */ |
---|
89 | OrxoBlox::~OrxoBlox() |
---|
90 | { |
---|
91 | if (this->isInitialized()) |
---|
92 | this->cleanup(); |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | @brief |
---|
97 | Cleans up the Gametype by destroying the ball and the bats. |
---|
98 | */ |
---|
99 | void OrxoBlox::cleanup() |
---|
100 | { |
---|
101 | //if (this->ball_ != nullptr) // Destroy the ball, if present. |
---|
102 | //{ |
---|
103 | // this->ball_->destroy(); |
---|
104 | // this->ball_ = nullptr; |
---|
105 | //} |
---|
106 | |
---|
107 | /*if (this->futureWall_ != nullptr) |
---|
108 | { |
---|
109 | this->futureWall_->destroy(); |
---|
110 | this->futureWall_ = nullptr; |
---|
111 | } |
---|
112 | */ |
---|
113 | |
---|
114 | for (OrxoBloxWall* wall : this->activeWalls_) |
---|
115 | if (wall != nullptr) |
---|
116 | wall->destroy(); |
---|
117 | this->activeWalls_.clear(); |
---|
118 | |
---|
119 | |
---|
120 | for (OrxoBloxStones* stone : this->stones_) |
---|
121 | if(stone != nullptr) |
---|
122 | stone->destroy(); |
---|
123 | this->stones_.clear(); |
---|
124 | |
---|
125 | |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | @brieftt |
---|
130 | Starts the OrxoBlox minigame. |
---|
131 | */ |
---|
132 | void OrxoBlox::start() |
---|
133 | |
---|
134 | { |
---|
135 | orxout() << "Orxoblox started" << endl; |
---|
136 | if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place. |
---|
137 | { |
---|
138 | //if (this->ball_ == nullptr) // If there is no ball, create a new ball. |
---|
139 | //{ |
---|
140 | // this->ball_ = new OrxoBloxBall(this->center_->getContext()); |
---|
141 | // Apply the template for the ball specified by the centerpoint. |
---|
142 | // this->ball_->addTemplate(this->center_->getBalltemplate()); |
---|
143 | //} |
---|
144 | |
---|
145 | // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to. |
---|
146 | //this->center_->attach(this->ball_); |
---|
147 | //Startposition Ball |
---|
148 | //this->ball_->setPosition(0, 0, 40); |
---|
149 | //this->ball_->setFieldDimension(this->center_->getFieldDimension()); |
---|
150 | //this->ball_->setSpeed(0); |
---|
151 | //this->ball_->setAccelerationFactor(this->center_->getBallAccelerationFactor()); |
---|
152 | |
---|
153 | level_=1; |
---|
154 | |
---|
155 | // Create the first Wall. |
---|
156 | this->LevelUp(); |
---|
157 | |
---|
158 | //Create Ship |
---|
159 | //this->ship_ = new OrxoBloxShip(this->center_->getContext()); |
---|
160 | //this->ship_->setPosition(0, 0, 0); |
---|
161 | |
---|
162 | } |
---|
163 | else // If no centerpoint was specified, an error is thrown and the level is exited. |
---|
164 | { |
---|
165 | orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl; |
---|
166 | GSLevel::startMainMenu(); |
---|
167 | return; |
---|
168 | } |
---|
169 | |
---|
170 | // Start the timer. After it has expired the ball is started. |
---|
171 | this->starttimer_.startTimer(); |
---|
172 | |
---|
173 | // Set variable to temporarily force the player to spawn. |
---|
174 | // Set variable to temporarily force the player to spawn. |
---|
175 | //bool temp = this->bForceSpawn_; |
---|
176 | this->bForceSpawn_ = false; |
---|
177 | |
---|
178 | // Call start for the parent class. |
---|
179 | Deathmatch::start(); |
---|
180 | |
---|
181 | // Reset the variable. |
---|
182 | //this->bForceSpawn_ = temp; |
---|
183 | |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | @brief |
---|
188 | Ends the OrxoBlox minigame. |
---|
189 | */ |
---|
190 | void OrxoBlox::end() |
---|
191 | { |
---|
192 | ChatManager::message("You suck!!"); |
---|
193 | |
---|
194 | if (Highscore::exists()) |
---|
195 | { |
---|
196 | int score = this->getScore(this->getPlayer()); |
---|
197 | Highscore::getInstance().storeScore("Tetris", score, this->getPlayer()); |
---|
198 | } |
---|
199 | |
---|
200 | this->cleanup(); |
---|
201 | |
---|
202 | // Call end for the parent class. |
---|
203 | Deathmatch::end(); |
---|
204 | GSLevel::startMainMenu(); |
---|
205 | } |
---|
206 | |
---|
207 | PlayerInfo* OrxoBlox::getPlayer() |
---|
208 | { |
---|
209 | return this->player_; |
---|
210 | } |
---|
211 | |
---|
212 | // void OrxoBlox::spawnPlayer(PlayerInfo* player) |
---|
213 | // { |
---|
214 | // assert(player); |
---|
215 | |
---|
216 | // if(this->player_ == nullptr) |
---|
217 | // { |
---|
218 | // this->player_ = player; |
---|
219 | // this->players_[player].state_ = PlayerState::Alive; |
---|
220 | // } |
---|
221 | |
---|
222 | // } |
---|
223 | |
---|
224 | void OrxoBlox::LevelUp(){ |
---|
225 | level_++; |
---|
226 | int z_ = 0; |
---|
227 | |
---|
228 | orxout() << "level up called" << endl; |
---|
229 | this->playerScored(this->player_);// add points |
---|
230 | for(OrxoBloxStones* stone : this->stones_){ |
---|
231 | int x_=(stone->getPosition()).x; |
---|
232 | int y_=(stone->getPosition()).y; |
---|
233 | z_=(stone->getPosition()).z; |
---|
234 | //if(z_==90)this->end(); |
---|
235 | |
---|
236 | stone->setPosition(x_,y_,z_+9.0f); |
---|
237 | |
---|
238 | } |
---|
239 | |
---|
240 | |
---|
241 | this->createWall(); |
---|
242 | this->activeWalls_.push_back(this->futureWall_); |
---|
243 | for (int i = 0; i < this->futureWall_->getNumberOfStones(); i++) { |
---|
244 | if (this->futureWall_->getStone(i) == nullptr) { |
---|
245 | orxout() << "Added nullptr to std::list stones_" << endl; |
---|
246 | } |
---|
247 | |
---|
248 | this->stones_.push_back(this->futureWall_->getStone(i)); |
---|
249 | } |
---|
250 | |
---|
251 | for(OrxoBloxWall* wall : this->activeWalls_) { |
---|
252 | if(wall->isEmpty()) { |
---|
253 | wall->destroy(); |
---|
254 | } |
---|
255 | int NumberOfStones = 0; |
---|
256 | for(int i = 0; i < 10; i++) { |
---|
257 | if(wall->getStone(i) == nullptr) { |
---|
258 | continue; |
---|
259 | } |
---|
260 | else { |
---|
261 | NumberOfStones++; |
---|
262 | } |
---|
263 | |
---|
264 | } |
---|
265 | } |
---|
266 | //new location of ship |
---|
267 | //new amount of balls |
---|
268 | //create balls |
---|
269 | //insert new wall |
---|
270 | if( z_ >= 45){ |
---|
271 | orxout() << "calling end() function" << endl; |
---|
272 | this->end(); |
---|
273 | } |
---|
274 | |
---|
275 | } |
---|
276 | |
---|
277 | void OrxoBlox::createWall(){ |
---|
278 | this->futureWall_ = new OrxoBloxWall(this->center_->getContext()); |
---|
279 | // Apply the stone template to the stone. |
---|
280 | this->futureWall_->addTemplate(this->center_->getWallTemplate()); |
---|
281 | |
---|
282 | // Attach the brick to the Centerpoint and set the position of the brick to be at the left side. |
---|
283 | this->center_->attach(this->futureWall_); |
---|
284 | |
---|
285 | this->futureWall_->setPosition(0, 0, 0); |
---|
286 | this->futureWall_->setGame(this); |
---|
287 | } |
---|
288 | |
---|
289 | |
---|
290 | /** |
---|
291 | @brief |
---|
292 | Starts the ball with some default speed. |
---|
293 | */ |
---|
294 | //void OrxoBlox::startBall() |
---|
295 | //{ |
---|
296 | // if (this->ball_ != nullptr && this->center_ != nullptr) |
---|
297 | // this->ball_->setSpeed(this->center_->getBallSpeed()); |
---|
298 | //} |
---|
299 | |
---|
300 | /*OrxoBloxStones* OrxoBlox::CheckForCollision(OrxoBloxBall* Ball) { |
---|
301 | //orxout() << "Checking for Collision" << endl; |
---|
302 | Vector3 BallPosition = Ball->getPosition(); |
---|
303 | for(OrxoBloxStones* someStone : this->stones_) |
---|
304 | { |
---|
305 | if(someStone == nullptr) |
---|
306 | { |
---|
307 | continue; |
---|
308 | } |
---|
309 | //orxout() << "Checking a stone" << endl; |
---|
310 | const Vector3& StonePosition = someStone->getPosition(); //!< Saves the position of the currentStone |
---|
311 | int size = someStone->getSize()/2; |
---|
312 | if((BallPosition.x - Ball->getRadius() >= StonePosition.x - size && BallPosition.x + Ball->getRadius() <= StonePosition.x + size) && |
---|
313 | (BallPosition.z - Ball->getRadius() >= StonePosition.z - size && BallPosition.z + Ball->getRadius() <= StonePosition.z + size)) { |
---|
314 | //orxout() << "FOUND ONE" << endl; |
---|
315 | return someStone; |
---|
316 | } |
---|
317 | } |
---|
318 | orxout() << "Found nothing...." << endl; |
---|
319 | return nullptr; |
---|
320 | } |
---|
321 | */ |
---|
322 | |
---|
323 | void OrxoBlox::playerPreSpawn(PlayerInfo* player) |
---|
324 | { |
---|
325 | this->player_ = player; |
---|
326 | } |
---|
327 | |
---|
328 | /* |
---|
329 | bool OrxoBlox::Intersect(int XpositionBall, int XPositionBlock, int YPositionBall, int YPositionBlock, int radiusBall, int sizeBlock) { |
---|
330 | distanceX = XpositionBall - XPositionBlock; |
---|
331 | distanceY = YPositionBall - YPositionBlock; |
---|
332 | if (distanceX < 0) { |
---|
333 | distanceX = -distanceX; |
---|
334 | } |
---|
335 | if (distanceY < 0) { |
---|
336 | distanceY = -distanceY; |
---|
337 | } |
---|
338 | if((distanceX <= radiusBall + sizeBlock) || (distanceY <= radiusBall + sizeBlock)) { |
---|
339 | return true; |
---|
340 | } |
---|
341 | else { |
---|
342 | top = YPositionBall + radiusBall; |
---|
343 | right = XpositionBall + radiusBall; |
---|
344 | bottom = YPositionBall - radiusBall; |
---|
345 | left = XpositionBall - radiusBall; |
---|
346 | |
---|
347 | if((top >= YPositionBlock - size) && (top <= YPositionBlock + size) && (left <= XPositionBlock + size) && (left >= XPositionBlock - size)) |
---|
348 | } |
---|
349 | } |
---|
350 | */ |
---|
351 | } |
---|