Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

better Fireball

File size: 4.5 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      orxout() << "fireball existed" << endl;
72
73       
74    }
75
76   
77
78    void SOBFireball::XMLPort(Element& xmlelement, XMLPort::Mode mode)
79    {
80        SUPER(SOBFireball, XMLPort, xmlelement, mode);
81        XMLPortParam(SOBFireball, "speed", setSpeed, getSpeed, xmlelement, mode);
82
83
84    }
85
86   
87    bool SOBFireball::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) {
88        collDisX_ = getPosition().x - contactPoint.getPositionWorldOnB().getX();
89        collDisZ_ = getPosition().z - contactPoint.getPositionWorldOnB().getZ();
90
91        SOBGumba* gumba = orxonox_cast<SOBGumba*>(otherObject);
92
93        if(gumba!=nullptr && !(gumba->hasCollided_)) //if other object is a Gumba, kill the Gumba and add score and destroy the fireball
94        {
95            gumba->destroyLater();
96            gumba->hasCollided_ = true;
97            SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
98            SOBGame->addGumba();
99            this->destroyLater();
100            this->hasCollided_ = true;
101        }
102         //collision with either top or bottom of a block
103        else if(changeAllowed_ && (abs(collDisX_)<=abs(collDisZ_)))
104        {
105            changeAllowed_ = false;
106            Vector3 velocity = getVelocity();
107            orxout() << "before:    velocity in z = " << velocity.z << endl;
108            velocity.z = -velocity.z;
109            orxout() << "after:     velocity in z = " << velocity.z << endl;
110
111            setVelocity(velocity);
112        }
113
114        //collision with the vertical side of a block
115        else if(changeAllowed_ && (abs(collDisX_)>abs(collDisZ_))) 
116        {
117            orxout() << "collision with the vertical side of a block " << endl;
118
119            changeAllowed_ = false;
120            goesRight_=!goesRight_;
121        }
122
123        hitCounter_++;
124
125       
126        return true;
127    }
128
129
130    void SOBFireball::setFigure(SOBFigure* newFigure)
131    {
132        figure_ = newFigure;
133    }
134
135
136
137    void SOBFireball::tick(float dt)
138    {
139        SUPER(SOBFireball, tick, dt);
140
141        if (!changeAllowed_) {
142            changedOn_+= dt;
143            // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions!
144            if (changedOn_> 0.100) {
145                changeAllowed_ = true;
146                changedOn_ = 0.0;
147
148            }
149       
150        }
151            int dir = 1;
152            if (!goesRight_)
153                dir = -1;
154
155            Vector3 velocity = getVelocity();
156            velocity.z -= gravityAcceleration_*dt;
157            velocity.x = dir*speed_;
158            velocity.y = 0;
159            setVelocity(velocity);
160
161            lastPos_ = getPosition();
162       
163    }
164   
165
166
167}
Note: See TracBrowser for help on using the repository browser.