[11616] | 1 | /* ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 2 | * > www.orxonox.net < |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License |
---|
| 9 | * as published by the Free Software Foundation; either version 2 |
---|
| 10 | * of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
[11660] | 22 | * Viviane Yang |
---|
[11616] | 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
[11660] | 28 | |
---|
| 29 | |
---|
[11616] | 30 | /** |
---|
| 31 | @file Asteroids2DStone.cc |
---|
[11660] | 32 | |
---|
[11616] | 33 | @brief Implementation of the Asteroids2DStone class. |
---|
| 34 | |
---|
[11660] | 35 | TO DO: |
---|
| 36 | - instead of moving over the boarders of the playing field, modify the tick function so that the stones bounce back |
---|
| 37 | - when to split? It does not work if you override kill() function...->damage() function? |
---|
| 38 | */ |
---|
| 39 | |
---|
[11616] | 40 | #include "Asteroids2DStone.h" |
---|
| 41 | #include "Asteroids2D.h" |
---|
| 42 | #include "Asteroids2DShip.h" |
---|
| 43 | #include "core/CoreIncludes.h" |
---|
| 44 | #include "util/Math.h" |
---|
| 45 | |
---|
| 46 | namespace orxonox |
---|
| 47 | { |
---|
| 48 | RegisterClass(Asteroids2DStone); |
---|
| 49 | |
---|
| 50 | Asteroids2DStone::Asteroids2DStone(Context* context) : Pawn(context) |
---|
| 51 | { |
---|
| 52 | RegisterObject(Asteroids2DStone); |
---|
[11637] | 53 | this->size = rand()%3+1; |
---|
[11616] | 54 | this->width = 1043; |
---|
| 55 | this->height = 646; |
---|
| 56 | this->setPosition(randomPosition(this->width, this->height)); |
---|
[11637] | 57 | this->setCollisionTypeStr("dynamic"); |
---|
[11616] | 58 | this->setVelocity(randomVelocity(MAX_SPEED)); |
---|
| 59 | } |
---|
| 60 | |
---|
[11637] | 61 | Asteroids2DStone::Asteroids2DStone(Context* c, int sze, Vector3 pos) : Pawn(c) |
---|
| 62 | { |
---|
| 63 | RegisterObject(Asteroids2DStone); |
---|
| 64 | this->size = sze; |
---|
| 65 | this->width = 1043; |
---|
| 66 | this->height = 646; |
---|
| 67 | this->setPosition(pos); |
---|
| 68 | this->setCollisionTypeStr("dynamic"); |
---|
| 69 | this->setVelocity(randomVelocity(MAX_SPEED)); |
---|
| 70 | } |
---|
| 71 | |
---|
[11616] | 72 | Vector3 Asteroids2DStone::randomPosition(float maxwidth, float maxheight) |
---|
| 73 | { |
---|
| 74 | Vector3 pos; |
---|
| 75 | pos.x = rnd(-maxwidth/2, maxwidth/2); |
---|
| 76 | pos.y = 0; |
---|
| 77 | pos.z = rnd(-maxheight/2, maxheight/2); |
---|
| 78 | return pos; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | Vector3 Asteroids2DStone::randomVelocity(float maxspeed) |
---|
| 82 | { |
---|
| 83 | Vector3 vel; |
---|
| 84 | vel.x = rnd(maxspeed); |
---|
| 85 | vel.y = 0; |
---|
| 86 | vel.z = rnd(maxspeed); |
---|
| 87 | return vel; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | void Asteroids2DStone::tick(float dt) |
---|
| 92 | { |
---|
| 93 | SUPER(Asteroids2DStone, tick, dt); |
---|
| 94 | Vector3 pos = this->getPosition(); |
---|
[11637] | 95 | |
---|
[11660] | 96 | |
---|
[11637] | 97 | if(pos.x >= width/2){ |
---|
| 98 | pos.x = -width/2; |
---|
| 99 | }else if(pos.x <= -width/2){ |
---|
| 100 | pos.x = -width/2; |
---|
| 101 | }else if(pos.z >= height/2){ |
---|
| 102 | pos.z = -height/2; |
---|
| 103 | }else if(pos.z <= -height/2){ |
---|
| 104 | pos.z = -width/2; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | this->setPosition(pos); |
---|
| 108 | |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | inline bool Asteroids2DStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) |
---|
| 112 | { |
---|
[11660] | 113 | orxout() << "AsteroidStone getroffen" << endl; |
---|
[11637] | 114 | if(orxonox_cast<Asteroids2DShip*>(otherObject)) |
---|
[11616] | 115 | { |
---|
[11660] | 116 | orxout() << "getroffen von Ship" << endl; |
---|
| 117 | split(); |
---|
[11616] | 118 | } |
---|
[11637] | 119 | return false; |
---|
| 120 | } |
---|
[11616] | 121 | |
---|
[11637] | 122 | void Asteroids2DStone::split() |
---|
| 123 | { |
---|
[11660] | 124 | orxout() << "split" << endl; |
---|
[11637] | 125 | if(size == 1) |
---|
| 126 | { |
---|
| 127 | this->death(); |
---|
| 128 | |
---|
| 129 | }else if(size == 2){ |
---|
[11660] | 130 | |
---|
| 131 | |
---|
| 132 | //Templates can be found in data/levels/templates/asteroidsAsteroids2D.oxt |
---|
[11637] | 133 | Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 1, this->getPosition()); |
---|
| 134 | newStone1->addTemplate("stone1"); |
---|
| 135 | Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 1, this->getPosition()); |
---|
| 136 | newStone2->addTemplate("stone1"); |
---|
[11660] | 137 | |
---|
[11637] | 138 | }else{ |
---|
| 139 | Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 2, this->getPosition()); |
---|
| 140 | newStone1->addTemplate("stone1"); |
---|
| 141 | Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 2, this->getPosition()); |
---|
| 142 | newStone2->addTemplate("stone1"); |
---|
| 143 | } |
---|
[11616] | 144 | } |
---|
| 145 | |
---|
| 146 | } |
---|