[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 | |
---|
[12341] | 21 | this->num_Stones_ = 10; |
---|
[12335] | 22 | this->size_ = 9.0f; |
---|
[12278] | 23 | this->delay_ = false; |
---|
[12341] | 24 | |
---|
[12307] | 25 | this->orxoblox_ = this->getOrxoBlox(); |
---|
[12341] | 26 | this->center_ = this->orxoblox_->getCenterpoint(); |
---|
[12331] | 27 | this->createWall(); |
---|
| 28 | } |
---|
[12307] | 29 | |
---|
| 30 | |
---|
[12331] | 31 | void OrxoBloxWall::createWall(void){ |
---|
| 32 | for (unsigned int i=0; i<this->num_Stones_;++i){ |
---|
[12335] | 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->getContext()); |
---|
| 37 | this->TotalStones_.push_back(stone); |
---|
| 38 | this->attach(stone); |
---|
[12341] | 39 | float x_=(this->center_->getFieldDimension()).x; |
---|
| 40 | float y_=(this->center_->getFieldDimension()).y; |
---|
| 41 | stone->setPosition(size_*i -x_/2 +4.5f, -3.5f, -y_/2 + 6.5f); |
---|
[12331] | 42 | |
---|
| 43 | |
---|
| 44 | |
---|
[12335] | 45 | if(this->orxoblox_ != nullptr) |
---|
| 46 | { |
---|
| 47 | stone->setGame(this->orxoblox_); |
---|
| 48 | if(this->orxoblox_->getCenterpoint() != nullptr) |
---|
| 49 | stone->addTemplate(this->orxoblox_->getCenterpoint()->getStoneTemplate()); |
---|
| 50 | else |
---|
| 51 | orxout()<< "tetris_->getCenterpoint == nullptr in TetrisBrick.cc"<< endl; |
---|
| 52 | } |
---|
[12307] | 53 | else |
---|
[12335] | 54 | orxout()<< "tetris_ == nullptr in TetrisBrick.cc"<< endl; |
---|
[12307] | 55 | } |
---|
[12331] | 56 | |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | // OrxoBloxStones* stone = new OrxoBloxStones(this->getContext()); |
---|
| 62 | // if(this->orxoblox_ != nullptr) |
---|
| 63 | // { |
---|
| 64 | // stone->setGame(this->orxoblox_); |
---|
| 65 | // if(this->orxoblox_->getCenterpoint() != nullptr) |
---|
| 66 | // stone->addTemplate(this->orxoblox_->getCenterpoint()->getStoneTemplate()); |
---|
| 67 | // else |
---|
| 68 | // orxout()<< "orxoblox_->getCenterpoint == nullptr in TetrisBrick.cc"<< endl; |
---|
| 69 | // } |
---|
| 70 | // else |
---|
| 71 | // orxout()<< "orxoblox_ == nullptr in TetrisBrick.cc"<< endl; |
---|
[12278] | 72 | } |
---|
[12307] | 73 | |
---|
[12331] | 74 | OrxoBloxStones* OrxoBloxWall::getStone(unsigned int i) |
---|
| 75 | { |
---|
| 76 | if(i < this->TotalStones_.size()) |
---|
| 77 | return this->TotalStones_[i]; |
---|
| 78 | else return nullptr; |
---|
| 79 | } |
---|
[12307] | 80 | |
---|
| 81 | OrxoBlox* OrxoBloxWall::getOrxoBlox() |
---|
| 82 | { |
---|
| 83 | if (this->getGametype() != nullptr && this->getGametype()->isA(Class(OrxoBlox))) |
---|
| 84 | { |
---|
| 85 | OrxoBlox* orxobloxGametype = orxonox_cast<OrxoBlox*>(this->getGametype()); |
---|
| 86 | return orxobloxGametype; |
---|
| 87 | } |
---|
[12308] | 88 | else orxout()<<"There is no Gametype for OrxoBlox! ask Anna"<< endl; |
---|
[12307] | 89 | return nullptr; |
---|
| 90 | } |
---|
[12346] | 91 | |
---|
| 92 | int OrxoBloxWall::getNumberOfStones() { |
---|
| 93 | return num_Stones_; |
---|
| 94 | } |
---|
[12278] | 95 | } |
---|