Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

BallProjectiles fly

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