[10394] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabien Vultier |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file TowerDefenseSelecter.cc |
---|
| 31 | @brief This class represents your figure when you play the minigame. Here the movement of the figure, activating items, ... are handled. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "TowerDefenseSelecter.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/XMLPort.h" |
---|
| 38 | #include "graphics/Model.h" |
---|
| 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
| 42 | RegisterClass(TowerDefenseSelecter); |
---|
| 43 | |
---|
| 44 | TowerDefenseSelecter::TowerDefenseSelecter(Context* context) : ControllableEntity(context) |
---|
| 45 | { |
---|
| 46 | RegisterObject(TowerDefenseSelecter); |
---|
| 47 | |
---|
| 48 | // initialize variables |
---|
| 49 | moveUpPressed_ = false; |
---|
| 50 | moveDownPressed_ = false; |
---|
| 51 | moveLeftPressed_ = false; |
---|
| 52 | moveRightPressed_ = false; |
---|
[10629] | 53 | boostPressed_ = false; |
---|
| 54 | buildTower_ = false; |
---|
| 55 | setSelectedPosition(0,0); |
---|
[10394] | 56 | } |
---|
| 57 | |
---|
| 58 | TowerDefenseSelecter::~TowerDefenseSelecter() |
---|
| 59 | { |
---|
| 60 | |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | void TowerDefenseSelecter::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 64 | { |
---|
| 65 | SUPER(TowerDefenseSelecter, XMLPort, xmlelement, mode); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void TowerDefenseSelecter::tick(float dt) |
---|
| 69 | { |
---|
| 70 | SUPER(TowerDefenseSelecter, tick, dt); |
---|
| 71 | |
---|
[10629] | 72 | time_ += dt; |
---|
[10408] | 73 | |
---|
[10629] | 74 | if (hasLocalController() && time_ >= 0.25) |
---|
| 75 | { |
---|
| 76 | time_ = 0; |
---|
[10394] | 77 | |
---|
[10629] | 78 | int selecterPosX = selectedPos_->GetX(); |
---|
| 79 | int selecterPosY = selectedPos_->GetY(); |
---|
[10394] | 80 | |
---|
[10629] | 81 | if (moveUpPressed_ == true) |
---|
| 82 | { |
---|
| 83 | moveUpPressed_ = false; |
---|
| 84 | selectedPos_->Set(selecterPosX, selecterPosY + 1); |
---|
| 85 | updatePosition(); |
---|
| 86 | } |
---|
| 87 | if (moveDownPressed_ == true) |
---|
| 88 | { |
---|
| 89 | moveDownPressed_ = false; |
---|
| 90 | selectedPos_->Set(selecterPosX, selecterPosY - 1); |
---|
| 91 | updatePosition(); |
---|
| 92 | } |
---|
| 93 | if (moveLeftPressed_ == true) |
---|
| 94 | { |
---|
| 95 | moveLeftPressed_ = false; |
---|
| 96 | selectedPos_->Set(selecterPosX - 1, selecterPosY); |
---|
| 97 | updatePosition(); |
---|
| 98 | } |
---|
| 99 | if (moveRightPressed_ == true) |
---|
| 100 | { |
---|
| 101 | moveRightPressed_ = false; |
---|
| 102 | selectedPos_->Set(selecterPosX + 1, selecterPosY); |
---|
| 103 | updatePosition(); |
---|
| 104 | } |
---|
| 105 | if (boostPressed_ == true) |
---|
| 106 | { |
---|
| 107 | boostPressed_ = false; |
---|
| 108 | buildTower_ = true; |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | } |
---|
[10394] | 112 | |
---|
[10408] | 113 | |
---|
[10394] | 114 | void TowerDefenseSelecter::moveFrontBack(const Vector2& value) |
---|
| 115 | { |
---|
| 116 | if (value.x > 0) |
---|
| 117 | { |
---|
| 118 | moveUpPressed_ = true; |
---|
| 119 | moveDownPressed_ = false; |
---|
| 120 | } |
---|
| 121 | else |
---|
| 122 | { |
---|
| 123 | moveUpPressed_ = false; |
---|
| 124 | moveDownPressed_ = true; |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | void TowerDefenseSelecter::moveRightLeft(const Vector2& value) |
---|
| 129 | { |
---|
| 130 | if (value.x > 0) |
---|
| 131 | { |
---|
| 132 | moveLeftPressed_ = false; |
---|
| 133 | moveRightPressed_ = true; |
---|
| 134 | } |
---|
| 135 | else |
---|
| 136 | { |
---|
| 137 | moveLeftPressed_ = true; |
---|
| 138 | moveRightPressed_ = false; |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | void TowerDefenseSelecter::rotateYaw(const Vector2& value) |
---|
| 143 | { |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | void TowerDefenseSelecter::rotatePitch(const Vector2& value) |
---|
| 147 | { |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | void TowerDefenseSelecter::rotateRoll(const Vector2& value) |
---|
| 151 | { |
---|
| 152 | } |
---|
| 153 | |
---|
[10629] | 154 | void TowerDefenseSelecter::fire(unsigned int firemode) |
---|
| 155 | { |
---|
| 156 | } |
---|
[10394] | 157 | |
---|
[10629] | 158 | void TowerDefenseSelecter::fired(unsigned int firemode) |
---|
| 159 | { |
---|
| 160 | |
---|
| 161 | } |
---|
| 162 | |
---|
[10408] | 163 | void TowerDefenseSelecter::boost(bool bBoost) |
---|
[10394] | 164 | { |
---|
[10629] | 165 | if (bBoost == true) |
---|
| 166 | { |
---|
| 167 | boostPressed_ = true; |
---|
| 168 | } |
---|
[10394] | 169 | } |
---|
[10406] | 170 | |
---|
| 171 | void TowerDefenseSelecter::updatePosition() |
---|
| 172 | { |
---|
| 173 | setPosition(selectedPos_->get3dcoordinate()); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | void TowerDefenseSelecter::setSelectedPosition(TDCoordinate* newPos) |
---|
| 177 | { |
---|
| 178 | selectedPos_ = newPos; |
---|
| 179 | updatePosition(); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | void TowerDefenseSelecter::setSelectedPosition(int x, int y) |
---|
| 183 | { |
---|
| 184 | setSelectedPosition(new TDCoordinate(x,y)); |
---|
| 185 | } |
---|
[10394] | 186 | } |
---|