Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

We have new template

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