/* ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Viviane Yang * Co-authors: * ... * */ /** @file Asteroids2DStone.cc @brief Implementation of the Asteroids2DStone class. TO DO: - instead of moving over the boarders of the playing field, modify the tick function so that the stones bounce back - when to split? It does not work if you override kill() function...->damage() function? */ #include "Asteroids2DStone.h" #include "Asteroids2D.h" #include "Asteroids2DShip.h" #include "core/CoreIncludes.h" #include "util/Math.h" namespace orxonox { RegisterClass(Asteroids2DStone); Asteroids2DStone::Asteroids2DStone(Context* context) : Pawn(context) { RegisterObject(Asteroids2DStone); this->size = rand()%3+1; this->width = 1043; this->height = 646; this->setPosition(randomPosition(this->width, this->height)); this->setCollisionTypeStr("dynamic"); this->setVelocity(randomVelocity(MAX_SPEED)); } Asteroids2DStone::Asteroids2DStone(Context* c, int sze, Vector3 pos) : Pawn(c) { RegisterObject(Asteroids2DStone); this->size = sze; this->width = 1043; this->height = 646; this->setPosition(pos); this->setCollisionTypeStr("dynamic"); this->setVelocity(randomVelocity(MAX_SPEED)); } Vector3 Asteroids2DStone::randomPosition(float maxwidth, float maxheight) { Vector3 pos; pos.x = rnd(-maxwidth/2, maxwidth/2); pos.y = 0; pos.z = rnd(-maxheight/2, maxheight/2); return pos; } Vector3 Asteroids2DStone::randomVelocity(float maxspeed) { Vector3 vel; vel.x = rnd(maxspeed); vel.y = 0; vel.z = rnd(maxspeed); return vel; } void Asteroids2DStone::tick(float dt) { SUPER(Asteroids2DStone, tick, dt); Vector3 pos = this->getPosition(); if(pos.x >= width/2){ pos.x = -width/2; }else if(pos.x <= -width/2){ pos.x = -width/2; }else if(pos.z >= height/2){ pos.z = -height/2; }else if(pos.z <= -height/2){ pos.z = -width/2; } this->setPosition(pos); } inline bool Asteroids2DStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) { orxout() << "AsteroidStone getroffen" << endl; if(orxonox_cast(otherObject)) { orxout() << "getroffen von Ship" << endl; split(); } return false; } void Asteroids2DStone::split() { orxout() << "split" << endl; if(size == 1) { this->death(); }else if(size == 2){ //Templates can be found in data/levels/templates/asteroidsAsteroids2D.oxt Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 1, this->getPosition()); newStone1->addTemplate("stone1"); Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 1, this->getPosition()); newStone2->addTemplate("stone1"); }else{ Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 2, this->getPosition()); newStone1->addTemplate("stone1"); Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 2, this->getPosition()); newStone2->addTemplate("stone1"); } } }