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