Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12388 was 12384, checked in by pomselj, 5 years ago

OrxoBlox is linked to Projectile, level up works

File size: 10.2 KB
RevLine 
[12210]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/**
[12212]30    @file OrxoBlox.cc
31    @brief Implementation of the OrxoBlox class.
[12210]32*/
33
[12212]34#include "OrxoBlox.h"
[12308]35#include "Highscore.h"
[12210]36
37#include "core/CoreIncludes.h"
38#include "core/EventIncludes.h"
39#include "core/command/Executor.h"
40
[12308]41
42#include "core/config/ConfigValueIncludes.h"//Remove??
43
[12210]44#include "gamestates/GSLevel.h"
45
[12308]46
47#include "chat/ChatManager.h"//Remove?
48
[12212]49#include "OrxoBloxCenterpoint.h"
[12268]50#include "OrxoBloxStones.h"
[12288]51#include "OrxoBloxWall.h"
[12314]52#include "OrxoBloxShip.h"
[12260]53
[12210]54namespace orxonox
55{
[12308]56   
[12210]57
[12212]58    RegisterUnloadableClass(OrxoBlox);
[12210]59
60    /**
61    @brief
62        Constructor. Registers and initializes the object.
63    */
[12366]64    OrxoBlox::OrxoBlox(Context* context) : Deathmatch(context)
[12210]65    {
[12212]66        RegisterObject(OrxoBlox);
[12210]67
68        this->center_ = nullptr;
[12371]69        //this->ball_ = nullptr;
[12280]70        this->futureWall_ = nullptr;
[12307]71        this->player_ = nullptr;
[12331]72        level_ = 0;
[12210]73
[12307]74        this->setHUDTemplate("OrxoBloxHUD");
[12277]75        //Error when specified
[12210]76
77        // Pre-set the timer, but don't start it yet.
[12371]78        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&OrxoBlox::LevelUp, this)));
[12210]79        this->starttimer_.stopTimer();
80
[12307]81       
[12210]82
83    }
84
85    /**
86    @brief
87        Destructor. Cleans up, if initialized.
88    */
[12212]89    OrxoBlox::~OrxoBlox()
[12210]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    */
[12212]99    void OrxoBlox::cleanup()
[12376]100    {   
[12371]101        //if (this->ball_ != nullptr) // Destroy the ball, if present.
102        //{
103        //    this->ball_->destroy();
104        //    this->ball_ = nullptr;
105        //}
[12210]106
[12376]107        /*if (this->futureWall_ != nullptr)
[12307]108            {
[12349]109            this->futureWall_->destroy();
110            this->futureWall_ = nullptr;
[12307]111            }
[12376]112        */
113       
[12349]114        for (OrxoBloxWall* wall : this->activeWalls_)
[12368]115            if (wall != nullptr)
[12376]116                wall->destroy();
[12349]117        this->activeWalls_.clear();
118       
119
[12343]120        for (OrxoBloxStones* stone : this->stones_)
[12368]121            if(stone != nullptr)
[12343]122            stone->destroy();
123        this->stones_.clear();
124       
[12210]125
126    }
127
128    /**
[12307]129    @brieftt   
[12212]130        Starts the OrxoBlox minigame.
[12210]131    */
[12212]132    void OrxoBlox::start()
[12367]133
[12210]134    {
[12376]135        orxout() << "Orxoblox started" << endl;
[12212]136        if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place.
[12210]137        {
[12371]138            //if (this->ball_ == nullptr) // If there is no ball, create a new ball.
139            //{
140            //    this->ball_ = new OrxoBloxBall(this->center_->getContext());
[12210]141                // Apply the template for the ball specified by the centerpoint.
[12371]142            //    this->ball_->addTemplate(this->center_->getBalltemplate());
143            //}
[12210]144
145            // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to.
[12371]146            //this->center_->attach(this->ball_);
[12339]147            //Startposition Ball
[12371]148            //this->ball_->setPosition(0, 0, 40);
149            //this->ball_->setFieldDimension(this->center_->getFieldDimension());
150            //this->ball_->setSpeed(0);
151            //this->ball_->setAccelerationFactor(this->center_->getBallAccelerationFactor());
[12366]152           
[12331]153            level_=1;
[12307]154
155            // Create the first Wall.
[12349]156            this->LevelUp();
[12307]157
[12382]158
159
[12337]160            //Create Ship
161            //this->ship_ = new OrxoBloxShip(this->center_->getContext());
162            //this->ship_->setPosition(0, 0, 0);
163
[12210]164        }
165        else // If no centerpoint was specified, an error is thrown and the level is exited.
166        {
[12212]167            orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl;
[12210]168            GSLevel::startMainMenu();
169            return;
170        }
171
172        // Start the timer. After it has expired the ball is started.
173        this->starttimer_.startTimer();
174
175        // Set variable to temporarily force the player to spawn.
[12359]176        // Set variable to temporarily force the player to spawn.
[12367]177        //bool temp = this->bForceSpawn_;
[12370]178        this->bForceSpawn_ = false;
[12210]179
180        // Call start for the parent class.
181        Deathmatch::start();
182
[12359]183        // Reset the variable.
[12367]184        //this->bForceSpawn_ = temp;
[12359]185
[12210]186    }
187
188    /**
189    @brief
[12212]190        Ends the OrxoBlox minigame.
[12210]191    */
[12212]192    void OrxoBlox::end()
[12210]193    {
[12268]194        ChatManager::message("You suck!!");
[12359]195
196        if (Highscore::exists())
197        {
198            int score = this->getScore(this->getPlayer());
[12382]199            Highscore::getInstance().storeScore("OrxoBlox", score, this->getPlayer());
[12359]200        }
201
[12210]202        this->cleanup();
203
204        // Call end for the parent class.
205        Deathmatch::end();
[12351]206        GSLevel::startMainMenu();
[12210]207    }
208
[12359]209    PlayerInfo* OrxoBlox::getPlayer()
[12337]210    {
[12359]211        return this->player_;
[12337]212    }
213   
[12367]214    // void OrxoBlox::spawnPlayer(PlayerInfo* player)
215    // {
216    //     assert(player);
[12210]217
[12367]218    //     if(this->player_ == nullptr)
219    //     {
220    //         this->player_ = player;
221    //         this->players_[player].state_ = PlayerState::Alive;
222    //     }
[12210]223
[12367]224    // }
[12314]225
[12331]226    void OrxoBlox::LevelUp(){
227        level_++;
[12379]228        int z_ = 0;
[12376]229
230        orxout() << "level up called" << endl;
[12359]231        this->playerScored(this->player_);// add points
[12384]232       
[12355]233
234
[12351]235        this->createWall();
[12345]236        this->activeWalls_.push_back(this->futureWall_);
[12350]237        for (int i = 0; i < this->futureWall_->getNumberOfStones(); i++) {
238            if (this->futureWall_->getStone(i) == nullptr) {
239                orxout() << "Added nullptr to std::list stones_" << endl;
240            }
[12349]241
[12346]242            this->stones_.push_back(this->futureWall_->getStone(i));
[12350]243        }
[12360]244
245        for(OrxoBloxWall* wall : this->activeWalls_) {
246            if(wall->isEmpty()) {
247                wall->destroy();
248            }
249            int NumberOfStones = 0;
250            for(int i = 0; i < 10; i++) {
251                if(wall->getStone(i) == nullptr) {
252                    continue;
253                }
254                else {
255                    NumberOfStones++;
256                }
257
258            }
259        }
[12331]260        //new location of ship
261        //new amount of balls
262        //create balls
263        //insert new wall
[12384]264        for(OrxoBloxStones* stone : this->stones_){
265            if (stone != nullptr) {
266            int x_=(stone->getPosition()).x;
267            int y_=(stone->getPosition()).y;
268            z_=(stone->getPosition()).z;
269            //if(z_==90)this->end();
270
271            stone->setPosition(x_,y_,z_+9.0f);
272            if( z_ >= 45){
273                orxout() << "calling end() function" << endl;
274                this->end();
[12376]275            }
[12384]276            }
277           
278        }
279
[12376]280       
[12331]281    }
[12210]282
[12350]283    void OrxoBlox::createWall(){
[12307]284        this->futureWall_ = new OrxoBloxWall(this->center_->getContext());
285        // Apply the stone template to the stone.
286        this->futureWall_->addTemplate(this->center_->getWallTemplate());
[12210]287
[12307]288        // Attach the brick to the Centerpoint and set the position of the brick to be at the left side.
289        this->center_->attach(this->futureWall_);
290       
[12345]291        this->futureWall_->setPosition(0, 0, 0);
[12307]292        this->futureWall_->setGame(this);
[12210]293    }
294
[12278]295
[12210]296    /**
297    @brief
298        Starts the ball with some default speed.
299    */
[12371]300    //void OrxoBlox::startBall()
301    //{
302    //    if (this->ball_ != nullptr && this->center_ != nullptr)
303    //        this->ball_->setSpeed(this->center_->getBallSpeed());
304    //}
[12368]305     
[12371]306    /*OrxoBloxStones* OrxoBlox::CheckForCollision(OrxoBloxBall* Ball) {
[12367]307        //orxout() << "Checking for Collision" << endl;
[12346]308        Vector3 BallPosition = Ball->getPosition();
309        for(OrxoBloxStones* someStone : this->stones_)
310        {
[12350]311            if(someStone == nullptr)
312            {
313                continue;
314            }
[12367]315            //orxout() << "Checking a stone" << endl;
[12346]316            const Vector3& StonePosition = someStone->getPosition(); //!< Saves the position of the currentStone
[12360]317            int size = someStone->getSize()/2;
318            if((BallPosition.x - Ball->getRadius() >= StonePosition.x - size && BallPosition.x + Ball->getRadius() <= StonePosition.x + size) &&
319                (BallPosition.z - Ball->getRadius() >= StonePosition.z - size && BallPosition.z + Ball->getRadius() <= StonePosition.z + size)) {
[12370]320                //orxout() << "FOUND ONE" << endl;
[12346]321                return someStone;
322            }
323        }
324        orxout() << "Found nothing...." << endl;
325        return nullptr;
[12350]326    }
[12371]327    */
[12367]328
329    void OrxoBlox::playerPreSpawn(PlayerInfo* player)
330    {
331        this->player_ = player;
332    }
[12260]333   
[12368]334/*
335    bool OrxoBlox::Intersect(int XpositionBall, int XPositionBlock, int YPositionBall, int YPositionBlock, int radiusBall, int sizeBlock) {
336        distanceX = XpositionBall - XPositionBlock;
337        distanceY = YPositionBall - YPositionBlock;
338        if (distanceX < 0) {
339            distanceX = -distanceX;
340        }
341        if (distanceY < 0) {
342            distanceY = -distanceY;
343        }
344        if((distanceX <= radiusBall + sizeBlock) || (distanceY <= radiusBall + sizeBlock)) {
345            return true;
346        }
347        else {
348            top = YPositionBall + radiusBall;
349            right = XpositionBall + radiusBall;
350            bottom = YPositionBall - radiusBall;
351            left = XpositionBall - radiusBall;
352
353            if((top >= YPositionBlock - size) && (top <= YPositionBlock + size) && (left <= XPositionBlock + size) && (left >= XPositionBlock - size))
354        }
355    }
356  */ 
[12210]357}
Note: See TracBrowser for help on using the repository browser.