Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12351 was 12351, checked in by ahuwyler, 6 years ago

Walls are coming down

File size: 8.0 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 "OrxoBloxBot.h"//Remove??
52#include "OrxoBloxStones.h"
53#include "OrxoBloxWall.h"
54#include "OrxoBloxShip.h"
55
56namespace orxonox
57{
58   
59
60    RegisterUnloadableClass(OrxoBlox);
61
62    /**
63    @brief
64        Constructor. Registers and initializes the object.
65    */
66    OrxoBlox::OrxoBlox(Context* context) : ::orxonox::Deathmatch::Deathmatch(context)
67    {
68        RegisterObject(OrxoBlox);
69
70        this->center_ = nullptr;
71        this->ball_ = nullptr;
72        this->futureWall_ = nullptr;
73        this->player_ = nullptr;
74        level_ = 0;
75
76        this->setHUDTemplate("OrxoBloxHUD");
77        //Error when specified
78
79        // Pre-set the timer, but don't start it yet.
80        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&OrxoBlox::startBall, this)));
81        this->starttimer_.stopTimer();
82
83       
84
85    }
86
87    /**
88    @brief
89        Destructor. Cleans up, if initialized.
90    */
91    OrxoBlox::~OrxoBlox()
92    {
93        if (this->isInitialized())
94            this->cleanup();
95    }
96
97    /**
98    @brief
99        Cleans up the Gametype by destroying the ball and the bats.
100    */
101    void OrxoBlox::cleanup()
102    {
103        if (this->ball_ != nullptr) // Destroy the ball, if present.
104        {
105            this->ball_->destroy();
106            this->ball_ = nullptr;
107        }
108
109        if (this->futureWall_)
110            {
111            this->futureWall_->destroy();
112            this->futureWall_ = nullptr;
113            }
114
115        for (OrxoBloxWall* wall : this->activeWalls_)
116            wall->destroy();
117        this->activeWalls_.clear();
118       
119
120        for (OrxoBloxStones* stone : this->stones_)
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        if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place.
134        {
135            if (this->ball_ == nullptr) // If there is no ball, create a new ball.
136            {
137                this->ball_ = new OrxoBloxBall(this->center_->getContext());
138                // Apply the template for the ball specified by the centerpoint.
139                this->ball_->addTemplate(this->center_->getBalltemplate());
140            }
141
142            // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to.
143            this->center_->attach(this->ball_);
144            //Startposition Ball
145            this->ball_->setPosition(0, 0, 40);
146            this->ball_->setFieldDimension(this->center_->getFieldDimension());
147            this->ball_->setSpeed(0);
148            this->ball_->setAccelerationFactor(this->center_->getBallAccelerationFactor());
149            this->ball_->setBatLength(this->center_->getBatLength());
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        this->bForceSpawn_ = true;
173
174        // Call start for the parent class.
175        Deathmatch::start();
176
177    }
178
179    /**
180    @brief
181        Ends the OrxoBlox minigame.
182    */
183    void OrxoBlox::end()
184    {
185        ChatManager::message("You suck!!");
186        this->cleanup();
187
188        // Call end for the parent class.
189        Deathmatch::end();
190        GSLevel::startMainMenu();
191    }
192
193    OrxoBloxShip* OrxoBlox::getPlayer()
194    {
195        if (playership == nullptr)
196        {
197            for (OrxoBloxShip* ship_ : ObjectList<OrxoBloxShip>())
198            {
199                playership = ship_;
200            }
201        }
202        return playership;
203    }
204   
205    void OrxoBlox::spawnPlayer(PlayerInfo* player)
206    {
207        assert(player);
208
209        if(this->player_ == nullptr)
210        {
211            this->player_ = player;
212            this->players_[player].state_ = PlayerState::Alive;
213        }
214
215    }
216
217    void OrxoBlox::LevelUp(){
218        level_++;
219
220        for(OrxoBloxWall* Wall : this->activeWalls_){
221            int z_=(Wall->getPosition()).z;
222            if(z_==90)this->end();
223            Wall->setPosition(0,0,z_+9.0f);
224        }
225        this->createWall();
226        this->activeWalls_.push_back(this->futureWall_);
227        for (int i = 0; i < this->futureWall_->getNumberOfStones(); i++) {
228            if (this->futureWall_->getStone(i) == nullptr) {
229                orxout() << "Added nullptr to std::list stones_" << endl;
230            }
231
232            this->stones_.push_back(this->futureWall_->getStone(i));
233        }
234        //new location of ship
235        //new amount of balls
236        //create balls
237        //insert new wall
238    }
239
240    void OrxoBlox::createWall(){
241        this->futureWall_ = new OrxoBloxWall(this->center_->getContext());
242        // Apply the stone template to the stone.
243        this->futureWall_->addTemplate(this->center_->getWallTemplate());
244
245        // Attach the brick to the Centerpoint and set the position of the brick to be at the left side.
246        this->center_->attach(this->futureWall_);
247       
248        this->futureWall_->setPosition(0, 0, 0);
249        this->futureWall_->setGame(this);
250    }
251
252
253    /**
254    @brief
255        Starts the ball with some default speed.
256    */
257    void OrxoBlox::startBall()
258    {
259        if (this->ball_ != nullptr && this->center_ != nullptr)
260            this->ball_->setSpeed(this->center_->getBallSpeed());
261    }
262
263    OrxoBloxStones* OrxoBlox::CheckForCollision(OrxoBloxBall* Ball) {
264
265        orxout() << "Checking for Collision" << endl;
266        Vector3 BallPosition = Ball->getPosition();
267        for(OrxoBloxStones* someStone : this->stones_)
268        {
269            if(someStone == nullptr) 
270            {
271                continue;
272            }
273            orxout() << "Checking a stone" << endl;
274            const Vector3& StonePosition = someStone->getPosition(); //!< Saves the position of the currentStone
275            int size = someStone->getSize();
276            if((BallPosition.x >= StonePosition.x - size && BallPosition.x <= StonePosition.x + size) && 
277                (BallPosition.z >= StonePosition.z - size && BallPosition.z <= StonePosition.z + size)) {
278                orxout() << "FOUND ONE" << endl;
279                return someStone;
280            }
281        }
282        orxout() << "Found nothing...." << endl;
283        return nullptr;
284    }
285   
286}
Note: See TracBrowser for help on using the repository browser.