Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

SOBGumbaBoss

File size: 3.7 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 All items in this minigame inherit from this class. Items can move around like platforms and enemies.
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_ = 10;
57        gumbaTime_ = 0;
58       
59    }
60
61
62
63   
64    bool SOBGumbaBoss::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) {
65
66        //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.
67        if (changeAllowed_ && otherObject->getMass() != -1) {
68            goesRight_ = !goesRight_;
69            changeAllowed_ = false;
70        }
71
72        return true;
73    }
74
75
76
77
78    void SOBGumbaBoss::tick(float dt)
79    {
80        SUPER(SOBGumbaBoss, tick, dt);
81
82        if (!changeAllowed_) {
83            changedOn_+= dt;
84            // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions!
85            if (changedOn_> 0.200) {
86                changeAllowed_ = true;
87                changedOn_ = 0.0;
88
89            }
90        }
91   
92        gumbaTime_ += dt;
93        orxout() << "gumbaTime_ = " << gumbaTime_ << endl;
94
95        if(gumbaTime_ > gumbaMaxTime_){
96            spawnFireball();
97            orxout() << "shoot" << endl;
98            gumbaTime_ = 0;
99        }
100
101        int dir = 1;
102        if (!goesRight_)
103            dir = -1;
104
105        Vector3 velocity = getVelocity();
106        velocity.z -= gravityAcceleration_*dt;
107        velocity.x = dir*speed_;
108        setVelocity(velocity);
109
110        lastPos_ = getPosition();
111
112    }
113    void SOBGumbaBoss::spawnFireball() {
114        SOBCenterpoint* center_ = ((SOB*)getGametype())->center_;
115
116         SOBFireball* ball = new SOBFireball(center_->getContext());
117         Vector3 spawnpos = this->getWorldPosition();
118         spawnpos.z += 0;
119
120        if (ball != nullptr && center_ != nullptr)
121        {
122            ball->addTemplate("fireball");
123            bool direction = ((this->getWorldOrientation().getRoll().valueRadians())>-1.6&&(this->getWorldOrientation().getRoll().valueRadians()<1.6));
124            ball->setDirection(direction);
125            if(direction)
126            {
127                spawnpos.x+=10;
128            }
129            else
130            {
131                spawnpos.x-=10;
132            }
133            ball->setPosition(spawnpos);
134
135        }
136     }
137}
Note: See TracBrowser for help on using the repository browser.