Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

komplet

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