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