[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 | /** |
---|
| 45 | @brief |
---|
| 46 | Constructor. Registers and initializes the object. |
---|
| 47 | */ |
---|
| 48 | InvaderShip::InvaderShip(Context* context) : SpaceShip(context) |
---|
| 49 | { |
---|
| 50 | RegisterObject(InvaderShip); |
---|
| 51 | |
---|
| 52 | speed = 500; |
---|
[9744] | 53 | isFireing = false; |
---|
[9725] | 54 | damping = 10; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | void InvaderShip::tick(float dt) |
---|
| 58 | { |
---|
[9793] | 59 | Vector3 pos = getPosition(); |
---|
[9744] | 60 | |
---|
[9793] | 61 | //Movement calculation |
---|
[9725] | 62 | lastTimeFront += dt * damping; |
---|
| 63 | lastTimeLeft += dt * damping; |
---|
[9793] | 64 | lastTime += dt; |
---|
| 65 | |
---|
[9725] | 66 | velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); |
---|
| 67 | velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); |
---|
| 68 | |
---|
[9793] | 69 | //Execute movement |
---|
| 70 | if (this->hasLocalController()) |
---|
| 71 | { |
---|
| 72 | float dist_y = velocity.y * dt; |
---|
[9828] | 73 | float dist_x = velocity.x * dt; |
---|
[9793] | 74 | if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6) |
---|
| 75 | posforeward += dist_y; |
---|
| 76 | else |
---|
| 77 | velocity.y = 0; |
---|
[9828] | 78 | if (pos.z + dist_x > 42*2.5 || pos.z + dist_x < -42*3) |
---|
| 79 | velocity.x = 0; |
---|
[9793] | 80 | // this->setVelocity(Vector3(1000 + velocity.y, 0, velocity.x)); |
---|
| 81 | pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt; |
---|
| 82 | } |
---|
| 83 | |
---|
[9725] | 84 | if (isFireing) |
---|
| 85 | ControllableEntity::fire(0); |
---|
| 86 | |
---|
[9793] | 87 | // Camera |
---|
| 88 | Camera* camera = this->getCamera(); |
---|
| 89 | if (camera != NULL) |
---|
[9777] | 90 | { |
---|
[9793] | 91 | camera->setPosition(Vector3(-pos.z, -posforeward, 0)); |
---|
| 92 | camera->setOrientation(Vector3::UNIT_Z, Degree(90)); |
---|
| 93 | // orxout() << "asbhajskjasjahg" << pos << endl; |
---|
[9777] | 94 | } |
---|
[9744] | 95 | |
---|
[9793] | 96 | |
---|
| 97 | |
---|
| 98 | // bring back on track! |
---|
[9828] | 99 | // if (pos.z > 42*2.5) |
---|
| 100 | // pos.z = 42*2.5; |
---|
| 101 | // else if (pos.z < -42*3) |
---|
| 102 | // pos.z = -42*3; |
---|
[9793] | 103 | if(pos.y != 0) |
---|
| 104 | pos.y = 0; |
---|
| 105 | |
---|
[9777] | 106 | |
---|
[9793] | 107 | setPosition(pos); |
---|
| 108 | setOrientation(Vector3::UNIT_Y, Degree(270)); |
---|
[9744] | 109 | |
---|
[9793] | 110 | // Level up! |
---|
[9828] | 111 | if (pos.x > 42000) |
---|
[9793] | 112 | { |
---|
| 113 | updateLevel(); |
---|
[9828] | 114 | setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0) |
---|
[9793] | 115 | } |
---|
[9744] | 116 | |
---|
[9725] | 117 | SUPER(InvaderShip, tick, dt); |
---|
| 118 | } |
---|
| 119 | |
---|
[9793] | 120 | void InvaderShip::updateLevel() |
---|
| 121 | { |
---|
| 122 | lastTime = 0; |
---|
[9829] | 123 | if (getGame()) |
---|
| 124 | { |
---|
| 125 | getGame()->levelUp(); |
---|
| 126 | // SmartPtr<Invader> game = orxonox_cast<Invader>(getGametype()); |
---|
| 127 | |
---|
| 128 | } |
---|
[9793] | 129 | //level++ |
---|
| 130 | } |
---|
[9777] | 131 | |
---|
[9725] | 132 | void InvaderShip::moveFrontBack(const Vector2& value) |
---|
| 133 | { |
---|
[9793] | 134 | lastTimeLeft = 0; |
---|
| 135 | desiredVelocity.x = -value.x * speed; |
---|
[9725] | 136 | } |
---|
| 137 | |
---|
| 138 | void InvaderShip::moveRightLeft(const Vector2& value) |
---|
| 139 | { |
---|
[9793] | 140 | lastTimeFront = 0; |
---|
| 141 | desiredVelocity.y = value.y * speed * 42; |
---|
[9725] | 142 | } |
---|
| 143 | void InvaderShip::boost(bool bBoost) |
---|
| 144 | { |
---|
| 145 | isFireing = bBoost; |
---|
| 146 | } |
---|
[9828] | 147 | inline bool InvaderShip::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) |
---|
| 148 | { |
---|
| 149 | // orxout() << "touch!!! " << endl; //<< otherObject << " at " << contactPoint; |
---|
| 150 | |
---|
| 151 | WeakPtr<InvaderEnemy> enemy = orxonox_cast<InvaderEnemy*>(otherObject); |
---|
| 152 | if (enemy != NULL && lastEnemy != enemy) |
---|
| 153 | { |
---|
| 154 | lastEnemy = enemy; |
---|
| 155 | orxout() << "Enemy!!!! " << endl; |
---|
| 156 | removeHealth(20); |
---|
| 157 | if (getHealth() <= 0) |
---|
| 158 | { |
---|
| 159 | orxout() << "DIED!!!! " << endl; |
---|
[9829] | 160 | if (getGame()) |
---|
| 161 | { |
---|
| 162 | getGame()->costLife(); |
---|
| 163 | // SmartPtr<Invader> game = orxonox_cast<Invader>(getGametype()); |
---|
| 164 | |
---|
| 165 | } |
---|
[9828] | 166 | } |
---|
| 167 | return false; |
---|
| 168 | } |
---|
| 169 | return false; |
---|
| 170 | // SUPER(InvaderShip, collidesAgainst, otherObject, contactPoint); |
---|
| 171 | } |
---|
[9829] | 172 | |
---|
| 173 | WeakPtr<Invader> InvaderShip::getGame() |
---|
| 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 | } |
---|
[9725] | 182 | } |
---|