Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.cc @ 12305

Last change on this file since 12305 was 12291, checked in by pomselj, 6 years ago

BallProjectile method is caled during collision

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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file ParticleProjectile.h
31    @brief Implementation of the ParticleProjectile class.
32*/
33
34#include "BallProjectile.h"
35
36#include <OgreParticleEmitter.h>
37#include "core/CoreIncludes.h"
38#include "tools/ParticleInterface.h"
39#include "Scene.h"
40#include "core/command/Executor.h"
41#include "util/Convert.h"
42
43namespace orxonox
44{
45    RegisterClass(BallProjectile);
46
47    BallProjectile::BallProjectile(Context* context) : BillboardProjectile(context)
48    {
49        RegisterObject(BallProjectile);
50        this->textureIndex_ = 1;
51        this->setMass(0.1f);
52        this->maxTextureIndex_ = 8;
53        this->setDestroyAfterCollision(false); //I want the ball to bounce, not to be destroyed
54
55        //setEffect("Orxonox/sparks2");
56    }
57
58    void BallProjectile::registerVariables()
59    {
60        registerVariable(this->materialBase_);
61    }
62
63    /**
64    @brief
65        Set the material.
66    @param material
67        The name of the material. Material names with 1 to 8 appended must exist.
68    */
69    void BallProjectile::setMaterial(const std::string& material)
70    {
71        this->materialBase_ = material;
72
73        BillboardProjectile::setMaterial(material + multi_cast<std::string>(this->textureIndex_));
74    }
75
76    /**
77    @brief
78        Change the texture.
79    */
80    void BallProjectile::changeTexture()
81    {
82        this->textureIndex_++;
83        if (this->textureIndex_ > this->maxTextureIndex_)
84            this->textureIndex_ = 1;
85
86        this->setMaterial(this->materialBase_);
87    }
88
89    void BallProjectile::Bounce(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs) {
90
91        Vector3 velocity = this->getVelocity();
92        Vector3 positionOtherObject = otherObject->getPosition();
93        Vector3 contactPosition = this->getPosition();
94        orxout() << "About to Bounce >D" << endl;
95        //if (positionOtherObject.y < 0) {
96            //this.destroy()
97        //}S
98        //else {
99       
100            int distance_X = positionOtherObject.x - contactPosition.x;
101            int distance_Y = positionOtherObject.y - contactPosition.y;
102
103            if (distance_X < 0)
104                distance_Y = -distance_Y;
105   
106
107            if (distance_Y < 0)
108                distance_X = -distance_X;
109
110            if (distance_X < distance_Y)
111                velocity.y = -velocity.y;
112            if (distance_Y < distance_X)
113                velocity.x = -velocity.x;
114            else {
115                velocity.x = -velocity.x;
116                velocity.y = -velocity.y;
117            }
118        //}
119    }
120
121/**
122    @brief
123        The function called when a projectile hits another thing.
124        Calls the hit-function, starts the shield recharge countdown, displays visual hit effects defined in Pawn.
125        Needs to be called in the collidesAgainst() function by every Class directly inheriting from BasicProjectile.
126    @param otherObject
127        A pointer to the object the Projectile has collided against.
128    @param contactPoint
129        A btManifoldPoint indicating the point of contact/impact.
130    @param cs
131        The btCollisionShape of the other object
132    @return
133        Returns true if the collision resulted in a successful hit.
134    @see Pawn.h
135    */
136   
137    bool BallProjectile::processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs)
138    {
139
140        orxout() << "wanna bounce..." << endl;
141        bool result = BasicProjectile::processCollision(otherObject, contactPoint, cs);
142        Bounce(otherObject, contactPoint, cs);
143        orxout() << "BOUNCED!" << endl;
144
145        return result;
146    }
147}
Note: See TracBrowser for help on using the repository browser.