[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: |
---|
| 23 | * Florian Zinggeler |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[11617] | 29 | /*TODO: orientation/direction of the ship must be defined |
---|
| 30 | implement shoot function ->or switch it on? |
---|
| 31 | switch off boosting particles in the back of the ship |
---|
| 32 | |
---|
[11593] | 33 | /** |
---|
| 34 | @file Asteroids2DShip.cc |
---|
| 35 | @brief Implementation of the Asteroids2DShip class. |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "Asteroids2DShip.h" |
---|
[11637] | 39 | #include "Asteroids2DStone.h" |
---|
[11593] | 40 | #include "core/CoreIncludes.h" |
---|
| 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | RegisterClass(Asteroids2DShip); |
---|
| 45 | |
---|
| 46 | Asteroids2DShip::Asteroids2DShip(Context* context) : SpaceShip(context) |
---|
| 47 | { |
---|
| 48 | RegisterObject(Asteroids2DShip); |
---|
| 49 | |
---|
| 50 | speed = 830; |
---|
| 51 | isFireing = false; |
---|
| 52 | damping = 10; |
---|
[11613] | 53 | this->width = 1043; |
---|
| 54 | this->height = 646; |
---|
[11593] | 55 | |
---|
[11613] | 56 | timer.setTimer(3.5f, true, createExecutor(createFunctor(&Asteroids2DShip::showposition, this))); |
---|
[11593] | 57 | } |
---|
| 58 | |
---|
[11613] | 59 | //Use this function to display your position on the field -> to determine field width and height |
---|
| 60 | void Asteroids2DShip::showposition() |
---|
| 61 | { |
---|
| 62 | Vector3 pos = this->getPosition(); |
---|
| 63 | orxout() << "x = "<< pos.x << " y = " << pos.y << " z = "<< pos.z << endl; |
---|
| 64 | } |
---|
| 65 | |
---|
[11593] | 66 | void Asteroids2DShip::tick(float dt) |
---|
| 67 | { |
---|
| 68 | SUPER(Asteroids2DShip, tick, dt); |
---|
[11613] | 69 | Vector3 pos = this->getPosition(); |
---|
| 70 | |
---|
| 71 | //haelt ship innerhalb des Kamerafensters, kommt oben bzw seitlich wieder raus. Man spawnt in (0,0) |
---|
| 72 | if(pos.x > width/2) pos.x = -width/2; |
---|
| 73 | if(pos.x < -width/2) pos.x = width/2; |
---|
| 74 | if(pos.z > height/2) pos.z = -height/2; |
---|
| 75 | if(pos.z < -height/2) pos.z = height/2; |
---|
| 76 | |
---|
| 77 | //2D movement, position should always = 0 on y-axis |
---|
| 78 | if(pos.y!=0) pos.y = 0; |
---|
| 79 | this->setPosition(pos); |
---|
| 80 | |
---|
| 81 | //update level |
---|
| 82 | |
---|
| 83 | //shoot? |
---|
[11593] | 84 | } |
---|
| 85 | |
---|
[11608] | 86 | void Asteroids2DShip::updateLevel() |
---|
[11593] | 87 | { |
---|
[11608] | 88 | if (getGame()) |
---|
| 89 | getGame()->levelUp(); |
---|
| 90 | } |
---|
| 91 | |
---|
[11593] | 92 | void Asteroids2DShip::boost(bool bBoost) |
---|
| 93 | { |
---|
| 94 | //getGame()->bEndGame = bBoost; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | inline bool Asteroids2DShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) |
---|
| 98 | { |
---|
[11643] | 99 | |
---|
| 100 | orxout() << "touched" << endl; |
---|
| 101 | Asteroids2DStone* stone = orxonox_cast<Asteroids2DStone*>(otherObject); |
---|
| 102 | if(stone != nullptr && (stone != lastStone || lastStone == nullptr)) |
---|
| 103 | { |
---|
| 104 | removeHealth(100); |
---|
| 105 | lastStone = stone; |
---|
| 106 | |
---|
| 107 | } |
---|
[11593] | 108 | return false; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | Asteroids2D* Asteroids2DShip::getGame() |
---|
| 112 | { |
---|
| 113 | if (game == nullptr) |
---|
| 114 | { |
---|
| 115 | for (Asteroids2D* race : ObjectList<Asteroids2D>()) |
---|
| 116 | { |
---|
| 117 | game = race; |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | return game; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | void Asteroids2DShip::death() |
---|
| 124 | { |
---|
[11608] | 125 | getGame()->costLife(); |
---|
[11593] | 126 | SpaceShip::death(); |
---|
| 127 | } |
---|
| 128 | } |
---|