[9725] | 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 InvaderShip.cc |
---|
| 31 | @brief Implementation of the InvaderShip class. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "InvaderShip.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/XMLPort.h" |
---|
[9829] | 38 | #include "Invader.h" |
---|
[9725] | 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
| 42 | RegisterClass(InvaderShip); |
---|
| 43 | |
---|
| 44 | InvaderShip::InvaderShip(Context* context) : SpaceShip(context) |
---|
| 45 | { |
---|
| 46 | RegisterObject(InvaderShip); |
---|
| 47 | |
---|
| 48 | speed = 500; |
---|
[9744] | 49 | isFireing = false; |
---|
[9725] | 50 | damping = 10; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | void InvaderShip::tick(float dt) |
---|
| 54 | { |
---|
[9793] | 55 | Vector3 pos = getPosition(); |
---|
[9744] | 56 | |
---|
[9793] | 57 | //Movement calculation |
---|
[9725] | 58 | lastTimeFront += dt * damping; |
---|
| 59 | lastTimeLeft += dt * damping; |
---|
[9793] | 60 | lastTime += dt; |
---|
| 61 | |
---|
[9725] | 62 | velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); |
---|
| 63 | velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); |
---|
| 64 | |
---|
[9793] | 65 | //Execute movement |
---|
| 66 | if (this->hasLocalController()) |
---|
| 67 | { |
---|
| 68 | float dist_y = velocity.y * dt; |
---|
[9828] | 69 | float dist_x = velocity.x * dt; |
---|
[9793] | 70 | if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6) |
---|
| 71 | posforeward += dist_y; |
---|
| 72 | else |
---|
[9884] | 73 | { |
---|
[9793] | 74 | velocity.y = 0; |
---|
[9884] | 75 | // restart if game ended |
---|
| 76 | if (getGame()) |
---|
| 77 | if (getGame()->bEndGame) |
---|
| 78 | { |
---|
| 79 | getGame()->start(); |
---|
| 80 | return; |
---|
| 81 | } |
---|
| 82 | } |
---|
[9828] | 83 | if (pos.z + dist_x > 42*2.5 || pos.z + dist_x < -42*3) |
---|
| 84 | velocity.x = 0; |
---|
[9793] | 85 | pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt; |
---|
| 86 | } |
---|
| 87 | |
---|
[9868] | 88 | // shoot! |
---|
[9725] | 89 | if (isFireing) |
---|
| 90 | ControllableEntity::fire(0); |
---|
| 91 | |
---|
[9793] | 92 | // Camera |
---|
[10624] | 93 | Camera* camera = this->getCamera(); |
---|
[9793] | 94 | if (camera != NULL) |
---|
[9777] | 95 | { |
---|
[9793] | 96 | camera->setPosition(Vector3(-pos.z, -posforeward, 0)); |
---|
| 97 | camera->setOrientation(Vector3::UNIT_Z, Degree(90)); |
---|
[9777] | 98 | } |
---|
[9744] | 99 | |
---|
[9793] | 100 | |
---|
| 101 | |
---|
| 102 | // bring back on track! |
---|
| 103 | if(pos.y != 0) |
---|
| 104 | pos.y = 0; |
---|
[9777] | 105 | |
---|
[9793] | 106 | setPosition(pos); |
---|
| 107 | setOrientation(Vector3::UNIT_Y, Degree(270)); |
---|
[9744] | 108 | |
---|
[9793] | 109 | // Level up! |
---|
[9828] | 110 | if (pos.x > 42000) |
---|
[9793] | 111 | { |
---|
| 112 | updateLevel(); |
---|
[9828] | 113 | setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0) |
---|
[9793] | 114 | } |
---|
[9744] | 115 | |
---|
[9725] | 116 | SUPER(InvaderShip, tick, dt); |
---|
| 117 | } |
---|
| 118 | |
---|
[9793] | 119 | void InvaderShip::updateLevel() |
---|
| 120 | { |
---|
| 121 | lastTime = 0; |
---|
[9829] | 122 | if (getGame()) |
---|
| 123 | getGame()->levelUp(); |
---|
[9793] | 124 | } |
---|
[9777] | 125 | |
---|
[9725] | 126 | void InvaderShip::moveFrontBack(const Vector2& value) |
---|
| 127 | { |
---|
[9793] | 128 | lastTimeLeft = 0; |
---|
| 129 | desiredVelocity.x = -value.x * speed; |
---|
[9725] | 130 | } |
---|
| 131 | |
---|
| 132 | void InvaderShip::moveRightLeft(const Vector2& value) |
---|
| 133 | { |
---|
[9793] | 134 | lastTimeFront = 0; |
---|
| 135 | desiredVelocity.y = value.y * speed * 42; |
---|
[9725] | 136 | } |
---|
| 137 | void InvaderShip::boost(bool bBoost) |
---|
| 138 | { |
---|
| 139 | isFireing = bBoost; |
---|
| 140 | } |
---|
[9828] | 141 | inline bool InvaderShip::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
| 142 | { |
---|
| 143 | // orxout() << "touch!!! " << endl; //<< otherObject << " at " << contactPoint; |
---|
[10624] | 144 | InvaderEnemy* enemy = orxonox_cast<InvaderEnemy*>(otherObject); |
---|
| 145 | Projectile* shot = orxonox_cast<Projectile*>(otherObject); |
---|
[9868] | 146 | // ensure that this gets only called once per enemy. |
---|
[9828] | 147 | if (enemy != NULL && lastEnemy != enemy) |
---|
| 148 | { |
---|
| 149 | lastEnemy = enemy; |
---|
[9868] | 150 | |
---|
[9828] | 151 | removeHealth(20); |
---|
[9868] | 152 | if (getGame()) |
---|
[9828] | 153 | { |
---|
[9874] | 154 | getGame()->multiplier = 1; |
---|
[9828] | 155 | } |
---|
| 156 | } |
---|
[9874] | 157 | // was shot, decrease multiplier |
---|
| 158 | else if (shot != NULL && lastShot != shot) |
---|
| 159 | { |
---|
| 160 | if (getGame() && orxonox_cast<InvaderEnemy*>(shot->getShooter()) != NULL) |
---|
| 161 | { |
---|
| 162 | if (getGame()->multiplier > 1) |
---|
| 163 | { |
---|
| 164 | lastShot = shot; |
---|
| 165 | getGame()->multiplier -= 1; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | } |
---|
[9828] | 169 | return false; |
---|
| 170 | // SUPER(InvaderShip, collidesAgainst, otherObject, contactPoint); |
---|
| 171 | } |
---|
[9829] | 172 | |
---|
[10624] | 173 | Invader* InvaderShip::getGame() |
---|
[9829] | 174 | { |
---|
| 175 | if (game == NULL) |
---|
| 176 | { |
---|
| 177 | for (ObjectList<Invader>::iterator it = ObjectList<Invader>::begin(); it != ObjectList<Invader>::end(); ++it) |
---|
| 178 | game = *it; |
---|
| 179 | } |
---|
| 180 | return game; |
---|
| 181 | } |
---|
[9874] | 182 | |
---|
| 183 | void InvaderShip::death() |
---|
| 184 | { |
---|
| 185 | getGame()->costLife(); |
---|
| 186 | SpaceShip::death(); |
---|
| 187 | } |
---|
[9725] | 188 | } |
---|