Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12308 was 12308, checked in by ahuwyler, 5 years ago

Bats are gone

File size: 6.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 "OrxoBloxBall.h"
51// #include "OrxoBloxBat.h"//Remove??
52#include "OrxoBloxBot.h"//Remove??
53#include "OrxoBloxStones.h"
54#include "OrxoBloxWall.h"
55
56
57namespace orxonox
58{
59   
60
61    RegisterUnloadableClass(OrxoBlox);
62
63    /**
64    @brief
65        Constructor. Registers and initializes the object.
66    */
67    OrxoBlox::OrxoBlox(Context* context) : Deathmatch(context)
68    {
69        RegisterObject(OrxoBlox);
70
71        this->center_ = nullptr;
72        this->ball_ = nullptr;
73        this->futureWall_ = nullptr;
74        this->player_ = nullptr;
75       
76
77        this->setHUDTemplate("OrxoBloxHUD");
78        //Error when specified
79
80        // Pre-set the timer, but don't start it yet.
81        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&OrxoBlox::startBall, this)));
82        this->starttimer_.stopTimer();
83
84       
85
86    }
87
88    /**
89    @brief
90        Destructor. Cleans up, if initialized.
91    */
92    OrxoBlox::~OrxoBlox()
93    {
94        if (this->isInitialized())
95            this->cleanup();
96    }
97
98    /**
99    @brief
100        Cleans up the Gametype by destroying the ball and the bats.
101    */
102    void OrxoBlox::cleanup()
103    {
104        if (this->ball_ != nullptr) // Destroy the ball, if present.
105        {
106            this->ball_->destroy();
107            this->ball_ = nullptr;
108        }
109
110        if (this->futureWall_)
111            {
112                this->futureWall_->destroy();
113                this->futureWall_ = nullptr;
114            }
115
116        // Destroy 6 bWalls, if present.
117        for (size_t i = 0; i < 6; ++i)
118        {
119            if (this->activeWalls_[0] != nullptr)
120            {
121                this->activeWalls_[0]->destroy();
122                this->activeWalls_[0] = nullptr;
123            }
124           
125        }
126
127    }
128
129    /**
130    @brieftt   
131        Starts the OrxoBlox minigame.
132    */
133    void OrxoBlox::start()
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            this->ball_->setPosition(0, 0, 50);
147            this->ball_->setFieldDimension(this->center_->getFieldDimension());
148            this->ball_->setSpeed(0);
149            this->ball_->setAccelerationFactor(this->center_->getBallAccelerationFactor());
150            this->ball_->setBatLength(this->center_->getBatLength());
151
152
153            // Create the first Wall.
154            this->createWall();
155
156        }
157        else // If no centerpoint was specified, an error is thrown and the level is exited.
158        {
159            orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl;
160            GSLevel::startMainMenu();
161            return;
162        }
163
164        // Start the timer. After it has expired the ball is started.
165        this->starttimer_.startTimer();
166
167        // Set variable to temporarily force the player to spawn.
168        bool temp = this->bForceSpawn_;
169        this->bForceSpawn_ = true;
170
171        // Call start for the parent class.
172        Deathmatch::start();
173
174        // Reset the variable.
175        this->bForceSpawn_ = temp;
176    }
177
178    /**
179    @brief
180        Ends the OrxoBlox minigame.
181    */
182    void OrxoBlox::end()
183    {
184        ChatManager::message("You suck!!");
185        this->cleanup();
186
187        // Call end for the parent class.
188        Deathmatch::end();
189    }
190
191    /**
192    @brief
193        Spawns players, and fills the rest up with bots.
194    */
195    void OrxoBlox::spawnPlayersIfRequested()
196    {
197        // first spawn human players to assign always the left bat to the player in singleplayer
198        for (const auto& mapEntry : this->players_)
199            if (mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_))
200                this->spawnPlayer(mapEntry.first);
201        // now spawn bots
202        for (const auto& mapEntry : this->players_)
203            if (!mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_))
204                this->spawnPlayer(mapEntry.first);
205    }
206
207
208    /**
209    @brief
210        Spawns the input player.
211    @param player
212        The player to be spawned.
213    */
214    void OrxoBlox::spawnPlayer(PlayerInfo* player)
215    {
216         assert(player);
217
218        if(this->player_ == nullptr)
219        {
220            this->player_ = player;
221            this->players_[player].state_ = PlayerState::Alive;
222        }
223    }
224
225    /**
226    @brief
227        Is called when the player scored.
228    */
229   
230    //void startWall(void);
231   
232
233
234    void OrxoBlox::createWall(void){
235        this->futureWall_ = new OrxoBloxWall(this->center_->getContext());
236        // Apply the stone template to the stone.
237        this->futureWall_->addTemplate(this->center_->getWallTemplate());
238
239        // Attach the brick to the Centerpoint and set the position of the brick to be at the left side.
240        this->center_->attach(this->futureWall_);
241       
242       
243        this->futureWall_->setPosition(10, 10, 0.0f);
244        this->futureWall_->setGame(this);
245    }
246
247
248    /**
249    @brief
250        Starts the ball with some default speed.
251    */
252    void OrxoBlox::startBall()
253    {
254        if (this->ball_ != nullptr && this->center_ != nullptr)
255            this->ball_->setSpeed(this->center_->getBallSpeed());
256    }
257
258   
259   
260}
Note: See TracBrowser for help on using the repository browser.