[12278] | 1 | #include "OrxoBloxWall.h" |
---|
| 2 | #include "core/CoreIncludes.h" |
---|
| 3 | #include "core/XMLPort.h" |
---|
| 4 | |
---|
| 5 | #include "OrxoBlox.h" |
---|
[12331] | 6 | #include "OrxoBloxStones.h" |
---|
| 7 | #include "OrxoBloxCenterpoint.h" |
---|
| 8 | #include "util/Math.h" |
---|
[12278] | 9 | |
---|
| 10 | namespace 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 | |
---|
[12335] | 21 | this->num_Stones_ = 1 + static_cast<unsigned int>(rnd(6.0f)); //<! random number between 0 and 7; |
---|
| 22 | this->size_ = 9.0f; |
---|
[12278] | 23 | this->delay_ = false; |
---|
[12307] | 24 | this->orxoblox_ = this->getOrxoBlox(); |
---|
[12331] | 25 | this->createWall(); |
---|
| 26 | } |
---|
[12307] | 27 | |
---|
| 28 | |
---|
[12331] | 29 | void OrxoBloxWall::createWall(void){ |
---|
| 30 | for (unsigned int i=0; i<this->num_Stones_;++i){ |
---|
[12335] | 31 | unsigned int j=1 + static_cast<unsigned int>(rnd(2.0f)); //<! random number between 0 and 2; |
---|
| 32 | if(j<2){ |
---|
| 33 | this->size_ = 9.0f; |
---|
| 34 | OrxoBloxStones* stone = new OrxoBloxStones(this->getContext()); |
---|
| 35 | this->TotalStones_.push_back(stone); |
---|
| 36 | this->attach(stone); |
---|
| 37 | stone->setPosition(size_*i -55.5f, 0, 0.0f); |
---|
[12331] | 38 | |
---|
| 39 | |
---|
| 40 | |
---|
[12335] | 41 | if(this->orxoblox_ != nullptr) |
---|
| 42 | { |
---|
| 43 | stone->setGame(this->orxoblox_); |
---|
| 44 | if(this->orxoblox_->getCenterpoint() != nullptr) |
---|
| 45 | stone->addTemplate(this->orxoblox_->getCenterpoint()->getStoneTemplate()); |
---|
| 46 | else |
---|
| 47 | orxout()<< "tetris_->getCenterpoint == nullptr in TetrisBrick.cc"<< endl; |
---|
| 48 | } |
---|
[12307] | 49 | else |
---|
[12335] | 50 | orxout()<< "tetris_ == nullptr in TetrisBrick.cc"<< endl; |
---|
[12307] | 51 | } |
---|
[12331] | 52 | |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | // OrxoBloxStones* stone = new OrxoBloxStones(this->getContext()); |
---|
| 58 | // if(this->orxoblox_ != nullptr) |
---|
| 59 | // { |
---|
| 60 | // stone->setGame(this->orxoblox_); |
---|
| 61 | // if(this->orxoblox_->getCenterpoint() != nullptr) |
---|
| 62 | // stone->addTemplate(this->orxoblox_->getCenterpoint()->getStoneTemplate()); |
---|
| 63 | // else |
---|
| 64 | // orxout()<< "orxoblox_->getCenterpoint == nullptr in TetrisBrick.cc"<< endl; |
---|
| 65 | // } |
---|
| 66 | // else |
---|
| 67 | // orxout()<< "orxoblox_ == nullptr in TetrisBrick.cc"<< endl; |
---|
[12278] | 68 | } |
---|
[12307] | 69 | |
---|
[12331] | 70 | OrxoBloxStones* OrxoBloxWall::getStone(unsigned int i) |
---|
| 71 | { |
---|
| 72 | if(i < this->TotalStones_.size()) |
---|
| 73 | return this->TotalStones_[i]; |
---|
| 74 | else return nullptr; |
---|
| 75 | } |
---|
[12307] | 76 | |
---|
| 77 | OrxoBlox* OrxoBloxWall::getOrxoBlox() |
---|
| 78 | { |
---|
| 79 | if (this->getGametype() != nullptr && this->getGametype()->isA(Class(OrxoBlox))) |
---|
| 80 | { |
---|
| 81 | OrxoBlox* orxobloxGametype = orxonox_cast<OrxoBlox*>(this->getGametype()); |
---|
| 82 | return orxobloxGametype; |
---|
| 83 | } |
---|
[12308] | 84 | else orxout()<<"There is no Gametype for OrxoBlox! ask Anna"<< endl; |
---|
[12307] | 85 | return nullptr; |
---|
| 86 | } |
---|
[12278] | 87 | } |
---|