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