[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; |
---|
[10408] | 53 | firePressed_ = false; |
---|
[10451] | 54 | setSelectedPosition(6,6); |
---|
[10408] | 55 | timerSetFire_=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 | |
---|
[10408] | 72 | |
---|
[10394] | 73 | if (hasLocalController()) |
---|
| 74 | { |
---|
[10408] | 75 | timerSetFire_ +=dt; |
---|
[10394] | 76 | |
---|
[10408] | 77 | if(timerSetFire_ >= 0.25) |
---|
| 78 | { |
---|
| 79 | timerSetFire_ = 0; |
---|
[10394] | 80 | |
---|
[10408] | 81 | int selecterPosX = selectedPos_->GetX(); |
---|
| 82 | int selecterPosY = selectedPos_->GetY(); |
---|
[10394] | 83 | |
---|
[10408] | 84 | if (moveUpPressed_ == true) |
---|
| 85 | { |
---|
| 86 | moveUpPressed_ = false; |
---|
| 87 | selectedPos_->Set(selecterPosX, selecterPosY + 1); |
---|
| 88 | updatePosition(); |
---|
| 89 | } |
---|
| 90 | if (moveDownPressed_ == true) |
---|
| 91 | { |
---|
| 92 | moveDownPressed_ = false; |
---|
| 93 | selectedPos_->Set(selecterPosX, selecterPosY - 1); |
---|
| 94 | updatePosition(); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if (moveLeftPressed_ == true) |
---|
| 98 | { |
---|
| 99 | moveLeftPressed_ = false; |
---|
| 100 | selectedPos_->Set(selecterPosX - 1, selecterPosY); |
---|
| 101 | updatePosition(); |
---|
| 102 | } |
---|
| 103 | if (moveRightPressed_ == true) |
---|
| 104 | { |
---|
| 105 | moveRightPressed_ = false; |
---|
| 106 | selectedPos_->Set(selecterPosX + 1, selecterPosY); |
---|
| 107 | updatePosition(); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|
[10394] | 115 | } |
---|
[10408] | 116 | } |
---|
[10394] | 117 | |
---|
| 118 | |
---|
| 119 | void TowerDefenseSelecter::moveFrontBack(const Vector2& value) |
---|
| 120 | { |
---|
| 121 | if (value.x > 0) |
---|
| 122 | { |
---|
| 123 | moveUpPressed_ = true; |
---|
| 124 | moveDownPressed_ = false; |
---|
| 125 | } |
---|
| 126 | else |
---|
| 127 | { |
---|
| 128 | moveUpPressed_ = false; |
---|
| 129 | moveDownPressed_ = true; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | void TowerDefenseSelecter::moveRightLeft(const Vector2& value) |
---|
| 134 | { |
---|
| 135 | if (value.x > 0) |
---|
| 136 | { |
---|
| 137 | moveLeftPressed_ = false; |
---|
| 138 | moveRightPressed_ = true; |
---|
| 139 | } |
---|
| 140 | else |
---|
| 141 | { |
---|
| 142 | moveLeftPressed_ = true; |
---|
| 143 | moveRightPressed_ = false; |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | void TowerDefenseSelecter::rotateYaw(const Vector2& value) |
---|
| 148 | { |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | void TowerDefenseSelecter::rotatePitch(const Vector2& value) |
---|
| 152 | { |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | void TowerDefenseSelecter::rotateRoll(const Vector2& value) |
---|
| 156 | { |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | |
---|
[10408] | 160 | void TowerDefenseSelecter::boost(bool bBoost) |
---|
[10394] | 161 | { |
---|
[10408] | 162 | firePressed_ = true; |
---|
| 163 | orxout() << "boost" << endl; |
---|
[10394] | 164 | } |
---|
[10406] | 165 | |
---|
[10408] | 166 | |
---|
[10406] | 167 | void TowerDefenseSelecter::updatePosition() |
---|
| 168 | { |
---|
| 169 | setPosition(selectedPos_->get3dcoordinate()); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | void TowerDefenseSelecter::setSelectedPosition(TDCoordinate* newPos) |
---|
| 173 | { |
---|
| 174 | selectedPos_ = newPos; |
---|
| 175 | updatePosition(); |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | void TowerDefenseSelecter::setSelectedPosition(int x, int y) |
---|
| 179 | { |
---|
| 180 | setSelectedPosition(new TDCoordinate(x,y)); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | |
---|
[10394] | 184 | } |
---|