[10117] | 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 | |
---|
[10166] | 44 | speed = 830; |
---|
[10117] | 45 | isFireing = false; |
---|
| 46 | damping = 10; |
---|
[10118] | 47 | |
---|
[10124] | 48 | // not sure if has to be zero? |
---|
[10118] | 49 | lastTimeFront = 0; |
---|
| 50 | lastTimeLeft = 0; |
---|
| 51 | lastTime = 0; |
---|
[10117] | 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; |
---|
[10166] | 70 | //float dist_x = velocity.x * dt; |
---|
[10117] | 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 |
---|
[10166] | 77 | /* |
---|
[10117] | 78 | if (getGame()) |
---|
| 79 | if (getGame()->bEndGame) |
---|
| 80 | { |
---|
| 81 | getGame()->start(); |
---|
| 82 | return; |
---|
[10152] | 83 | }*/ |
---|
[10117] | 84 | } |
---|
[10166] | 85 | |
---|
[10117] | 86 | pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | // Camera |
---|
| 91 | WeakPtr<Camera> camera = this->getCamera(); |
---|
| 92 | if (camera != NULL) |
---|
| 93 | { |
---|
[10135] | 94 | // camera->setPosition(Vector3(-pos.z, -posforeward, 0)); |
---|
[10127] | 95 | camera->setOrientation(Vector3::UNIT_Z, Degree(0)); |
---|
[10117] | 96 | } |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | // bring back on track! |
---|
| 101 | if(pos.y != 0) |
---|
[10128] | 102 | { |
---|
| 103 | pos.y = 0; |
---|
| 104 | } |
---|
[10117] | 105 | |
---|
| 106 | setPosition(pos); |
---|
| 107 | setOrientation(Vector3::UNIT_Y, Degree(270)); |
---|
[10124] | 108 | |
---|
[10117] | 109 | // Level up! |
---|
| 110 | if (pos.x > 42000) |
---|
| 111 | { |
---|
| 112 | updateLevel(); |
---|
| 113 | setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0) |
---|
| 114 | } |
---|
[10124] | 115 | |
---|
[10117] | 116 | SUPER(DodgeRaceShip, tick, dt); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | void DodgeRaceShip::updateLevel() |
---|
| 120 | { |
---|
| 121 | lastTime = 0; |
---|
| 122 | if (getGame()) |
---|
| 123 | getGame()->levelUp(); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | void DodgeRaceShip::moveFrontBack(const Vector2& value) |
---|
| 127 | { |
---|
[10127] | 128 | //lastTimeFront = 0; |
---|
| 129 | //desiredVelocity.y = value.y * speed * 42; |
---|
| 130 | |
---|
[10117] | 131 | } |
---|
| 132 | |
---|
| 133 | void DodgeRaceShip::moveRightLeft(const Vector2& value) |
---|
| 134 | { |
---|
[10127] | 135 | lastTimeLeft = 0; |
---|
[10128] | 136 | desiredVelocity.x = value.x * speed; |
---|
[10117] | 137 | } |
---|
| 138 | void DodgeRaceShip::boost(bool bBoost) |
---|
| 139 | { |
---|
[10166] | 140 | //getGame()->bEndGame = bBoost; |
---|
[10117] | 141 | } |
---|
[10128] | 142 | |
---|
[10118] | 143 | inline bool DodgeRaceShip::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
[10117] | 144 | { |
---|
| 145 | |
---|
[10154] | 146 | removeHealth(100); |
---|
[10135] | 147 | this->death(); |
---|
[10117] | 148 | return false; |
---|
[10118] | 149 | } |
---|
[10128] | 150 | |
---|
[10117] | 151 | WeakPtr<DodgeRace> DodgeRaceShip::getGame() |
---|
| 152 | { |
---|
| 153 | if (game == NULL) |
---|
| 154 | { |
---|
| 155 | for (ObjectList<DodgeRace>::iterator it = ObjectList<DodgeRace>::begin(); it != ObjectList<DodgeRace>::end(); ++it) |
---|
[10118] | 156 | { |
---|
| 157 | game = *it; |
---|
| 158 | } |
---|
[10117] | 159 | } |
---|
| 160 | return game; |
---|
| 161 | } |
---|
[10124] | 162 | |
---|
[10117] | 163 | void DodgeRaceShip::death() |
---|
| 164 | { |
---|
| 165 | getGame()->costLife(); |
---|
| 166 | SpaceShip::death(); |
---|
[10124] | 167 | } |
---|
[10117] | 168 | } |
---|