Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SOBv2_HS17/src/modules/superorxobros/SOBGumbaBoss.cc @ 11650

Last change on this file since 11650 was 11650, checked in by varxth, 6 years ago

better than evver

File size: 4.6 KB
Line 
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
32    @brief A Boss Gumba, which shoots small Gumbas
33**/
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
56        gumbaMaxTime_   = 1;
57        gumbaTime_      = 0;
58        maxGumbas_      = 10; //Max Gumbas spawnable by a Boss
59        jumpTime_       = 0;
60        jumpTimeMax_    = 5;
61       
62    }
63
64   
65    bool SOBGumbaBoss::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) {
66
67        SOBGumba*       gumba       = orxonox_cast<SOBGumba*>(otherObject);
68        SOBGumbaBoss*   gumbaBoss   = orxonox_cast<SOBGumbaBoss*>(otherObject);
69
70        if (gumba != nullptr && gumbaBoss == nullptr && !(gumba->hasCollided_)) {
71            gumba->destroyLater();
72            gumba->hasCollided_ = true;
73        }
74
75
76        //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.
77        else if (changeAllowed_ && otherObject->getMass() != -1) {
78            goesRight_ = !goesRight_;
79            changeAllowed_ = false;
80        }
81
82        return true;
83    }
84
85
86
87
88    void SOBGumbaBoss::tick(float dt)
89    {
90        SUPER(SOBGumbaBoss, tick, dt);
91        gumbaTime_ += dt;
92        jumpTime_  += dt; 
93
94        if (!changeAllowed_) {
95            changedOn_+= dt;
96            // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions!
97            if (changedOn_> 0.200) {
98                changeAllowed_ = true;
99                changedOn_ = 0.0;
100
101            }
102        }
103   
104
105        if(gumbaTime_ > gumbaMaxTime_){ //Spawn Gumba
106            int gumbaCounter=0;
107
108            for (SOBGumba*  gumbaInstance : ObjectList<SOBGumba>())
109            {
110                if (gumbaInstance != nullptr && gumbaInstance->creator_==this)
111                {
112                    gumbaCounter++;
113                }
114            } 
115
116
117            if(gumbaCounter<maxGumbas_){    //only maxGumbas are allowed at one time per Gumbaboss
118                spawnGumba();
119                gumbaTime_ = 0;
120            }
121        }
122
123        int dir = 1;
124        if (!goesRight_)
125            dir = -1;
126
127        Vector3 velocity = getVelocity();
128        if(jumpTime_ > jumpTimeMax_){
129            velocity.z = speed_*15;
130            jumpTime_ = 0;
131        }
132        else{
133            velocity.z -= gravityAcceleration_*dt;
134        }
135
136        velocity.x = dir*speed_;
137        setVelocity(velocity);
138
139        lastPos_ = getPosition();
140
141    }
142    void SOBGumbaBoss::spawnGumba() {
143        SOBCenterpoint* center_ = ((SOB*)getGametype())->center_;
144
145         SOBGumba* gumba = new SOBGumba(center_->getContext());
146         Vector3 spawnpos = this->getWorldPosition();
147         spawnpos.z += 0;
148         gumba->creator_=this;
149
150        if (gumba != nullptr && center_ != nullptr)
151        {
152            gumba->addTemplate("gumbaShootable");
153            gumba->setDirection(goesRight_);
154            if(goesRight_)
155            {
156                spawnpos.x+=20;
157            }
158            else
159            {
160                spawnpos.x-=20;
161            }
162            spawnpos.z+=15;
163            gumba->setPosition(spawnpos);
164
165        }
166
167        Vector3 velocity = gumba->getVelocity();
168        velocity.x += (2*goesRight_ -1) * 100;
169        velocity.z += 200;
170        gumba->setVelocity(velocity);
171     }
172}
Note: See TracBrowser for help on using the repository browser.