Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Added movement of camera.

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 *      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
41
42namespace orxonox
43{
44    RegisterClass(SOBFigure);
45
46    SOBFigure::SOBFigure(Context* context) : ControllableEntity(context)
47    {
48        RegisterObject(SOBFigure);
49
50        // initialize variables
51
52        moveUpPressed_ = false;
53        moveDownPressed_ = false;
54        moveLeftPressed_ = false;
55        moveDownPressed_ = false;
56        firePressed_ = false;
57        timeSinceLastFire_ = 0.0;
58        lastSpeed_z = 0.0;
59
60        gravityAcceleration_ = 250.0;//8.0
61
62        dead_ = false;
63        setAngularFactor(0.0);
64    }
65
66    void SOBFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode)
67    {
68        SUPER(SOBFigure, XMLPort, xmlelement, mode);
69
70    }
71
72    void SOBFigure::tick(float dt)
73    {
74        SUPER(SOBFigure, tick, dt);
75
76        if (hasLocalController())
77        {
78          Vector3 velocity = getVelocity();
79          Vector3 position = getPosition();
80
81          if (dead_) {
82            velocity.x = 0;
83            velocity.z = 0;
84            setVelocity(velocity);
85            return;
86        }
87
88
89        int maxvelocity_x = 100;
90        int speedAddedPerTick = 5;
91        int camMaxOffset = 25;
92
93        timeSinceLastFire_ += dt;
94        lastSpeed_z = velocity.z;
95
96
97
98        //If player hits space and does not move in z-dir
99        if (firePressed_ && std::abs(velocity.z) < 0.07 && std::abs(lastSpeed_z) < 0.07) {
100            velocity.z = 150;
101        } 
102
103        //Left-right movement with acceleration
104        if (moveRightPressed_) {
105            if (std::abs(velocity.x) < maxvelocity_x) {
106                velocity.x += speedAddedPerTick;
107            }
108        } else if (moveLeftPressed_) {
109            if (std::abs(velocity.x) < maxvelocity_x) {
110                velocity.x -= speedAddedPerTick;
111            }
112        } else {
113            velocity.x /= 1.1;
114        } 
115       
116
117        velocity.z -= gravityAcceleration_*dt;
118        setVelocity(velocity);
119
120
121        //Camera operation
122        Camera* cam = getCamera();
123        Vector3 campos = cam->getPosition();
124
125        if (campos.x + camMaxOffset < position.x) {
126            campos.x = position.x - camMaxOffset;
127            cam->setPosition(campos);
128        }
129           if (campos.x - camMaxOffset > position.x) {
130            campos.x = position.x + camMaxOffset;
131            cam->setPosition(campos);
132        }
133
134
135
136    }
137
138        // Move through the left and right screen boundaries
139
140        //setPosition(position);
141
142        // Reset key variables
143    moveUpPressed_ = false;
144    moveDownPressed_ = false;
145    moveLeftPressed_ = false;
146    moveRightPressed_ = false;
147    moveDownPressed_ = false;
148    firePressed_ = false;
149
150}
151
152
153
154
155
156   /* void SOBFigure::CollisionWithEnemy(SOBEnemy* enemy)
157    {
158        if (rocketActive_ == nullptr && propellerActive_ == nullptr && shieldActive_ == nullptr)
159        {
160            dead_ = true;
161        }
162    }*/
163
164
165
166
167
168
169void SOBFigure::moveFrontBack(const Vector2& value)
170{
171    if (value.x > 0)
172    {
173        moveUpPressed_ = true;
174        moveDownPressed_ = false;
175    }
176    else
177    {
178        moveUpPressed_ = false;
179        moveDownPressed_ = true;
180    }
181}
182
183void SOBFigure::moveRightLeft(const Vector2& value)
184{
185    if (value.x > 0)
186    {
187        moveLeftPressed_ = false;
188        moveRightPressed_ = true;
189    }
190    else
191    {
192        moveLeftPressed_ = true;
193        moveRightPressed_ = false;
194    }
195}
196
197
198
199
200
201void SOBFigure::boost(bool boost)
202{
203    firePressed_ = true;
204}
205}
Note: See TracBrowser for help on using the repository browser.