Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

BOUNCE

File size: 3.7 KB
Line 
1#include "OrxoBloxWall.h"
2#include "core/CoreIncludes.h"
3#include "core/XMLPort.h"
4
5#include "OrxoBlox.h"
6#include "OrxoBloxStones.h"
7#include "OrxoBloxCenterpoint.h"
8#include "util/Math.h"
9
10namespace orxonox
11{
12    RegisterClass(OrxoBloxWall);
13    /**
14    @brief
15        Constructor. Registers and initializes the object.
16    */
17    OrxoBloxWall::OrxoBloxWall(Context* context) : StaticEntity(context)
18    {
19        RegisterObject(OrxoBloxWall);
20
21        this->num_Stones_ = 10;
22        this->size_ = 9.0f;
23        this->delay_ = false;
24
25        this->orxoblox_ = this->getOrxoBlox();
26        this->center_ = this->orxoblox_->getCenterpoint();
27        this->createWall();
28    }
29
30
31    void OrxoBloxWall::createWall(){
32        for (unsigned int i=0; i<this->num_Stones_;++i){
33            unsigned int j=1 + static_cast<unsigned int>(rnd(2.0f)); //<! random number between 0 and 2;
34            if(j<2){
35                this->size_ = 9.0f;
36                OrxoBloxStones* stone = new OrxoBloxStones(this->center_->getContext());
37                stone->addTemplate(this->orxoblox_->getCenterpoint()->getStoneTemplate());
38                if (stone == nullptr) {
39                    std::abort();
40                }
41                this->TotalStones_.push_back(stone);
42                this->attach(stone);
43                float x_=(this->center_->getFieldDimension()).x;
44                float y_=(this->center_->getFieldDimension()).y;
45                stone->setPosition(size_*i -x_/2 +4.5f, -3.5f, -y_/2 + 6.5f);
46
47
48
49                if(this->orxoblox_ != nullptr)
50                {
51                    stone->setGame(this->orxoblox_);
52                    if(this->orxoblox_->getCenterpoint() != nullptr)
53                        stone->addTemplate(this->orxoblox_->getCenterpoint()->getStoneTemplate());
54                    else
55                        orxout()<< "tetris_->getCenterpoint == nullptr in TetrisBrick.cc"<< endl;
56                }
57                else
58                    orxout()<< "tetris_ == nullptr in TetrisBrick.cc"<< endl;
59            }
60
61        }
62
63        this->num_Stones_ = TotalStones_.size();
64
65
66
67        // OrxoBloxStones* stone = new OrxoBloxStones(this->getContext());
68        // if(this->orxoblox_ != nullptr)
69        //     {
70        //         stone->setGame(this->orxoblox_);
71        //         if(this->orxoblox_->getCenterpoint() != nullptr)
72        //             stone->addTemplate(this->orxoblox_->getCenterpoint()->getStoneTemplate());
73        //         else
74        //             orxout()<< "orxoblox_->getCenterpoint == nullptr in TetrisBrick.cc"<< endl;
75        //     }
76        //     else
77        //         orxout()<< "orxoblox_ == nullptr in TetrisBrick.cc"<< endl;
78    }
79
80    OrxoBloxStones* OrxoBloxWall::getStone(unsigned int i)
81    {
82        if(i < this->TotalStones_.size())
83            return this->TotalStones_[i];
84        else return nullptr;
85    }
86
87    OrxoBlox* OrxoBloxWall::getOrxoBlox()
88    {
89        if (this->getGametype() != nullptr && this->getGametype()->isA(Class(OrxoBlox)))
90        {
91            OrxoBlox* orxobloxGametype = orxonox_cast<OrxoBlox*>(this->getGametype());
92            return orxobloxGametype;
93        }
94        else orxout()<<"There is no Gametype for OrxoBlox! ask Anna"<< endl;
95        return nullptr;
96    }
97
98    int OrxoBloxWall::getNumberOfStones() {
99        return num_Stones_;
100    }
101
102    void OrxoBloxWall::setNumberOfStones(int number) {
103        this->num_Stones_ = number;
104    }
105
106    bool OrxoBloxWall::isEmpty() {
107        if (num_Stones_ == 0) {
108            return true;
109        }
110        return false;
111    }
112
113    void OrxoBloxWall::reduceNumberOfStones() {
114        if(num_Stones_ == 0) {
115            orxout() << "Wanted to reduce number of stones, but there were none" << endl;
116        }
117        this->num_Stones_ -= 1;
118    }
119}
Note: See TracBrowser for help on using the repository browser.