[11593] | 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: |
---|
[11660] | 23 | * Viviane Yang |
---|
[11593] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[11660] | 29 | /* TODO: |
---|
[11617] | 30 | |
---|
[11593] | 31 | @file Asteroids2DShip.cc |
---|
| 32 | @brief Implementation of the Asteroids2DShip class. |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | #include "Asteroids2DShip.h" |
---|
[11637] | 36 | #include "Asteroids2DStone.h" |
---|
[11593] | 37 | #include "core/CoreIncludes.h" |
---|
| 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
| 41 | RegisterClass(Asteroids2DShip); |
---|
| 42 | |
---|
| 43 | Asteroids2DShip::Asteroids2DShip(Context* context) : SpaceShip(context) |
---|
| 44 | { |
---|
| 45 | RegisterObject(Asteroids2DShip); |
---|
| 46 | |
---|
| 47 | isFireing = false; |
---|
[11613] | 48 | this->width = 1043; |
---|
| 49 | this->height = 646; |
---|
[11593] | 50 | |
---|
[11660] | 51 | //timer.setTimer(3.5f, true, createExecutor(createFunctor(&Asteroids2DShip::showorientation, this))); |
---|
[11593] | 52 | } |
---|
| 53 | |
---|
[11613] | 54 | //Use this function to display your position on the field -> to determine field width and height |
---|
| 55 | void Asteroids2DShip::showposition() |
---|
| 56 | { |
---|
| 57 | Vector3 pos = this->getPosition(); |
---|
| 58 | orxout() << "x = "<< pos.x << " y = " << pos.y << " z = "<< pos.z << endl; |
---|
| 59 | } |
---|
| 60 | |
---|
[11660] | 61 | //Same thing for orientation |
---|
| 62 | void Asteroids2DShip::showorientation() |
---|
| 63 | { |
---|
| 64 | Quaternion ort = this->getOrientation(); |
---|
| 65 | orxout() << "w = " << ort.w << " x = " << ort.x << " y = " << ort.y << "z = " << ort.z << endl; |
---|
| 66 | } |
---|
| 67 | |
---|
[11593] | 68 | void Asteroids2DShip::tick(float dt) |
---|
| 69 | { |
---|
| 70 | SUPER(Asteroids2DShip, tick, dt); |
---|
[11613] | 71 | Vector3 pos = this->getPosition(); |
---|
| 72 | |
---|
[11660] | 73 | //ensure that the ship stays in playing field |
---|
[11613] | 74 | if(pos.x > width/2) pos.x = -width/2; |
---|
| 75 | if(pos.x < -width/2) pos.x = width/2; |
---|
| 76 | if(pos.z > height/2) pos.z = -height/2; |
---|
| 77 | if(pos.z < -height/2) pos.z = height/2; |
---|
| 78 | |
---|
| 79 | //2D movement, position should always = 0 on y-axis |
---|
| 80 | if(pos.y!=0) pos.y = 0; |
---|
| 81 | this->setPosition(pos); |
---|
| 82 | |
---|
| 83 | |
---|
[11666] | 84 | //if you hit an asteroid, the ship will turn -> you need to reorientate the ship |
---|
| 85 | Quaternion ort = this->getOrientation(); |
---|
| 86 | ort.x = 0; |
---|
| 87 | ort.z = 0; |
---|
| 88 | this->setOrientation(ort); |
---|
[11593] | 89 | } |
---|
| 90 | |
---|
[11660] | 91 | void Asteroids2DShip::boost(bool bBoost) |
---|
| 92 | { |
---|
| 93 | isFireing = bBoost; |
---|
| 94 | } |
---|
| 95 | |
---|
[11608] | 96 | void Asteroids2DShip::updateLevel() |
---|
[11593] | 97 | { |
---|
[11608] | 98 | if (getGame()) |
---|
| 99 | getGame()->levelUp(); |
---|
| 100 | } |
---|
| 101 | |
---|
[11593] | 102 | inline bool Asteroids2DShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) |
---|
| 103 | { |
---|
[11643] | 104 | |
---|
| 105 | Asteroids2DStone* stone = orxonox_cast<Asteroids2DStone*>(otherObject); |
---|
[11645] | 106 | if(stone != nullptr && !bImmune) |
---|
[11643] | 107 | { |
---|
| 108 | removeHealth(100); |
---|
[11645] | 109 | this->getGame()->addPoints(10); |
---|
| 110 | |
---|
| 111 | //The ship will be immune for 3 seconds after it has been hit by an asteroid |
---|
| 112 | bImmune = true; |
---|
| 113 | isimmune.setTimer(3.0f, false, createExecutor(createFunctor(&Asteroids2DShip::toggleImmune, this))); |
---|
[11643] | 114 | } |
---|
[11593] | 115 | return false; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | Asteroids2D* Asteroids2DShip::getGame() |
---|
| 119 | { |
---|
| 120 | if (game == nullptr) |
---|
| 121 | { |
---|
| 122 | for (Asteroids2D* race : ObjectList<Asteroids2D>()) |
---|
| 123 | { |
---|
| 124 | game = race; |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | return game; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | void Asteroids2DShip::death() |
---|
| 131 | { |
---|
[11608] | 132 | getGame()->costLife(); |
---|
[11593] | 133 | SpaceShip::death(); |
---|
| 134 | } |
---|
| 135 | } |
---|