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 Asteroids2DShip.cc |
---|
31 | @brief Implementation of the Asteroids2DShip class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "Asteroids2DShip.h" |
---|
35 | #include "core/CoreIncludes.h" |
---|
36 | |
---|
37 | namespace orxonox |
---|
38 | { |
---|
39 | RegisterClass(Asteroids2DShip); |
---|
40 | |
---|
41 | Asteroids2DShip::Asteroids2DShip(Context* context) : SpaceShip(context) |
---|
42 | { |
---|
43 | RegisterObject(Asteroids2DShip); |
---|
44 | |
---|
45 | speed = 830; |
---|
46 | isFireing = false; |
---|
47 | damping = 10; |
---|
48 | |
---|
49 | // not sure if has to be zero? |
---|
50 | lastTimeFront = 0; |
---|
51 | lastTimeLeft = 0; |
---|
52 | lastTime = 0; |
---|
53 | } |
---|
54 | |
---|
55 | void Asteroids2DShip::tick(float dt) |
---|
56 | { |
---|
57 | Vector3 pos = getPosition(); |
---|
58 | |
---|
59 | //Movement calculation |
---|
60 | lastTimeFront += dt * damping; |
---|
61 | lastTimeLeft += dt * damping; |
---|
62 | lastTime += dt; |
---|
63 | |
---|
64 | velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); |
---|
65 | velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); |
---|
66 | |
---|
67 | //Execute movement |
---|
68 | if (this->hasLocalController()) |
---|
69 | { |
---|
70 | float dist_y = velocity.y * dt; |
---|
71 | //float dist_x = velocity.x * dt; |
---|
72 | if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6) |
---|
73 | posforeward += dist_y; |
---|
74 | else |
---|
75 | { |
---|
76 | velocity.y = 0; |
---|
77 | // restart if game ended |
---|
78 | /* |
---|
79 | if (getGame()) |
---|
80 | if (getGame()->bEndGame) |
---|
81 | { |
---|
82 | getGame()->start(); |
---|
83 | return; |
---|
84 | }*/ |
---|
85 | } |
---|
86 | |
---|
87 | pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt; |
---|
88 | } |
---|
89 | |
---|
90 | // bring back on track! |
---|
91 | if(pos.y != 0) |
---|
92 | { |
---|
93 | pos.y = 0; |
---|
94 | } |
---|
95 | |
---|
96 | setPosition(pos); |
---|
97 | setOrientation(Vector3::UNIT_Y, Degree(270)); |
---|
98 | |
---|
99 | SUPER(Asteroids2DShip, tick, dt); |
---|
100 | } |
---|
101 | |
---|
102 | void Asteroids2DShip::moveFrontBack(const Vector2& value) |
---|
103 | { |
---|
104 | //lastTimeFront = 0; |
---|
105 | //desiredVelocity.y = value.y * speed * 42; |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | void Asteroids2DShip::moveRightLeft(const Vector2& value) |
---|
110 | { |
---|
111 | lastTimeLeft = 0; |
---|
112 | desiredVelocity.x = value.x * speed; |
---|
113 | } |
---|
114 | void Asteroids2DShip::boost(bool bBoost) |
---|
115 | { |
---|
116 | //getGame()->bEndGame = bBoost; |
---|
117 | } |
---|
118 | |
---|
119 | inline bool Asteroids2DShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) |
---|
120 | { |
---|
121 | |
---|
122 | removeHealth(100); |
---|
123 | this->death(); |
---|
124 | return false; |
---|
125 | } |
---|
126 | |
---|
127 | Asteroids2D* Asteroids2DShip::getGame() |
---|
128 | { |
---|
129 | if (game == nullptr) |
---|
130 | { |
---|
131 | for (Asteroids2D* race : ObjectList<Asteroids2D>()) |
---|
132 | { |
---|
133 | game = race; |
---|
134 | } |
---|
135 | } |
---|
136 | return game; |
---|
137 | } |
---|
138 | |
---|
139 | void Asteroids2DShip::death() |
---|
140 | { |
---|
141 | //getGame()->costLife(); |
---|
142 | SpaceShip::death(); |
---|
143 | } |
---|
144 | } |
---|