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_ = 8.0; |
---|
59 | |
---|
60 | dead_ = false; |
---|
61 | } |
---|
62 | |
---|
63 | void SOBFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
64 | { |
---|
65 | SUPER(SOBFigure, XMLPort, xmlelement, mode); |
---|
66 | |
---|
67 | } |
---|
68 | |
---|
69 | void SOBFigure::tick(float dt) |
---|
70 | { |
---|
71 | SUPER(SOBFigure, tick, dt); |
---|
72 | |
---|
73 | if (hasLocalController()) |
---|
74 | { |
---|
75 | timeSinceLastFire_ += dt; |
---|
76 | |
---|
77 | // Move up/down |
---|
78 | Vector3 velocity = getVelocity(); |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | velocity.z -= gravityAcceleration_; |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | // Move left/right |
---|
88 | if (dead_ == false) |
---|
89 | { |
---|
90 | if (moveRightPressed_) |
---|
91 | velocity.x = 75; |
---|
92 | else if (moveLeftPressed_) |
---|
93 | velocity.x = 75; |
---|
94 | else |
---|
95 | velocity.x = 0; |
---|
96 | } |
---|
97 | else |
---|
98 | { |
---|
99 | velocity.x = 0.0; |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | setVelocity(velocity); |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | } |
---|
109 | |
---|
110 | // Move through the left and right screen boundaries |
---|
111 | |
---|
112 | //setPosition(position); |
---|
113 | |
---|
114 | // Reset key variables |
---|
115 | moveUpPressed_ = false; |
---|
116 | moveDownPressed_ = false; |
---|
117 | moveLeftPressed_ = false; |
---|
118 | moveDownPressed_ = false; |
---|
119 | |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | /* void SOBFigure::CollisionWithEnemy(SOBEnemy* enemy) |
---|
127 | { |
---|
128 | if (rocketActive_ == nullptr && propellerActive_ == nullptr && shieldActive_ == nullptr) |
---|
129 | { |
---|
130 | dead_ = true; |
---|
131 | } |
---|
132 | }*/ |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | void SOBFigure::moveFrontBack(const Vector2& value) |
---|
140 | { |
---|
141 | if (value.x > 0) |
---|
142 | { |
---|
143 | moveUpPressed_ = true; |
---|
144 | moveDownPressed_ = false; |
---|
145 | } |
---|
146 | else |
---|
147 | { |
---|
148 | moveUpPressed_ = false; |
---|
149 | moveDownPressed_ = true; |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | void SOBFigure::moveRightLeft(const Vector2& value) |
---|
154 | { |
---|
155 | if (value.x > 0) |
---|
156 | { |
---|
157 | moveLeftPressed_ = false; |
---|
158 | moveRightPressed_ = true; |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | moveLeftPressed_ = true; |
---|
163 | moveRightPressed_ = false; |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | |
---|
171 | void SOBFigure::fired(unsigned int firemode) |
---|
172 | { |
---|
173 | firePressed_ = true; |
---|
174 | } |
---|
175 | } |
---|