Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

kinda done

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