[10005] | 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 JumpShip.cc |
---|
| 31 | @brief Implementation of the JumpShip class. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "JumpShip.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/XMLPort.h" |
---|
| 38 | #include "Jump.h" |
---|
| 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
| 42 | RegisterClass(JumpShip); |
---|
| 43 | |
---|
| 44 | JumpShip::JumpShip(Context* context) : SpaceShip(context) |
---|
| 45 | { |
---|
| 46 | RegisterObject(JumpShip); |
---|
| 47 | |
---|
| 48 | //speed = 500; |
---|
| 49 | //isFireing = false; |
---|
| 50 | //damping = 10; |
---|
[10017] | 51 | leftPressed = false; |
---|
| 52 | rightPressed = false; |
---|
| 53 | upPressed = false; |
---|
| 54 | downPressed = false; |
---|
[10005] | 55 | |
---|
[10017] | 56 | yScreenPosition = 0; |
---|
| 57 | yVelocity = 0; |
---|
[10005] | 58 | } |
---|
| 59 | |
---|
| 60 | void JumpShip::tick(float dt) |
---|
| 61 | { |
---|
[10017] | 62 | Vector3 movement(0,0,0); |
---|
| 63 | Vector3 shipPosition = getPosition(); |
---|
[10005] | 64 | |
---|
| 65 | /* |
---|
| 66 | //Movement calculation |
---|
| 67 | lastTimeFront += dt * damping; |
---|
| 68 | lastTimeLeft += dt * damping; |
---|
| 69 | lastTime += dt; |
---|
| 70 | |
---|
| 71 | velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); |
---|
| 72 | velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); |
---|
| 73 | |
---|
| 74 | //Execute movement |
---|
| 75 | if (this->hasLocalController()) |
---|
| 76 | { |
---|
| 77 | float dist_y = velocity.y * dt; |
---|
| 78 | float dist_x = velocity.x * dt; |
---|
| 79 | if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6) |
---|
| 80 | posforeward += dist_y; |
---|
| 81 | else |
---|
| 82 | { |
---|
| 83 | velocity.y = 0; |
---|
| 84 | // restart if game ended |
---|
| 85 | if (getGame()) |
---|
| 86 | if (getGame()->bEndGame) |
---|
| 87 | { |
---|
| 88 | getGame()->start(); |
---|
| 89 | return; |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | if (pos.z + dist_x > 42*2.5 || pos.z + dist_x < -42*3) |
---|
| 93 | velocity.x = 0; |
---|
| 94 | pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt; |
---|
| 95 | |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | // shoot! |
---|
| 99 | if (isFireing) |
---|
| 100 | ControllableEntity::fire(0); |
---|
[10017] | 101 | */ |
---|
[10005] | 102 | // Camera |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
[10017] | 106 | |
---|
| 107 | /* |
---|
[10005] | 108 | // bring back on track! |
---|
| 109 | if(pos.y != 0) |
---|
| 110 | pos.y = 0; |
---|
| 111 | |
---|
| 112 | setPosition(pos); |
---|
| 113 | setOrientation(Vector3::UNIT_Y, Degree(270)); |
---|
| 114 | |
---|
| 115 | // Level up! |
---|
| 116 | if (pos.x > 42000) |
---|
| 117 | { |
---|
| 118 | updateLevel(); |
---|
| 119 | setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0) |
---|
| 120 | } |
---|
| 121 | */ |
---|
| 122 | |
---|
[10017] | 123 | // Berechne Bewegung anhand der Eingabe |
---|
| 124 | if (leftPressed == true) |
---|
[10005] | 125 | { |
---|
[10017] | 126 | movement -= Vector3(xVelocity, 0, 0); |
---|
| 127 | leftPressed = false; |
---|
[10005] | 128 | } |
---|
[10017] | 129 | else if (rightPressed == true) |
---|
[10005] | 130 | { |
---|
[10017] | 131 | movement += Vector3(xVelocity, 0, 0); |
---|
| 132 | rightPressed = false; |
---|
[10005] | 133 | } |
---|
| 134 | |
---|
[10017] | 135 | if (upPressed == true) |
---|
| 136 | { |
---|
| 137 | //movement += Vector3(0, xVelocity, 0); |
---|
| 138 | yVelocity = ySpeedAfterJump; |
---|
| 139 | upPressed = false; |
---|
| 140 | } |
---|
| 141 | else if (downPressed == true) |
---|
| 142 | { |
---|
[10022] | 143 | platform = new JumpPlatform(getContext()); |
---|
| 144 | platform->setPosition(Vector3(0, 0, 0)); |
---|
| 145 | platform->setVelocity(Vector3(0, 0, 0)); |
---|
| 146 | platform->setScale(100); |
---|
| 147 | |
---|
[10017] | 148 | movement -= Vector3(0, 0, 0); |
---|
| 149 | downPressed = false; |
---|
| 150 | } |
---|
[10005] | 151 | |
---|
[10017] | 152 | movement += Vector3(0, yVelocity, 0); |
---|
| 153 | yVelocity -= yAcceleration; |
---|
[10005] | 154 | |
---|
[10017] | 155 | // Skalierung der Bewegung je nach vergangener Zeit |
---|
| 156 | movement *= dt; |
---|
| 157 | |
---|
| 158 | // Verschiebe das Schiff um den berechneten Vektor movement und verhindere Verlassen des Bildschrims |
---|
| 159 | shipPosition.x = clamp(shipPosition.x + movement.x, -xBoundary, xBoundary); |
---|
| 160 | shipPosition.y += movement.y; |
---|
| 161 | |
---|
| 162 | setPosition(shipPosition); |
---|
| 163 | |
---|
| 164 | // Bildschirmposition kann nur nach oben verschoben werden |
---|
| 165 | if (shipPosition.y > yScreenPosition) |
---|
| 166 | { |
---|
| 167 | yScreenPosition = shipPosition.y; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | // Kameraposition nachfuehren |
---|
| 171 | if (camera == NULL) |
---|
| 172 | { |
---|
| 173 | camera = getCamera(); |
---|
| 174 | } |
---|
| 175 | if (camera != NULL) |
---|
| 176 | { |
---|
| 177 | |
---|
| 178 | camera->setPosition(Vector3(-shipPosition.x, yScreenPosition-shipPosition.y, 100)); |
---|
| 179 | //camera->setOrientation(Vector3::UNIT_Z, Degree(180)); |
---|
| 180 | } |
---|
| 181 | |
---|
[10005] | 182 | SUPER(JumpShip, tick, dt); |
---|
| 183 | } |
---|
| 184 | /* |
---|
| 185 | void JumpShip::updateLevel() |
---|
| 186 | { |
---|
| 187 | lastTime = 0; |
---|
| 188 | if (getGame()) |
---|
| 189 | getGame()->levelUp(); |
---|
| 190 | }*/ |
---|
| 191 | |
---|
| 192 | void JumpShip::moveFrontBack(const Vector2& value) |
---|
| 193 | { |
---|
[10017] | 194 | if (value.y < 0) |
---|
| 195 | { |
---|
| 196 | downPressed = true; |
---|
| 197 | } |
---|
| 198 | else if (value.y > 0) |
---|
| 199 | { |
---|
| 200 | upPressed = true; |
---|
| 201 | } |
---|
[10005] | 202 | //lastTimeLeft = 0; |
---|
| 203 | //desiredVelocity.x = -value.x * speed; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | void JumpShip::moveRightLeft(const Vector2& value) |
---|
| 207 | { |
---|
[10017] | 208 | if (value.x < 0) |
---|
[10005] | 209 | { |
---|
[10017] | 210 | leftPressed = true; |
---|
[10005] | 211 | } |
---|
[10017] | 212 | else if (value.x > 0) |
---|
[10005] | 213 | { |
---|
[10017] | 214 | rightPressed = true; |
---|
[10005] | 215 | } |
---|
| 216 | //lastTimeFront = 0; |
---|
| 217 | //desiredVelocity.y = value.y * speed * 42; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | /* |
---|
| 221 | void JumpShip::boost(bool bBoost) |
---|
| 222 | { |
---|
| 223 | isFireing = bBoost; |
---|
| 224 | } |
---|
| 225 | inline bool JumpShip::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
| 226 | { |
---|
| 227 | // orxout() << "touch!!! " << endl; //<< otherObject << " at " << contactPoint; |
---|
| 228 | WeakPtr<JumpEnemy> enemy = orxonox_cast<JumpEnemy*>(otherObject); |
---|
| 229 | WeakPtr<Projectile> shot = orxonox_cast<Projectile*>(otherObject); |
---|
| 230 | // ensure that this gets only called once per enemy. |
---|
| 231 | if (enemy != NULL && lastEnemy != enemy) |
---|
| 232 | { |
---|
| 233 | lastEnemy = enemy; |
---|
| 234 | |
---|
| 235 | removeHealth(20); |
---|
| 236 | if (getGame()) |
---|
| 237 | { |
---|
| 238 | getGame()->multiplier = 1; |
---|
| 239 | } |
---|
| 240 | } |
---|
| 241 | // was shot, decrease multiplier |
---|
| 242 | else if (shot != NULL && lastShot != shot) |
---|
| 243 | { |
---|
| 244 | if (getGame() && orxonox_cast<JumpEnemy*>(shot->getShooter()) != NULL) |
---|
| 245 | { |
---|
| 246 | if (getGame()->multiplier > 1) |
---|
| 247 | { |
---|
| 248 | lastShot = shot; |
---|
| 249 | getGame()->multiplier -= 1; |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | } |
---|
| 253 | return false; |
---|
| 254 | // SUPER(JumpShip, collidesAgainst, otherObject, contactPoint); |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | void JumpShip::death() |
---|
| 258 | { |
---|
| 259 | getGame()->costLife(); |
---|
| 260 | SpaceShip::death(); |
---|
| 261 | } |
---|
| 262 | */ |
---|
| 263 | WeakPtr<Jump> JumpShip::getGame() |
---|
| 264 | { |
---|
| 265 | if (game == NULL) |
---|
| 266 | { |
---|
| 267 | for (ObjectList<Jump>::iterator it = ObjectList<Jump>::begin(); it != ObjectList<Jump>::end(); ++it) |
---|
| 268 | { |
---|
| 269 | game = *it; |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | return game; |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | } |
---|