[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 | /** |
---|
| 32 | @file Asteroids2DShip.cc |
---|
| 33 | @brief Implementation of the Asteroids2DShip class. |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | #include "Asteroids2DShip.h" |
---|
[11637] | 37 | #include "Asteroids2DStone.h" |
---|
[11593] | 38 | #include "core/CoreIncludes.h" |
---|
| 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
| 42 | RegisterClass(Asteroids2DShip); |
---|
| 43 | |
---|
| 44 | Asteroids2DShip::Asteroids2DShip(Context* context) : SpaceShip(context) |
---|
| 45 | { |
---|
| 46 | RegisterObject(Asteroids2DShip); |
---|
| 47 | |
---|
| 48 | speed = 830; |
---|
| 49 | isFireing = false; |
---|
| 50 | damping = 10; |
---|
[11613] | 51 | this->width = 1043; |
---|
| 52 | this->height = 646; |
---|
[11593] | 53 | |
---|
[11660] | 54 | //timer.setTimer(3.5f, true, createExecutor(createFunctor(&Asteroids2DShip::showorientation, this))); |
---|
[11593] | 55 | } |
---|
| 56 | |
---|
[11613] | 57 | //Use this function to display your position on the field -> to determine field width and height |
---|
| 58 | void Asteroids2DShip::showposition() |
---|
| 59 | { |
---|
| 60 | Vector3 pos = this->getPosition(); |
---|
| 61 | orxout() << "x = "<< pos.x << " y = " << pos.y << " z = "<< pos.z << endl; |
---|
| 62 | } |
---|
| 63 | |
---|
[11660] | 64 | //Same thing for orientation |
---|
| 65 | void Asteroids2DShip::showorientation() |
---|
| 66 | { |
---|
| 67 | Quaternion ort = this->getOrientation(); |
---|
| 68 | orxout() << "w = " << ort.w << " x = " << ort.x << " y = " << ort.y << "z = " << ort.z << endl; |
---|
| 69 | } |
---|
| 70 | |
---|
[11593] | 71 | void Asteroids2DShip::tick(float dt) |
---|
| 72 | { |
---|
| 73 | SUPER(Asteroids2DShip, tick, dt); |
---|
[11613] | 74 | Vector3 pos = this->getPosition(); |
---|
| 75 | |
---|
[11660] | 76 | //ensure that the ship stays in playing field |
---|
[11613] | 77 | if(pos.x > width/2) pos.x = -width/2; |
---|
| 78 | if(pos.x < -width/2) pos.x = width/2; |
---|
| 79 | if(pos.z > height/2) pos.z = -height/2; |
---|
| 80 | if(pos.z < -height/2) pos.z = height/2; |
---|
| 81 | |
---|
| 82 | //2D movement, position should always = 0 on y-axis |
---|
| 83 | if(pos.y!=0) pos.y = 0; |
---|
| 84 | this->setPosition(pos); |
---|
| 85 | |
---|
| 86 | |
---|
[11660] | 87 | |
---|
[11613] | 88 | //shoot? |
---|
[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 | } |
---|