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 | * Florian Zinggeler |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file DodgeRaceShip.cc |
---|
31 | @brief Implementation of the DodgeRaceShip class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "DodgeRaceShip.h" |
---|
35 | |
---|
36 | namespace orxonox |
---|
37 | { |
---|
38 | RegisterClass(DodgeRaceShip); |
---|
39 | |
---|
40 | DodgeRaceShip::DodgeRaceShip(Context* context) : SpaceShip(context) |
---|
41 | { |
---|
42 | RegisterObject(DodgeRaceShip); |
---|
43 | |
---|
44 | speed = 800; |
---|
45 | isFireing = false; |
---|
46 | damping = 10; |
---|
47 | |
---|
48 | // not sure if has to be zero? |
---|
49 | lastTimeFront = 0; |
---|
50 | lastTimeLeft = 0; |
---|
51 | lastTime = 0; |
---|
52 | } |
---|
53 | |
---|
54 | void DodgeRaceShip::tick(float dt) |
---|
55 | { |
---|
56 | Vector3 pos = getPosition(); |
---|
57 | |
---|
58 | //Movement calculation |
---|
59 | lastTimeFront += dt * damping; |
---|
60 | lastTimeLeft += dt * damping; |
---|
61 | lastTime += dt; |
---|
62 | |
---|
63 | velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); |
---|
64 | velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); |
---|
65 | |
---|
66 | //Execute movement |
---|
67 | if (this->hasLocalController()) |
---|
68 | { |
---|
69 | float dist_y = velocity.y * dt; |
---|
70 | float dist_x = velocity.x * dt; |
---|
71 | if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6) |
---|
72 | posforeward += dist_y; |
---|
73 | else |
---|
74 | { |
---|
75 | velocity.y = 0; |
---|
76 | // restart if game ended |
---|
77 | /* |
---|
78 | if (getGame()) |
---|
79 | if (getGame()->bEndGame) |
---|
80 | { |
---|
81 | getGame()->start(); |
---|
82 | return; |
---|
83 | }*/ |
---|
84 | } |
---|
85 | /* |
---|
86 | if (pos.z + dist_x > 42*2.5 || pos.z + dist_x < -42*3) |
---|
87 | { |
---|
88 | velocity.x = 0; |
---|
89 | } |
---|
90 | */ |
---|
91 | pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt; |
---|
92 | } |
---|
93 | |
---|
94 | // shoot! |
---|
95 | if (isFireing) |
---|
96 | { |
---|
97 | //pos += Vector3(900, 0, 0) * dt; |
---|
98 | //ControllableEntity::fire(0); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | // Camera |
---|
103 | WeakPtr<Camera> camera = this->getCamera(); |
---|
104 | if (camera != NULL) |
---|
105 | { |
---|
106 | // camera->setPosition(Vector3(-pos.z, -posforeward, 0)); |
---|
107 | camera->setOrientation(Vector3::UNIT_Z, Degree(0)); |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | // bring back on track! |
---|
113 | if(pos.y != 0) |
---|
114 | { |
---|
115 | pos.y = 0; |
---|
116 | } |
---|
117 | |
---|
118 | setPosition(pos); |
---|
119 | setOrientation(Vector3::UNIT_Y, Degree(270)); |
---|
120 | |
---|
121 | // Level up! |
---|
122 | if (pos.x > 42000) |
---|
123 | { |
---|
124 | updateLevel(); |
---|
125 | setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0) |
---|
126 | } |
---|
127 | |
---|
128 | SUPER(DodgeRaceShip, tick, dt); |
---|
129 | } |
---|
130 | |
---|
131 | void DodgeRaceShip::updateLevel() |
---|
132 | { |
---|
133 | lastTime = 0; |
---|
134 | if (getGame()) |
---|
135 | getGame()->levelUp(); |
---|
136 | } |
---|
137 | |
---|
138 | void DodgeRaceShip::moveFrontBack(const Vector2& value) |
---|
139 | { |
---|
140 | //lastTimeFront = 0; |
---|
141 | //desiredVelocity.y = value.y * speed * 42; |
---|
142 | |
---|
143 | } |
---|
144 | |
---|
145 | void DodgeRaceShip::moveRightLeft(const Vector2& value) |
---|
146 | { |
---|
147 | lastTimeLeft = 0; |
---|
148 | desiredVelocity.x = value.x * speed; |
---|
149 | } |
---|
150 | void DodgeRaceShip::boost(bool bBoost) |
---|
151 | { |
---|
152 | //isFireing = bBoost; |
---|
153 | } |
---|
154 | |
---|
155 | inline bool DodgeRaceShip::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
156 | { |
---|
157 | /* |
---|
158 | if (otherObject != NULL && lastEntity != otherObject) |
---|
159 | { |
---|
160 | lastEntity = otherObject; |
---|
161 | removeHealth(20); |
---|
162 | } |
---|
163 | */ |
---|
164 | |
---|
165 | removeHealth(100); |
---|
166 | this->death(); |
---|
167 | return false; |
---|
168 | } |
---|
169 | |
---|
170 | WeakPtr<DodgeRace> DodgeRaceShip::getGame() |
---|
171 | { |
---|
172 | if (game == NULL) |
---|
173 | { |
---|
174 | for (ObjectList<DodgeRace>::iterator it = ObjectList<DodgeRace>::begin(); it != ObjectList<DodgeRace>::end(); ++it) |
---|
175 | { |
---|
176 | game = *it; |
---|
177 | } |
---|
178 | } |
---|
179 | return game; |
---|
180 | } |
---|
181 | |
---|
182 | void DodgeRaceShip::death() |
---|
183 | { |
---|
184 | getGame()->costLife(); |
---|
185 | SpaceShip::death(); |
---|
186 | } |
---|
187 | } |
---|