/* * 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: * Noah Zarro * Theo von Arx * Co-authors: * * */ /** @file SOBGumbaBoss.cc @brief A Boss Gumba, which shoots small Gumbas **/ #include "SOB.h" #include "SOBGumba.h" #include "SOBGumbaBoss.h" #include "SOBFireball.h" #include "SOBFigure.h" #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "util/Output.h" #include namespace orxonox { RegisterClass(SOBGumbaBoss); SOBGumbaBoss::SOBGumbaBoss(Context* context) : SOBGumba(context) { RegisterObject(SOBGumbaBoss); gumbaMaxTime_ = 1; // time after which a Gumba is shot gumbaTime_ = 0; // time since last gumba was shot maxGumbas_ = 50; // Max Gumbas spawnable by a Boss jumpTimeMax_ = 5; // time after which the gumba boss jumps jumpTime_ = 0; // time since last jump of gumba boss } // PRE: otherObject collides with this. // POST: collision is handled: velocity changed, small gumbas murdered bool SOBGumbaBoss::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) { SOBGumba* gumba = orxonox_cast(otherObject); SOBGumbaBoss* gumbaBoss = orxonox_cast(otherObject); // if boss collides with small gumbas, destroy them. if (gumba != nullptr && gumbaBoss == nullptr && !(gumba->hasCollided_)) { gumba->die(); } //Every object with mass -1 does not change the direction of the GumbaBoss. For example the ground floor! The other objects switch the direction of the GumbaBoss. else if (changeAllowed_ && otherObject->getMass() != -1) { goesRight_ = !goesRight_; changeAllowed_ = false; } return true; } // POST: done what was to do in a time dt void SOBGumbaBoss::tick(float dt) { SUPER(SOBGumbaBoss, tick, dt); // increase timers: gumbaTime_ += dt; jumpTime_ += dt; // set y-component of position of gumba boss to 0, so he doesn't fall in to the nothing Vector3 position = getPosition(); position.y = 0; setPosition(position); if (!changeAllowed_) { changedOn_+= dt; // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions! if (changedOn_> 0.200) { changeAllowed_ = true; changedOn_ = 0.0; } } if(gumbaTime_ > gumbaMaxTime_){ //Spawn Gumba int gumbaCounter=0; for (SOBGumba* gumbaInstance : ObjectList()) { if (gumbaInstance != nullptr && gumbaInstance->creator_==this) { gumbaCounter++; } } if(gumbaCounter 1750) dir = -1; //change velocity Vector3 velocity = getVelocity(); if(jumpTime_ > jumpTimeMax_){ // jump if the time has come. velocity.z = speed_*15; jumpTime_ = 0; } else{ velocity.z -= gravityAcceleration_*dt; } velocity.x = dir*speed_; setVelocity(velocity); lastPos_ = getPosition(); } // spawn gumbas void SOBGumbaBoss::spawnGumba() { SOBCenterpoint* center_ = ((SOB*)getGametype())->center_; SOBGumba* gumba = new SOBGumba(center_->getContext()); Vector3 spawnpos = this->getWorldPosition(); gumba->creator_=this; // we can shoot a gumba! if (gumba != nullptr && center_ != nullptr) { gumba->addTemplate("gumbaShootable"); gumba->setDirection(goesRight_); if(goesRight_) { spawnpos.x+=20; } else { spawnpos.x-=20; } spawnpos.z+=15; gumba->setPosition(spawnpos); } Vector3 velocity = gumba->getVelocity(); velocity.x += (2*goesRight_ -1) * 100; velocity.z += 200; gumba->setVelocity(velocity); } }