[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; |
---|
| 51 | left = false; |
---|
| 52 | right = false; |
---|
| 53 | |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | void JumpShip::tick(float dt) |
---|
| 57 | { |
---|
| 58 | |
---|
| 59 | Vector3 pos = getPosition(); |
---|
| 60 | |
---|
| 61 | /* |
---|
| 62 | //Movement calculation |
---|
| 63 | lastTimeFront += dt * damping; |
---|
| 64 | lastTimeLeft += dt * damping; |
---|
| 65 | lastTime += dt; |
---|
| 66 | |
---|
| 67 | velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); |
---|
| 68 | velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); |
---|
| 69 | |
---|
| 70 | //Execute movement |
---|
| 71 | if (this->hasLocalController()) |
---|
| 72 | { |
---|
| 73 | float dist_y = velocity.y * dt; |
---|
| 74 | float dist_x = velocity.x * dt; |
---|
| 75 | if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6) |
---|
| 76 | posforeward += dist_y; |
---|
| 77 | else |
---|
| 78 | { |
---|
| 79 | velocity.y = 0; |
---|
| 80 | // restart if game ended |
---|
| 81 | if (getGame()) |
---|
| 82 | if (getGame()->bEndGame) |
---|
| 83 | { |
---|
| 84 | getGame()->start(); |
---|
| 85 | return; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | if (pos.z + dist_x > 42*2.5 || pos.z + dist_x < -42*3) |
---|
| 89 | velocity.x = 0; |
---|
| 90 | pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt; |
---|
| 91 | |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | // shoot! |
---|
| 95 | if (isFireing) |
---|
| 96 | ControllableEntity::fire(0); |
---|
| 97 | |
---|
| 98 | // Camera |
---|
| 99 | WeakPtr<Camera> camera = this->getCamera(); |
---|
| 100 | if (camera != NULL) |
---|
| 101 | { |
---|
| 102 | camera->setPosition(Vector3(-pos.z, -posforeward, 0)); |
---|
| 103 | camera->setOrientation(Vector3::UNIT_Z, Degree(90)); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 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 | |
---|
| 123 | if (left == true) |
---|
| 124 | { |
---|
| 125 | pos += Vector3(100 + pos.y, 0, 0) * dt; |
---|
| 126 | left = false; |
---|
| 127 | } |
---|
| 128 | else if (right == true) |
---|
| 129 | { |
---|
| 130 | right = false; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | setPosition(pos); |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | SUPER(JumpShip, tick, dt); |
---|
| 137 | } |
---|
| 138 | /* |
---|
| 139 | void JumpShip::updateLevel() |
---|
| 140 | { |
---|
| 141 | lastTime = 0; |
---|
| 142 | if (getGame()) |
---|
| 143 | getGame()->levelUp(); |
---|
| 144 | }*/ |
---|
| 145 | |
---|
| 146 | void JumpShip::moveFrontBack(const Vector2& value) |
---|
| 147 | { |
---|
| 148 | //lastTimeLeft = 0; |
---|
| 149 | //desiredVelocity.x = -value.x * speed; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | void JumpShip::moveRightLeft(const Vector2& value) |
---|
| 153 | { |
---|
| 154 | if (value.y < 0) |
---|
| 155 | { |
---|
| 156 | left = true; |
---|
| 157 | } |
---|
| 158 | else if (value.y > 0) |
---|
| 159 | { |
---|
| 160 | right = true; |
---|
| 161 | } |
---|
| 162 | //lastTimeFront = 0; |
---|
| 163 | //desiredVelocity.y = value.y * speed * 42; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | /* |
---|
| 167 | void JumpShip::boost(bool bBoost) |
---|
| 168 | { |
---|
| 169 | isFireing = bBoost; |
---|
| 170 | } |
---|
| 171 | inline bool JumpShip::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
| 172 | { |
---|
| 173 | // orxout() << "touch!!! " << endl; //<< otherObject << " at " << contactPoint; |
---|
| 174 | WeakPtr<JumpEnemy> enemy = orxonox_cast<JumpEnemy*>(otherObject); |
---|
| 175 | WeakPtr<Projectile> shot = orxonox_cast<Projectile*>(otherObject); |
---|
| 176 | // ensure that this gets only called once per enemy. |
---|
| 177 | if (enemy != NULL && lastEnemy != enemy) |
---|
| 178 | { |
---|
| 179 | lastEnemy = enemy; |
---|
| 180 | |
---|
| 181 | removeHealth(20); |
---|
| 182 | if (getGame()) |
---|
| 183 | { |
---|
| 184 | getGame()->multiplier = 1; |
---|
| 185 | } |
---|
| 186 | } |
---|
| 187 | // was shot, decrease multiplier |
---|
| 188 | else if (shot != NULL && lastShot != shot) |
---|
| 189 | { |
---|
| 190 | if (getGame() && orxonox_cast<JumpEnemy*>(shot->getShooter()) != NULL) |
---|
| 191 | { |
---|
| 192 | if (getGame()->multiplier > 1) |
---|
| 193 | { |
---|
| 194 | lastShot = shot; |
---|
| 195 | getGame()->multiplier -= 1; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | return false; |
---|
| 200 | // SUPER(JumpShip, collidesAgainst, otherObject, contactPoint); |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | void JumpShip::death() |
---|
| 204 | { |
---|
| 205 | getGame()->costLife(); |
---|
| 206 | SpaceShip::death(); |
---|
| 207 | } |
---|
| 208 | */ |
---|
| 209 | WeakPtr<Jump> JumpShip::getGame() |
---|
| 210 | { |
---|
| 211 | if (game == NULL) |
---|
| 212 | { |
---|
| 213 | for (ObjectList<Jump>::iterator it = ObjectList<Jump>::begin(); it != ObjectList<Jump>::end(); ++it) |
---|
| 214 | { |
---|
| 215 | game = *it; |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | return game; |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | } |
---|