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 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file JumpFigure.cc |
---|
31 | @brief Implementation of the JumpFigure class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "JumpFigure.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/XMLPort.h" |
---|
38 | |
---|
39 | namespace orxonox |
---|
40 | { |
---|
41 | RegisterClass(JumpFigure); |
---|
42 | |
---|
43 | /** |
---|
44 | @brief |
---|
45 | Constructor. Registers and initializes the object. |
---|
46 | */ |
---|
47 | JumpFigure::JumpFigure(Context* context) : ControllableEntity(context) |
---|
48 | { |
---|
49 | RegisterObject(JumpFigure); |
---|
50 | |
---|
51 | this->movement_ = 0; |
---|
52 | this->bMoveLocal_ = false; |
---|
53 | this->length_ = 0.25; |
---|
54 | this->fieldWidth_ = 180; |
---|
55 | this->bSteadiedPosition_ = false; |
---|
56 | |
---|
57 | moveUpPressed = false; |
---|
58 | moveDownPressed = false; |
---|
59 | moveLeftPressed = false; |
---|
60 | moveDownPressed = false; |
---|
61 | firePressed = false; |
---|
62 | fireSignal = false; |
---|
63 | timeSinceLastFire = 0.0; |
---|
64 | |
---|
65 | gravityAcceleration = 8.0; |
---|
66 | mouseFactor_ = 75.0; |
---|
67 | maxFireRate = 0.3; |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | @brief |
---|
72 | Method to create a JumpCenterpoint through XML. |
---|
73 | */ |
---|
74 | void JumpFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
75 | { |
---|
76 | SUPER(JumpFigure, XMLPort, xmlelement, mode); |
---|
77 | XMLPortParam(JumpFigure, "mouseFactor", setMouseFactor, getMouseFactor, xmlelement, mode); |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | @brief |
---|
82 | Is called each tick. |
---|
83 | Moves the bat. |
---|
84 | @param dt |
---|
85 | The time since last tick. |
---|
86 | */ |
---|
87 | void JumpFigure::tick(float dt) |
---|
88 | { |
---|
89 | SUPER(JumpFigure, tick, dt); |
---|
90 | |
---|
91 | // If the bat is controlled (but not over the network). |
---|
92 | if (this->hasLocalController()) |
---|
93 | { |
---|
94 | timeSinceLastFire += dt; |
---|
95 | |
---|
96 | /*if (this->movement_ != 0) |
---|
97 | { |
---|
98 | // The absolute value of the movement is restricted to be lesser or equal than the speed of the bat. |
---|
99 | this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_; |
---|
100 | |
---|
101 | // If moveRightLeft() is used the movement is dependento on wehther it is the right or the left bat, so, it is i.e. dependent on the orientation of the bat. |
---|
102 | if (this->bMoveLocal_) |
---|
103 | this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0)); |
---|
104 | else |
---|
105 | this->setVelocity(0, 0, this->movement_); |
---|
106 | |
---|
107 | this->movement_ = 0; |
---|
108 | this->bSteadiedPosition_ = false; |
---|
109 | } |
---|
110 | // If there is no movement but the position has not been steadied, the velocity is set to zero and the position is reaffirmed. |
---|
111 | else if (!this->bSteadiedPosition_) |
---|
112 | { |
---|
113 | // To ensure network synchronicity |
---|
114 | this->setVelocity(0, 0, 0); |
---|
115 | this->setPosition(this->getPosition()); |
---|
116 | this->bSteadiedPosition_ = true; |
---|
117 | }*/ |
---|
118 | |
---|
119 | |
---|
120 | Vector3 velocity = getVelocity(); |
---|
121 | |
---|
122 | velocity.z -= gravityAcceleration; |
---|
123 | |
---|
124 | /*if (moveLeftPressed == true) |
---|
125 | { |
---|
126 | velocity.x = -accelerationFactor; |
---|
127 | moveLeftPressed = false; |
---|
128 | } |
---|
129 | if (moveRightPressed == true) |
---|
130 | { |
---|
131 | velocity.x = accelerationFactor; |
---|
132 | moveRightPressed = false; |
---|
133 | }*/ |
---|
134 | |
---|
135 | velocity.x = -mouseFactor_*horizontalSpeed; |
---|
136 | |
---|
137 | if (moveUpPressed == true) |
---|
138 | { |
---|
139 | velocity.z = 200.0f; |
---|
140 | moveUpPressed = false; |
---|
141 | } |
---|
142 | if (moveDownPressed == true) |
---|
143 | { |
---|
144 | moveDownPressed = false; |
---|
145 | } |
---|
146 | |
---|
147 | setVelocity(velocity); |
---|
148 | |
---|
149 | if (firePressed && timeSinceLastFire >= maxFireRate) |
---|
150 | { |
---|
151 | firePressed = false; |
---|
152 | timeSinceLastFire = 0.0; |
---|
153 | fireSignal = true; |
---|
154 | //orxout() << "fired signal set" << endl; |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | Vector3 position = this->getPosition(); |
---|
159 | |
---|
160 | if (position.x < -fieldWidth_*1.1) |
---|
161 | { |
---|
162 | position.x = fieldWidth_*1.1; |
---|
163 | } |
---|
164 | else if (position.x > fieldWidth_*1.1) |
---|
165 | { |
---|
166 | position.x = -fieldWidth_*1.1; |
---|
167 | } |
---|
168 | |
---|
169 | this->setPosition(position); |
---|
170 | |
---|
171 | moveUpPressed = false; |
---|
172 | moveDownPressed = false; |
---|
173 | moveLeftPressed = false; |
---|
174 | moveDownPressed = false; |
---|
175 | firePressed = false; |
---|
176 | } |
---|
177 | |
---|
178 | void JumpFigure::JumpFromPlatform(JumpPlatform* platform) |
---|
179 | { |
---|
180 | Vector3 velocity = getVelocity(); |
---|
181 | velocity.z = 200.0f; |
---|
182 | setVelocity(velocity); |
---|
183 | } |
---|
184 | |
---|
185 | |
---|
186 | /** |
---|
187 | @brief |
---|
188 | Overloaded the function to steer the bat up and down. |
---|
189 | @param value |
---|
190 | A vector whose first component is the inverse direction in which we want to steer the bat. |
---|
191 | */ |
---|
192 | void JumpFigure::moveFrontBack(const Vector2& value) |
---|
193 | { |
---|
194 | if (value.x > 0) |
---|
195 | { |
---|
196 | //orxout() << "up pressed" << endl; |
---|
197 | moveUpPressed = true; |
---|
198 | moveDownPressed = false; |
---|
199 | } |
---|
200 | else |
---|
201 | { |
---|
202 | //orxout() << "down pressed" << endl; |
---|
203 | moveUpPressed = false; |
---|
204 | moveDownPressed = true; |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | /** |
---|
209 | @brief |
---|
210 | Overloaded the function to steer the bat up and down. |
---|
211 | @param value |
---|
212 | A vector whose first component is the direction in which we wnat to steer the bat. |
---|
213 | */ |
---|
214 | void JumpFigure::moveRightLeft(const Vector2& value) |
---|
215 | { |
---|
216 | if (value.x > 0) |
---|
217 | { |
---|
218 | //orxout() << "right pressed" << endl; |
---|
219 | moveLeftPressed = false; |
---|
220 | moveRightPressed = true; |
---|
221 | } |
---|
222 | else |
---|
223 | { |
---|
224 | //orxout() << "left pressed" << endl; |
---|
225 | moveLeftPressed = true; |
---|
226 | moveRightPressed = false; |
---|
227 | } |
---|
228 | /*this->bMoveLocal_ = true; |
---|
229 | this->movement_ = value.x;*/ |
---|
230 | } |
---|
231 | |
---|
232 | void JumpFigure::rotateYaw(const Vector2& value) |
---|
233 | { |
---|
234 | horizontalSpeed = value.x; |
---|
235 | |
---|
236 | } |
---|
237 | |
---|
238 | void JumpFigure::rotatePitch(const Vector2& value) |
---|
239 | { |
---|
240 | |
---|
241 | |
---|
242 | } |
---|
243 | |
---|
244 | void JumpFigure::rotateRoll(const Vector2& value) |
---|
245 | { |
---|
246 | |
---|
247 | |
---|
248 | } |
---|
249 | |
---|
250 | void JumpFigure::fired(unsigned int firemode) |
---|
251 | { |
---|
252 | orxout() << "fire pressed" << endl; |
---|
253 | firePressed = true; |
---|
254 | } |
---|
255 | } |
---|