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 SOBFigure.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 "SOBFigure.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/XMLPort.h" |
---|
38 | #include "graphics/Model.h" |
---|
39 | |
---|
40 | |
---|
41 | namespace orxonox |
---|
42 | { |
---|
43 | RegisterClass(SOBFigure); |
---|
44 | |
---|
45 | SOBFigure::SOBFigure(Context* context) : ControllableEntity(context) |
---|
46 | { |
---|
47 | RegisterObject(SOBFigure); |
---|
48 | |
---|
49 | // initialize variables |
---|
50 | |
---|
51 | moveUpPressed_ = false; |
---|
52 | moveDownPressed_ = false; |
---|
53 | moveLeftPressed_ = false; |
---|
54 | moveDownPressed_ = false; |
---|
55 | firePressed_ = false; |
---|
56 | timeSinceLastFire_ = 0.0; |
---|
57 | |
---|
58 | gravityAcceleration_ = 250.0;//8.0 |
---|
59 | |
---|
60 | dead_ = false; |
---|
61 | setAngularFactor(0.0); |
---|
62 | } |
---|
63 | |
---|
64 | void SOBFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
65 | { |
---|
66 | SUPER(SOBFigure, XMLPort, xmlelement, mode); |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | void SOBFigure::tick(float dt) |
---|
71 | { |
---|
72 | SUPER(SOBFigure, tick, dt); |
---|
73 | |
---|
74 | if (hasLocalController()) |
---|
75 | { |
---|
76 | timeSinceLastFire_ += dt; |
---|
77 | |
---|
78 | // Move up/down |
---|
79 | Vector3 velocity = getVelocity(); |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | // Move left/right |
---|
89 | if (dead_ == false) |
---|
90 | { |
---|
91 | |
---|
92 | if (firePressed_ && std::abs(velocity.z) < 0.1) { |
---|
93 | velocity.z = 200; |
---|
94 | } else { |
---|
95 | |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | if (moveRightPressed_) |
---|
102 | velocity.x = 75; |
---|
103 | else if (moveLeftPressed_) |
---|
104 | velocity.x = -75; |
---|
105 | else |
---|
106 | velocity.x = 0; |
---|
107 | } |
---|
108 | else |
---|
109 | { |
---|
110 | velocity.x = 0.0; |
---|
111 | } |
---|
112 | velocity.z -= gravityAcceleration_*dt; |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | setVelocity(velocity); |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | } |
---|
121 | |
---|
122 | // Move through the left and right screen boundaries |
---|
123 | |
---|
124 | //setPosition(position); |
---|
125 | |
---|
126 | // Reset key variables |
---|
127 | moveUpPressed_ = false; |
---|
128 | moveDownPressed_ = false; |
---|
129 | moveLeftPressed_ = false; |
---|
130 | moveRightPressed_ = false; |
---|
131 | moveDownPressed_ = false; |
---|
132 | firePressed_ = false; |
---|
133 | |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | /* void SOBFigure::CollisionWithEnemy(SOBEnemy* enemy) |
---|
141 | { |
---|
142 | if (rocketActive_ == nullptr && propellerActive_ == nullptr && shieldActive_ == nullptr) |
---|
143 | { |
---|
144 | dead_ = true; |
---|
145 | } |
---|
146 | }*/ |
---|
147 | |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | void SOBFigure::moveFrontBack(const Vector2& value) |
---|
154 | { |
---|
155 | if (value.x > 0) |
---|
156 | { |
---|
157 | moveUpPressed_ = true; |
---|
158 | moveDownPressed_ = false; |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | moveUpPressed_ = false; |
---|
163 | moveDownPressed_ = true; |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | void SOBFigure::moveRightLeft(const Vector2& value) |
---|
168 | { |
---|
169 | if (value.x > 0) |
---|
170 | { |
---|
171 | moveLeftPressed_ = false; |
---|
172 | moveRightPressed_ = true; |
---|
173 | } |
---|
174 | else |
---|
175 | { |
---|
176 | moveLeftPressed_ = true; |
---|
177 | moveRightPressed_ = false; |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | void SOBFigure::boost(bool boost) |
---|
186 | { |
---|
187 | firePressed_ = true; |
---|
188 | } |
---|
189 | } |
---|