Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12394 was 12394, checked in by pomselj, 6 years ago

almost done

File size: 9.6 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 "OrxoBloxStones.h"
51#include "OrxoBloxWall.h"
52#include "OrxoBloxShip.h"
53
54namespace 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        this->counter = 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::LevelUp, 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        }
118        this->activeWalls_.clear();
119       
120
121        for (OrxoBloxStones* stone : this->stones_) {
122            if(stone != nullptr)
123            stone->destroy();
124        }
125        this->stones_.clear();
126        if(this->playership != nullptr) {
127            this->playership->destroy();
128        }
129        if(this->center_ != nullptr) {
130            this->center_->destroy();
131        }
132       
133
134    }
135
136    /**
137    @brieftt   
138        Starts the OrxoBlox minigame.
139    */
140    void OrxoBlox::start()
141
142    {
143        orxout() << "Orxoblox started" << endl;
144        if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place.
145        {
146
147            level_= 1;
148
149        }
150        else // If no centerpoint was specified, an error is thrown and the level is exited.
151        {
152            orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl;
153            GSLevel::startMainMenu();
154            return;
155        }
156
157        // Start the timer. After it has expired the ball is started.
158        this->starttimer_.startTimer();
159
160        // Set variable to temporarily force the player to spawn.
161        // Set variable to temporarily force the player to spawn.
162        //bool temp = this->bForceSpawn_;
163        this->bForceSpawn_ = false;
164
165        // Call start for the parent class.
166        Deathmatch::start();
167
168        // Reset the variable.
169        //this->bForceSpawn_ = temp;
170
171    }
172
173    /**
174    @brief
175        Ends the OrxoBlox minigame.
176    */
177    void OrxoBlox::end()
178    {
179        ChatManager::message("You suck!!");
180
181        if (Highscore::exists())
182        {
183            int score = this->getScore(this->getPlayer());
184            Highscore::getInstance().storeScore("OrxoBlox", score, this->getPlayer());
185        }
186
187        this->cleanup();
188
189        // Call end for the parent class.
190        Deathmatch::end();
191        GSLevel::startMainMenu();
192    }
193
194    PlayerInfo* OrxoBlox::getPlayer()
195    {
196        return this->player_;
197    }
198   
199    // void OrxoBlox::spawnPlayer(PlayerInfo* player)
200    // {
201    //     assert(player);
202
203    //     if(this->player_ == nullptr)
204    //     {
205    //         this->player_ = player;
206    //         this->players_[player].state_ = PlayerState::Alive;
207    //     }
208
209    // }
210
211    void OrxoBlox::LevelUp(){
212        level_++;
213        int z_ = 0;
214
215        orxout() << "level up called" << endl;
216        //this->playerScored(this->player_);// add points
217
218        this->createWall();
219        this->activeWalls_.push_back(this->futureWall_);
220/*        for (int i = 0; i < this->futureWall_->getNumberOfStones(); i++) {
221            this->stones_.push_back(this->futureWall_->getStone(i));
222        }*/
223
224        for(OrxoBloxWall* wall : this->activeWalls_) {
225            if(wall == nullptr) {
226                continue;
227            }
228            if(wall->isEmpty()) {
229                wall->destroy();
230            }
231            int NumberOfStones = 0;
232            for(int i = 0; i < 10; i++) {
233                if(wall->getStone(i) == nullptr) {
234                    continue;
235                }
236                else {
237                    NumberOfStones++;
238                }
239
240            }
241        }
242        //new location of ship
243        //new amount of balls
244        //create balls
245        //insert new wall
246        for(OrxoBloxStones* stone : this->stones_){
247            if (stone != nullptr) {
248                int x_=(stone->getPosition()).x;
249                int y_=(stone->getPosition()).y;
250                z_=(stone->getPosition()).z;
251                //if(z_==90)this->end();
252
253                stone->setPosition(x_,y_,z_+9.0f);
254                if( z_ >= 45){
255                    orxout() << "calling end() function" << endl;
256                    this->end();
257                }
258            }
259        }
260
261       
262    }
263
264    void OrxoBlox::createWall(){
265        this->futureWall_ = new OrxoBloxWall(this->center_->getContext());
266        // Apply the stone template to the stone.
267        this->futureWall_->addTemplate(this->center_->getWallTemplate());
268
269        // Attach the brick to the Centerpoint and set the position of the brick to be at the left side.
270        this->center_->attach(this->futureWall_);
271       
272        this->futureWall_->setPosition(0, 0, 0);
273        this->futureWall_->setGame(this);
274    }
275
276
277    /**
278    @brief
279        Starts the ball with some default speed.
280    */
281    //void OrxoBlox::startBall()
282    //{
283    //    if (this->ball_ != nullptr && this->center_ != nullptr)
284    //        this->ball_->setSpeed(this->center_->getBallSpeed());
285    //}
286     
287    /*OrxoBloxStones* OrxoBlox::CheckForCollision(OrxoBloxBall* Ball) {
288        //orxout() << "Checking for Collision" << endl;
289        Vector3 BallPosition = Ball->getPosition();
290        for(OrxoBloxStones* someStone : this->stones_)
291        {
292            if(someStone == nullptr)
293            {
294                continue;
295            }
296            //orxout() << "Checking a stone" << endl;
297            const Vector3& StonePosition = someStone->getPosition(); //!< Saves the position of the currentStone
298            int size = someStone->getSize()/2;
299            if((BallPosition.x - Ball->getRadius() >= StonePosition.x - size && BallPosition.x + Ball->getRadius() <= StonePosition.x + size) &&
300                (BallPosition.z - Ball->getRadius() >= StonePosition.z - size && BallPosition.z + Ball->getRadius() <= StonePosition.z + size)) {
301                //orxout() << "FOUND ONE" << endl;
302                return someStone;
303            }
304        }
305        orxout() << "Found nothing...." << endl;
306        return nullptr;
307    }
308    */
309
310    void OrxoBlox::playerPreSpawn(PlayerInfo* player)
311    {
312        this->player_ = player;
313    }
314   
315    void OrxoBlox::tick(float dt)
316    {       
317        SUPER(OrxoBlox, tick, dt);
318    }
319/*
320    bool OrxoBlox::Intersect(int XpositionBall, int XPositionBlock, int YPositionBall, int YPositionBlock, int radiusBall, int sizeBlock) {
321        distanceX = XpositionBall - XPositionBlock;
322        distanceY = YPositionBall - YPositionBlock;
323        if (distanceX < 0) {
324            distanceX = -distanceX;
325        }
326        if (distanceY < 0) {
327            distanceY = -distanceY;
328        }
329        if((distanceX <= radiusBall + sizeBlock) || (distanceY <= radiusBall + sizeBlock)) {
330            return true;
331        }
332        else {
333            top = YPositionBall + radiusBall;
334            right = XpositionBall + radiusBall;
335            bottom = YPositionBall - radiusBall;
336            left = XpositionBall - radiusBall;
337
338            if((top >= YPositionBlock - size) && (top <= YPositionBlock + size) && (left <= XPositionBlock + size) && (left >= XPositionBlock - size))
339        }
340    }
341  */ 
342    void OrxoBlox::count() {
343        if(this->counter >= this->max_counter) {
344            this->LevelUp();
345            counter = 0;
346            return;
347        }
348        else {
349            this->counter++;
350        }
351    }
352
353
354}
Note: See TracBrowser for help on using the repository browser.