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