[11506] | 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 | /** |
---|
[11555] | 30 | @file AsteroidsEnemy.h |
---|
| 31 | @brief Declaration of the AsteroidsEnemy class. |
---|
[11506] | 32 | */ |
---|
| 33 | |
---|
[11516] | 34 | #include "AsteroidsStone.h" |
---|
[11506] | 35 | #include "core/CoreIncludes.h" |
---|
[11516] | 36 | #include "Asteroids.h" |
---|
| 37 | #include "AsteroidsShip.h" |
---|
[11555] | 38 | #include <cstdlib> |
---|
[11516] | 39 | #include <cmath> |
---|
| 40 | #include "util/Math.h" |
---|
[11506] | 41 | |
---|
[11555] | 42 | const float delta = 3; |
---|
[11541] | 43 | |
---|
[11506] | 44 | namespace orxonox |
---|
| 45 | { |
---|
[11516] | 46 | RegisterClass(AsteroidsStone); |
---|
[11528] | 47 | //pawn kann sterben -> nach dem Tot sollen aber 2 Asteroiden spawnen |
---|
| 48 | AsteroidsStone::AsteroidsStone(Context* context) : Pawn(context) |
---|
[11506] | 49 | { |
---|
[11516] | 50 | RegisterObject(AsteroidsStone); |
---|
[11506] | 51 | |
---|
[11555] | 52 | direction = 0; |
---|
| 53 | //Spielfeld x als Horizontale und z als Vertikale |
---|
| 54 | fieldWidth_ = this->getGame()->center_->getFieldWidth; |
---|
| 55 | fieldHeigth_ = this->getGame()->center_->getFieldHeight; |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | //Random size 1, 2, 3 ->muss noch realisiert werden. Templates erstellen |
---|
| 59 | this.size = 1; |
---|
[11516] | 60 | maxspeed = 50.0f; |
---|
[11541] | 61 | //Random Spawn? pos= random? -> spawn durch timer in der Asteroids Klasse |
---|
[11555] | 62 | this->setPosition(rnd(fieldWidth_), 0, rnd(fieldHeigth)); |
---|
[11506] | 63 | |
---|
[11555] | 64 | //random Geschwindigkeit und Richtung |
---|
| 65 | velocity.x = rnd(maxspeed); |
---|
| 66 | velocity.y = rnd(maxspeed); |
---|
[11506] | 67 | } |
---|
[11541] | 68 | |
---|
[11555] | 69 | inline bool AsteroidsStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) |
---|
| 70 | { |
---|
| 71 | if(orxonox_cast<AsteroidsShip*>(otherObject)) |
---|
| 72 | removeHealth(2000); |
---|
| 73 | return false; |
---|
| 74 | } |
---|
| 75 | |
---|
[11541] | 76 | void Asteroids::death() |
---|
| 77 | { |
---|
| 78 | if(this->size == 1){ |
---|
| 79 | Pawn::death(); |
---|
| 80 | }else if(this->size == 2){ |
---|
| 81 | Pawn::death(); |
---|
| 82 | //Wie mache ich das ? Eigentlich in der game Klasse? sonst zeigt der Pointer auf einen falschen Bereich |
---|
| 83 | for(int i = 0; i<2; i++) |
---|
| 84 | { |
---|
| 85 | AsteroidsStone* newStone; |
---|
[11555] | 86 | newStone = new AsteroidsStone(this->getGame()->center_->getContext()); |
---|
[11541] | 87 | newStone->addTemplate("asteroidsstone"); |
---|
[11555] | 88 | newStone->setAsteroidsPlayer(this->getGame()->player); |
---|
[11541] | 89 | } |
---|
| 90 | |
---|
| 91 | } |
---|
| 92 | } |
---|
[11555] | 93 | |
---|
[11541] | 94 | |
---|
[11555] | 95 | Asteroids* AsteroidsStone::getGame() |
---|
| 96 | { |
---|
| 97 | if (game == nullptr) |
---|
| 98 | { |
---|
| 99 | for (Asteroids* Asteroids : ObjectList<Asteroids>()) |
---|
| 100 | game = asteroids; |
---|
| 101 | } |
---|
| 102 | return game; |
---|
| 103 | } |
---|
[11541] | 104 | |
---|
[11555] | 105 | |
---|
[11516] | 106 | //Bis hier geschrieben |
---|
| 107 | void AsteroidsStone::tick(float dt) |
---|
| 108 | { |
---|
[11555] | 109 | Vector3 pos = getPosition(); |
---|
[11541] | 110 | |
---|
[11555] | 111 | |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | //bounce on the borders |
---|
| 115 | if(pos.x-delta <= 0 || pos.x+delta >= fieldWidth_) |
---|
| 116 | direction = -direction; |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | //zurück bringen |
---|
[11541] | 121 | if(pos.y != 0){ |
---|
| 122 | pos.y=0; |
---|
| 123 | } |
---|
[11555] | 124 | |
---|
| 125 | //spin |
---|
| 126 | |
---|
| 127 | setOrientation() |
---|
[11516] | 128 | setPosition(pos); |
---|
[11555] | 129 | |
---|
[11516] | 130 | SUPER(AsteroidsStone, tick, dt); |
---|
| 131 | } |
---|
[11506] | 132 | |
---|
[11516] | 133 | inline bool AsteroidsStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) |
---|
[11506] | 134 | { |
---|
[11555] | 135 | if(orxonox_cast<AsteroidsShip*>(otherObject)) |
---|
[11506] | 136 | removeHealth(2000); |
---|
| 137 | return false; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | } |
---|