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