Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SOBv2_HS17/src/modules/superorxobros/SOBFireball.cc @ 11577

Last change on this file since 11577 was 11577, checked in by zarron, 6 years ago

first atempt to set dir of fireballs correctly

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 *      Theo von Arx
24 *      Noah Zarro
25 *   Co-authors:
26 *     
27 *
28 */
29
30/**
31    @file SOBFireball.cc
32    @brief Fireballs are the Projectile of the Fireflower Powerup
33*/
34
35#include "SOBFireball.h"
36
37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
39#include "SOBFigure.h"
40#include "SOBGumba.h"
41#include "SOB.h"   
42#include "util/Output.h"
43#include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
44
45
46
47namespace orxonox
48{
49    RegisterClass(SOBFireball);
50
51    SOBFireball::SOBFireball(Context* context) : MovableEntity(context)
52    {
53        RegisterObject(SOBFireball);
54
55        attachedToFigure_ = false;
56        setAngularFactor(0.0);
57        figure_ = nullptr;
58        this->enableCollisionCallback();
59        gravityAcceleration_ = 350.0;
60        speed_ = 0;
61        hasCollided_=false;
62        lastPos_ = getPosition();
63        lastPos_.x -= 20;
64        changeAllowed_ = true;
65        changedOn_ = 0.0;
66        goesRight_ = true;
67        collDisX_ = 0;
68        collDisZ_ = 0;
69        hitCounter_ = 0;
70       
71    }
72
73   
74
75    void SOBFireball::XMLPort(Element& xmlelement, XMLPort::Mode mode)
76    {
77        SUPER(SOBFireball, XMLPort, xmlelement, mode);
78        XMLPortParam(SOBFireball, "speed", setSpeed, getSpeed, xmlelement, mode);
79
80
81    }
82
83    void SOBFireball::setDirection(const bool direction)
84    {
85        if(direction)
86        {
87            goesRight_=true;
88        }
89        else
90        {
91            goesRight_=false;
92        }
93    }
94
95   
96    bool SOBFireball::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) {
97        collDisX_ = getPosition().x - contactPoint.getPositionWorldOnB().getX();
98        collDisZ_ = getPosition().z - contactPoint.getPositionWorldOnB().getZ();
99
100        SOBGumba* gumba = orxonox_cast<SOBGumba*>(otherObject);
101
102
103        if(gumba!=nullptr && !(gumba->hasCollided_)) //if other object is a Gumba, kill the Gumba and add score and destroy the fireball
104        {
105            gumba->destroyLater();
106            gumba->hasCollided_ = true;
107            SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
108            SOBGame->addGumba();
109            this->destroyLater();
110            this->hasCollided_ = true;
111        }
112
113
114         //collision with either top or bottom of a block
115        else if(changeAllowed_ && (abs(collDisX_)<=abs(collDisZ_)))
116        {
117            changeAllowed_ = false;
118            Vector3 velocity = getVelocity();
119            velocity.z = -velocity.z;
120     
121
122            setVelocity(velocity);
123        }
124
125        //collision with the vertical side of a block
126        else if(changeAllowed_ && (abs(collDisX_)>abs(collDisZ_))) 
127        {
128            changeAllowed_ = false;
129            goesRight_=!goesRight_;
130        }
131
132        hitCounter_++;
133       
134        return true;
135    }
136
137
138    void SOBFireball::setFigure(SOBFigure* newFigure)
139    {
140        figure_ = newFigure;
141    }
142
143
144
145    void SOBFireball::tick(float dt)
146    {
147        SUPER(SOBFireball, tick, dt);
148
149        if (!changeAllowed_) {
150            changedOn_+= dt;
151            // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions!
152            if (changedOn_> 0.100) {
153                changeAllowed_ = true;
154                changedOn_ = 0.0;
155
156            }
157       
158        }
159            int dir = 1;
160            if (!goesRight_)
161                dir = -1;
162
163            Vector3 velocity = getVelocity();
164            velocity.z -= gravityAcceleration_*dt;
165            velocity.x = dir*speed_;
166            velocity.y = 0;
167            if(hitCounter_ >= 3) velocity.y = 50;
168            setVelocity(velocity);
169
170            lastPos_ = getPosition();
171
172            if(abs(this->getPosition().z) > 1000) delete this;
173       
174    }
175   
176
177
178}
Note: See TracBrowser for help on using the repository browser.