Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/superorxobros/SOBGumbaBoss.cc @ 12285

Last change on this file since 12285 was 11783, checked in by landauf, 7 years ago

merged Presentation_HS17_merge back to trunk

  • Property svn:eol-style set to native
File size: 5.4 KB
RevLine 
[11623]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 *      Noah Zarro
24 *      Theo von Arx
25 *   Co-authors:
26 *     
27 *
28 */
29
30/**
31    @file SOBGumbaBoss.cc
[11647]32    @brief A Boss Gumba, which shoots small Gumbas
[11650]33**/
[11623]34
35#include "SOB.h"
36#include "SOBGumba.h"
37#include "SOBGumbaBoss.h"
38#include "SOBFireball.h"
39#include "SOBFigure.h"
40
41#include "core/CoreIncludes.h"
42#include "core/XMLPort.h"
43#include "util/Output.h"
44#include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
45
46
47
48namespace orxonox
49{
50    RegisterClass(SOBGumbaBoss);
51
52    SOBGumbaBoss::SOBGumbaBoss(Context* context) : SOBGumba(context)
53    {
54        RegisterObject(SOBGumbaBoss);
55
[11654]56        gumbaMaxTime_   = 1;  // time after which a Gumba is shot
57        gumbaTime_      = 0;  // time since last gumba was shot
58        maxGumbas_      = 50; // Max Gumbas spawnable by a Boss
59        jumpTimeMax_    = 5;  // time after which the gumba boss jumps
60        jumpTime_       = 0;  // time since last jump of gumba boss
[11623]61       
62    }
63
[11654]64    // PRE: otherObject collides with this.
65    // POST: collision is handled: velocity changed, small gumbas murdered
[11623]66    bool SOBGumbaBoss::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) {
67
[11650]68        SOBGumba*       gumba       = orxonox_cast<SOBGumba*>(otherObject);
69        SOBGumbaBoss*   gumbaBoss   = orxonox_cast<SOBGumbaBoss*>(otherObject);
70
[11654]71        // if boss collides with small gumbas, destroy them.
[11650]72        if (gumba != nullptr && gumbaBoss == nullptr && !(gumba->hasCollided_)) {
[11654]73            gumba->die();
[11650]74        }
75
76
[11623]77        //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.
[11650]78        else if (changeAllowed_ && otherObject->getMass() != -1) {
[11623]79            goesRight_ = !goesRight_;
80            changeAllowed_ = false;
81        }
82
83        return true;
84    }
85
86
87
[11654]88    // POST: done what was to do in a time dt
[11623]89    void SOBGumbaBoss::tick(float dt)
90    {
91        SUPER(SOBGumbaBoss, tick, dt);
[11654]92
93        // increase timers:
[11650]94        gumbaTime_ += dt;
95        jumpTime_  += dt; 
[11623]96
[11654]97        // set y-component of position of gumba boss to 0, so he doesn't fall in to the nothing
98        Vector3 position = getPosition();
99        position.y = 0;
100        setPosition(position);
101
102
[11623]103        if (!changeAllowed_) {
104            changedOn_+= dt;
105            // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions!
106            if (changedOn_> 0.200) {
107                changeAllowed_ = true;
108                changedOn_ = 0.0;
109
110            }
111        }
112   
113
[11632]114        if(gumbaTime_ > gumbaMaxTime_){ //Spawn Gumba
115            int gumbaCounter=0;
116
117            for (SOBGumba*  gumbaInstance : ObjectList<SOBGumba>())
118            {
119                if (gumbaInstance != nullptr && gumbaInstance->creator_==this)
120                {
121                    gumbaCounter++;
122                }
123            } 
124
125
[11650]126            if(gumbaCounter<maxGumbas_){    //only maxGumbas are allowed at one time per Gumbaboss
[11632]127                spawnGumba();
128                gumbaTime_ = 0;
129            }
[11623]130        }
131
132        int dir = 1;
133        if (!goesRight_)
134            dir = -1;
135
[11654]136        //
137        if(getPosition().x < 1640)
138            dir = 1;
139        else if (getPosition().x > 1750)
140            dir = -1;
141
142        //change velocity
143        Vector3 velocity = getVelocity();
144        if(jumpTime_ > jumpTimeMax_){ // jump if the time has come.
[11650]145            velocity.z = speed_*15;
146            jumpTime_ = 0;
147        }
[11654]148        else{
[11650]149            velocity.z -= gravityAcceleration_*dt;
150        }
[11623]151        velocity.x = dir*speed_;
152        setVelocity(velocity);
153
154    }
[11654]155
156    // spawn gumbas
[11629]157    void SOBGumbaBoss::spawnGumba() {
[11623]158        SOBCenterpoint* center_ = ((SOB*)getGametype())->center_;
159
[11629]160         SOBGumba* gumba = new SOBGumba(center_->getContext());
[11623]161         Vector3 spawnpos = this->getWorldPosition();
[11632]162         gumba->creator_=this;
[11623]163
[11654]164         // we can shoot a gumba!
[11629]165        if (gumba != nullptr && center_ != nullptr)
[11623]166        {
[11629]167            gumba->addTemplate("gumbaShootable");
[11650]168            gumba->setDirection(goesRight_);
169            if(goesRight_)
[11623]170            {
[11629]171                spawnpos.x+=20;
[11623]172            }
173            else
174            {
[11629]175                spawnpos.x-=20;
[11623]176            }
[11629]177            spawnpos.z+=15;
178            gumba->setPosition(spawnpos);
[11623]179
180        }
[11626]181
[11629]182        Vector3 velocity = gumba->getVelocity();
[11650]183        velocity.x += (2*goesRight_ -1) * 100;
184        velocity.z += 200;
[11629]185        gumba->setVelocity(velocity);
[11623]186     }
187}
Note: See TracBrowser for help on using the repository browser.