Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

A Stone is in the game/ Templates are ajusted

File size: 8.4 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
36#include "core/CoreIncludes.h"
37#include "core/EventIncludes.h"
38#include "core/command/Executor.h"
39#include "core/config/ConfigValueIncludes.h"
40
41#include "gamestates/GSLevel.h"
42#include "chat/ChatManager.h"
43
44#include "OrxoBloxCenterpoint.h"
45#include "OrxoBloxBall.h"
46#include "OrxoBloxBat.h"
47#include "OrxoBloxBot.h"
48#include "OrxoBloxStones.h"
49#include "OrxoBloxWall.h"
50
51
52namespace orxonox
53{
54    // Events to allow to react to scoring of a player, in the level-file.
55    CreateEventName(OrxoBloxCenterpoint, right);
56    CreateEventName(OrxoBloxCenterpoint, left);
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       
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::startBall, 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_)
108            {
109                this->futureWall_->destroy();
110                this->futureWall_ = nullptr;
111            }
112
113        // Destroy 6 bWalls, if present.
114        for (size_t i = 0; i < 6; ++i)
115        {
116            if (this->activeWalls_[0] != nullptr)
117            {
118                this->activeWalls_[0]->destroy();
119                this->activeWalls_[0] = nullptr;
120            }
121           
122        }
123
124    }
125
126    /**
127    @brieftt   
128        Starts the OrxoBlox minigame.
129    */
130    void OrxoBlox::start()
131    {
132        if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place.
133        {
134            if (this->ball_ == nullptr) // If there is no ball, create a new ball.
135            {
136                this->ball_ = new OrxoBloxBall(this->center_->getContext());
137                // Apply the template for the ball specified by the centerpoint.
138                this->ball_->addTemplate(this->center_->getBalltemplate());
139            }
140
141            // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to.
142            this->center_->attach(this->ball_);
143            this->ball_->setPosition(0, 0, 50);
144            this->ball_->setFieldDimension(this->center_->getFieldDimension());
145            this->ball_->setSpeed(0);
146            this->ball_->setAccelerationFactor(this->center_->getBallAccelerationFactor());
147            this->ball_->setBatLength(this->center_->getBatLength());
148
149
150
151
152
153            // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint.
154            for (WeakPtr<orxonox::OrxoBloxBat>& bat : this->bat_)
155            {
156                if (bat == nullptr)
157                {
158                    bat = new OrxoBloxBat(this->center_->getContext());
159                    bat->addTemplate(this->center_->getBattemplate());
160                }
161            }
162
163
164            // Create the first Wall.
165            this->createWall();
166            orxout()<< "helloo"<< endl;
167
168        }
169        else // If no centerpoint was specified, an error is thrown and the level is exited.
170        {
171            orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl;
172            GSLevel::startMainMenu();
173            return;
174        }
175
176        // Start the timer. After it has expired the ball is started.
177        this->starttimer_.startTimer();
178
179        // Set variable to temporarily force the player to spawn.
180        bool temp = this->bForceSpawn_;
181        this->bForceSpawn_ = true;
182
183        // Call start for the parent class.
184        Deathmatch::start();
185
186        // Reset the variable.
187        this->bForceSpawn_ = temp;
188    }
189
190    /**
191    @brief
192        Ends the OrxoBlox minigame.
193    */
194    void OrxoBlox::end()
195    {
196        ChatManager::message("You suck!!");
197        this->cleanup();
198
199        // Call end for the parent class.
200        Deathmatch::end();
201    }
202
203    /**
204    @brief
205        Spawns players, and fills the rest up with bots.
206    */
207    void OrxoBlox::spawnPlayersIfRequested()
208    {
209        // first spawn human players to assign always the left bat to the player in singleplayer
210        for (const auto& mapEntry : this->players_)
211            if (mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_))
212                this->spawnPlayer(mapEntry.first);
213        // now spawn bots
214        for (const auto& mapEntry : this->players_)
215            if (!mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_))
216                this->spawnPlayer(mapEntry.first);
217    }
218
219
220    /**
221    @brief
222        Spawns the input player.
223    @param player
224        The player to be spawned.
225    */
226    void OrxoBlox::spawnPlayer(PlayerInfo* player)
227    {
228         assert(player);
229
230        if(this->player_ == nullptr)
231        {
232            this->player_ = player;
233            this->players_[player].state_ = PlayerState::Alive;
234        }
235    }
236
237    /**
238    @brief
239        Is called when the player scored.
240    */
241   
242    //void startWall(void);
243   
244
245
246    void OrxoBlox::createWall(void){
247        this->futureWall_ = new OrxoBloxWall(this->center_->getContext());
248        // Apply the stone template to the stone.
249        this->futureWall_->addTemplate(this->center_->getWallTemplate());
250
251        // Attach the brick to the Centerpoint and set the position of the brick to be at the left side.
252        this->center_->attach(this->futureWall_);
253       
254       
255        this->futureWall_->setPosition(10, 10, 0.0f);
256        this->futureWall_->setGame(this);
257    }
258
259    // void OrxoBlox::createWall(void)             //TODO: random rotation offset between 0 and 3 (times 90°)
260    // {
261    //     // create new futureBrick_
262    //     this->futureWall_ = new TetrisBrick(this->center_->getContext());
263
264
265    //     // Apply the stone template to the stone.
266    //     this->futureBrick_->addTemplate(this->center_->getBrickTemplate());
267
268    //     // Attach the brick to the Centerpoint and set the position of the brick to be at the left side.
269    //     this->center_->attach(this->futureBrick_);
270    //     float xPos = (this->center_->getWidth()*1.6f + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();
271    //     float yPos = (this->center_->getHeight()-5.1f)*this->center_->getStoneSize();
272       
273    //     this->futureBrick_->setPosition(xPos, yPos, 0.0f);
274    //     this->futureBrick_->setGame(this);
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   
288   
289}
Note: See TracBrowser for help on using the repository browser.