[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; |
---|
[12392] | 36 | OrxoBloxStones* stone = new OrxoBloxStones(this->center_->getContext()); |
---|
[12393] | 37 | stone->addTemplate(this->orxoblox_->getCenterpoint()->getStoneTemplate()); |
---|
[12350] | 38 | if (stone == nullptr) { |
---|
| 39 | std::abort(); |
---|
| 40 | } |
---|
[12335] | 41 | this->TotalStones_.push_back(stone); |
---|
| 42 | this->attach(stone); |
---|
[12341] | 43 | float x_=(this->center_->getFieldDimension()).x; |
---|
| 44 | float y_=(this->center_->getFieldDimension()).y; |
---|
[12400] | 45 | stone->setPosition(size_*i -x_/2 +4.5f, -3.5f, -y_/2 - 2.25f); |
---|
[12331] | 46 | |
---|
| 47 | |
---|
| 48 | |
---|
[12335] | 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 | } |
---|
[12307] | 57 | else |
---|
[12335] | 58 | orxout()<< "tetris_ == nullptr in TetrisBrick.cc"<< endl; |
---|
[12307] | 59 | } |
---|
[12331] | 60 | |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | // OrxoBloxStones* stone = new OrxoBloxStones(this->getContext()); |
---|
| 66 | // if(this->orxoblox_ != nullptr) |
---|
| 67 | // { |
---|
| 68 | // stone->setGame(this->orxoblox_); |
---|
| 69 | // if(this->orxoblox_->getCenterpoint() != nullptr) |
---|
| 70 | // stone->addTemplate(this->orxoblox_->getCenterpoint()->getStoneTemplate()); |
---|
| 71 | // else |
---|
| 72 | // orxout()<< "orxoblox_->getCenterpoint == nullptr in TetrisBrick.cc"<< endl; |
---|
| 73 | // } |
---|
| 74 | // else |
---|
| 75 | // orxout()<< "orxoblox_ == nullptr in TetrisBrick.cc"<< endl; |
---|
[12278] | 76 | } |
---|
[12307] | 77 | |
---|
[12331] | 78 | OrxoBloxStones* OrxoBloxWall::getStone(unsigned int i) |
---|
| 79 | { |
---|
| 80 | if(i < this->TotalStones_.size()) |
---|
| 81 | return this->TotalStones_[i]; |
---|
| 82 | else return nullptr; |
---|
| 83 | } |
---|
[12307] | 84 | |
---|
| 85 | OrxoBlox* OrxoBloxWall::getOrxoBlox() |
---|
| 86 | { |
---|
| 87 | if (this->getGametype() != nullptr && this->getGametype()->isA(Class(OrxoBlox))) |
---|
| 88 | { |
---|
| 89 | OrxoBlox* orxobloxGametype = orxonox_cast<OrxoBlox*>(this->getGametype()); |
---|
| 90 | return orxobloxGametype; |
---|
| 91 | } |
---|
[12308] | 92 | else orxout()<<"There is no Gametype for OrxoBlox! ask Anna"<< endl; |
---|
[12307] | 93 | return nullptr; |
---|
| 94 | } |
---|
[12346] | 95 | |
---|
| 96 | int OrxoBloxWall::getNumberOfStones() { |
---|
[12395] | 97 | return TotalStones_.size(); |
---|
[12346] | 98 | } |
---|
[12360] | 99 | |
---|
| 100 | void OrxoBloxWall::setNumberOfStones(int number) { |
---|
| 101 | this->num_Stones_ = number; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | bool OrxoBloxWall::isEmpty() { |
---|
| 105 | if (num_Stones_ == 0) { |
---|
| 106 | return true; |
---|
| 107 | } |
---|
| 108 | return false; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | void OrxoBloxWall::reduceNumberOfStones() { |
---|
| 112 | if(num_Stones_ == 0) { |
---|
| 113 | orxout() << "Wanted to reduce number of stones, but there were none" << endl; |
---|
| 114 | } |
---|
| 115 | this->num_Stones_ -= 1; |
---|
| 116 | } |
---|
[12278] | 117 | } |
---|