Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_FS17/src/modules/superorxobros/SOBFigure.cc @ 11402

Last change on this file since 11402 was 11402, checked in by jkindle, 7 years ago

Added mushrooms and deadzone

File size: 6.1 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 *      Fabien Vultier
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file SOBFigure.cc
31    @brief This class represents your figure when you play the minigame. Here the movement of the figure, activating items, ... are handled.
32*/
33
34#include "SOBFigure.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "graphics/Model.h"
39#include "graphics/Camera.h"
40#include "graphics/ParticleSpawner.h"
41
42#include "SOBMushroom.h"
43
44namespace orxonox
45{
46    RegisterClass(SOBFigure);
47
48    SOBFigure::SOBFigure(Context* context) : ControllableEntity(context)
49    {
50        RegisterObject(SOBFigure);
51
52        // initialize variables
53
54        moveUpPressed_ = false;
55        moveDownPressed_ = false;
56        moveLeftPressed_ = false;
57        moveDownPressed_ = false;
58        firePressed_ = false;
59        timeSinceLastFire_ = 0.0;
60        lastSpeed_z = 0.0;
61        isColliding_ = true;
62        particlespawner_ = NULL;
63
64        gravityAcceleration_ = 350.0;
65        pitch_ = 0.0;
66
67        dead_ = false;
68        setAngularFactor(0.0);
69         this->enableCollisionCallback();
70    }
71
72
73
74    bool SOBFigure::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) {
75
76        isColliding_ = true;
77        SOBMushroom* mush = orxonox_cast<SOBMushroom*>(otherObject);
78        if (mush != nullptr) {
79            orxout() << "YEPPIE" << endl;
80            //DESTROY THE OTHER OBJECT otherObject.destroyLater();
81        }
82
83return true;
84    }
85
86
87
88    void SOBFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode)
89    {
90        SUPER(SOBFigure, XMLPort, xmlelement, mode);
91
92    }
93
94
95
96    void SOBFigure::tick(float dt)
97    {
98        SUPER(SOBFigure, tick, dt);
99
100        if (particlespawner_ == NULL) {
101            for (WorldEntity* object : this->getAttachedObjects())
102            {
103                 if (object->isA(Class(ParticleSpawner)))
104                    particlespawner_ = object;
105                   
106            }
107 
108        }
109       
110
111
112
113
114
115        if (firePressed_ == false) {
116             gravityAcceleration_ = 350.0;
117
118        }
119
120        if (hasLocalController())
121        {
122          Vector3 velocity = getVelocity();
123          Vector3 position = getPosition();
124
125
126          if (position.z < -100)
127            dead_ = true;
128
129          if (dead_) {
130            velocity.x = 0;
131            velocity.z = 0;
132            setVelocity(velocity);
133            return;
134        }
135
136
137        int maxvelocity_x = 100;
138        int speedAddedPerTick = 5;
139        int camMaxOffset = 25;
140
141        timeSinceLastFire_ += dt;
142        lastSpeed_z = velocity.z;
143
144
145
146        //Handle the rocket fire from the jetpack
147        if (velocity.z > 40)
148            particlespawner_->setVisible(true); 
149        else
150            particlespawner_->setVisible(false); 
151
152        //If player hits space and does not move in z-dir
153        if (firePressed_ && isColliding_ && std::abs(velocity.z) < 0.1 && std::abs(lastSpeed_z) < 0.1) {
154            gravityAcceleration_ = 100.0;
155            velocity.z = 110; //150
156        }
157
158      // rotate(1,getOrientation()* WorldEntity::FRONT)
159
160
161        //Left-right movement with acceleration
162        float rot = getOrientation().getRoll().valueDegrees();
163        if (moveRightPressed_) {
164            if (rot < 0.0)
165                    setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() + dt*Radian(6));
166
167            if (std::abs(velocity.x) < maxvelocity_x) {
168                velocity.x += speedAddedPerTick;
169
170               
171
172               
173
174                // if (pitch_ > 0.0) {
175                //     pitch -= turn_fac*dt);
176                // }
177            }
178        } else if (moveLeftPressed_) {
179            if (rot >= 0.0)
180                    setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() + dt*Radian(6));
181
182            if (std::abs(velocity.x) < maxvelocity_x) {
183                velocity.x -= speedAddedPerTick;
184            }
185        } else {
186            velocity.x /= 1.1;
187        }
188
189
190        velocity.z -= gravityAcceleration_*dt;
191        setVelocity(velocity);
192
193
194        //Camera operation
195        Camera* cam = getCamera();
196        Vector3 campos = cam->getPosition();
197
198        if (campos.x + camMaxOffset < position.x) {
199            campos.x = position.x - camMaxOffset;
200            cam->setPosition(campos);
201        }
202           if (campos.x - camMaxOffset > position.x) {
203            campos.x = position.x + camMaxOffset;
204            cam->setPosition(campos);
205        }
206
207
208
209
210    }
211
212        // Move through the left and right screen boundaries
213
214        //setPosition(position);
215
216        // Reset key variables
217    moveUpPressed_ = false;
218    moveDownPressed_ = false;
219    moveLeftPressed_ = false;
220    moveRightPressed_ = false;
221    moveDownPressed_ = false;
222    isColliding_ = false;
223
224}
225
226
227
228
229
230
231void SOBFigure::moveFrontBack(const Vector2& value)
232{
233    if (value.x > 0)
234    {
235        moveUpPressed_ = true;
236        moveDownPressed_ = false;
237    }
238    else
239    {
240        moveUpPressed_ = false;
241        moveDownPressed_ = true;
242    }
243}
244
245void SOBFigure::moveRightLeft(const Vector2& value)
246{
247    if (value.x > 0)
248    {
249        moveLeftPressed_ = false;
250        moveRightPressed_ = true;
251    }
252    else
253    {
254        moveLeftPressed_ = true;
255        moveRightPressed_ = false;
256    }
257}
258
259
260
261
262
263void SOBFigure::boost(bool boost)
264{
265    firePressed_ = boost;
266}
267}
Note: See TracBrowser for help on using the repository browser.