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