Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc @ 12368

Last change on this file since 12368 was 12368, checked in by pomselj, 5 years ago

We can shoot

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