Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

last commit

File size: 5.0 KB
RevLine 
[12212]1#include "OrxoBlox.h"
[12308]2#include "Highscore.h"
[12210]3
4#include "core/CoreIncludes.h"
5#include "core/EventIncludes.h"
6#include "core/command/Executor.h"
7
[12308]8
9#include "core/config/ConfigValueIncludes.h"//Remove??
10
[12210]11#include "gamestates/GSLevel.h"
12
[12308]13
14#include "chat/ChatManager.h"//Remove?
15
[12212]16#include "OrxoBloxCenterpoint.h"
[12268]17#include "OrxoBloxStones.h"
[12288]18#include "OrxoBloxWall.h"
[12314]19#include "OrxoBloxShip.h"
[12260]20
[12210]21namespace orxonox
22{
[12308]23   
[12210]24
[12212]25    RegisterUnloadableClass(OrxoBlox);
[12210]26
27    /**
28    @brief
29        Constructor. Registers and initializes the object.
30    */
[12366]31    OrxoBlox::OrxoBlox(Context* context) : Deathmatch(context)
[12210]32    {
[12212]33        RegisterObject(OrxoBlox);
[12210]34
35        this->center_ = nullptr;
[12371]36        //this->ball_ = nullptr;
[12280]37        this->futureWall_ = nullptr;
[12307]38        this->player_ = nullptr;
[12331]39        level_ = 0;
[12394]40        this->counter = 0;
[12210]41
[12307]42        this->setHUDTemplate("OrxoBloxHUD");
[12277]43        //Error when specified
[12210]44
45        // Pre-set the timer, but don't start it yet.
[12371]46        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&OrxoBlox::LevelUp, this)));
[12210]47        this->starttimer_.stopTimer();
48
[12307]49       
[12210]50
51    }
52
53    /**
54    @brief
55        Destructor. Cleans up, if initialized.
56    */
[12212]57    OrxoBlox::~OrxoBlox()
[12210]58    {
59        if (this->isInitialized())
60            this->cleanup();
61    }
62
63    /**
64    @brief
65        Cleans up the Gametype by destroying the ball and the bats.
66    */
[12212]67    void OrxoBlox::cleanup()
[12376]68    {   
[12210]69
[12396]70        std::vector<OrxoBloxWall*> vyserion_targets;
71        std::vector<OrxoBloxStones*> casterly_rocks;
72
73        for (OrxoBloxWall* wall : ObjectList<OrxoBloxWall>()) {
74            if(wall != nullptr) {
75                vyserion_targets.push_back(wall);
[12307]76            }
[12396]77        }
[12395]78        for (OrxoBloxStones* stone : ObjectList<OrxoBloxStones>()) {
[12396]79            if(stone != nullptr) {
80                casterly_rocks.push_back(stone);
81            }
[12395]82        }
[12396]83        for(unsigned int i = 0; i < vyserion_targets.size(); i++) {
84            vyserion_targets.at(i)->destroy();
[12392]85        }
[12396]86        for(unsigned int i = 0; i < casterly_rocks.size(); i++) {
87            casterly_rocks.at(i)->destroy();
[12392]88        }
[12210]89
90    }
91
92    /**
[12307]93    @brieftt   
[12212]94        Starts the OrxoBlox minigame.
[12210]95    */
[12212]96    void OrxoBlox::start()
[12367]97
[12210]98    {
[12376]99        orxout() << "Orxoblox started" << endl;
[12212]100        if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place.
[12210]101        {
[12394]102            level_= 1;
[12210]103        }
104        else // If no centerpoint was specified, an error is thrown and the level is exited.
105        {
[12212]106            orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl;
[12210]107            GSLevel::startMainMenu();
108            return;
109        }
110        this->starttimer_.startTimer();
111
[12370]112        this->bForceSpawn_ = false;
[12210]113        Deathmatch::start();
114    }
115
116    /**
117    @brief
[12212]118        Ends the OrxoBlox minigame.
[12210]119    */
[12212]120    void OrxoBlox::end()
[12210]121    {
[12268]122        ChatManager::message("You suck!!");
[12359]123
124        if (Highscore::exists())
125        {
126            int score = this->getScore(this->getPlayer());
[12382]127            Highscore::getInstance().storeScore("OrxoBlox", score, this->getPlayer());
[12359]128        }
129
[12210]130        this->cleanup();
131
132        // Call end for the parent class.
133        Deathmatch::end();
[12395]134        //GSLevel::startMainMenu();
[12210]135    }
136
[12359]137    PlayerInfo* OrxoBlox::getPlayer()
[12337]138    {
[12359]139        return this->player_;
[12337]140    }
141   
[12210]142
[12331]143    void OrxoBlox::LevelUp(){
144        level_++;
[12402]145        if((level_%10)==0){
146            --counter;
147        }
[12379]148        int z_ = 0;
[12376]149
150        orxout() << "level up called" << endl;
[12395]151        this->playerScored(this->player_);// add points
[12355]152
[12351]153        this->createWall();
[12360]154
[12395]155        for(OrxoBloxStones* stone : ObjectList<OrxoBloxStones>()){
156            if (stone->isA(Class(OrxoBloxStones))) {
[12392]157                int x_=(stone->getPosition()).x;
158                int y_=(stone->getPosition()).y;
159                z_=(stone->getPosition()).z;
160                //if(z_==90)this->end();
[12384]161
[12392]162                stone->setPosition(x_,y_,z_+9.0f);
163                if( z_ >= 45){
164                    orxout() << "calling end() function" << endl;
165                    this->end();
[12396]166                    return;
[12392]167                }
[12376]168            }
[12395]169            else {
[12396]170                orxout() << "WTF IS THIS SHIT?!?!?!" << endl;
[12395]171            }
[12384]172        }
[12331]173    }
[12210]174
[12350]175    void OrxoBlox::createWall(){
[12307]176        this->futureWall_ = new OrxoBloxWall(this->center_->getContext());
177        // Apply the stone template to the stone.
178        this->futureWall_->addTemplate(this->center_->getWallTemplate());
[12210]179
[12307]180        // Attach the brick to the Centerpoint and set the position of the brick to be at the left side.
181        this->center_->attach(this->futureWall_);
182       
[12345]183        this->futureWall_->setPosition(0, 0, 0);
[12307]184        this->futureWall_->setGame(this);
[12210]185    }
186
[12278]187
[12367]188    void OrxoBlox::playerPreSpawn(PlayerInfo* player)
189    {
190        this->player_ = player;
191    }
[12260]192   
[12391]193    void OrxoBlox::tick(float dt)
194    {       
195        SUPER(OrxoBlox, tick, dt);
196    }
[12396]197 
[12394]198    void OrxoBlox::count() {
[12395]199        if(++(this->counter) >= this->max_counter) {
[12394]200            this->LevelUp();
201            counter = 0;
202            return;
203        }
204    }
205
206
[12210]207}
Note: See TracBrowser for help on using the repository browser.