Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11392 was 11392, checked in by jkindle, 3 years ago

Lululululululululu

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 *      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
41namespace orxonox
42{
43    RegisterClass(SOBFigure);
44
45    SOBFigure::SOBFigure(Context* context) : ControllableEntity(context)
46    {
47        RegisterObject(SOBFigure);
48
49        // initialize variables
50
51        moveUpPressed_ = false;
52        moveDownPressed_ = false;
53        moveLeftPressed_ = false;
54        moveDownPressed_ = false;
55        firePressed_ = false;
56        timeSinceLastFire_ = 0.0;
57        lastSpeed_z = 0.0;
58
59        gravityAcceleration_ = 250.0;
60        pitch_ = 0.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      // rotate(1,getOrientation()* WorldEntity::FRONT)
104
105        //Left-right movement with acceleration
106        if (moveRightPressed_) {
107            if (std::abs(velocity.x) < maxvelocity_x) {
108                velocity.x += speedAddedPerTick;
109                // if (pitch_ > 0.0) {
110                //     pitch -= turn_fac*dt);
111                // }
112            }
113        } else if (moveLeftPressed_) {
114            if (std::abs(velocity.x) < maxvelocity_x) {
115                velocity.x -= speedAddedPerTick;
116            }
117        } else {
118            velocity.x /= 1.1;
119        }
120
121
122        velocity.z -= gravityAcceleration_*dt;
123        setVelocity(velocity);
124
125
126        //Camera operation
127        Camera* cam = getCamera();
128        Vector3 campos = cam->getPosition();
129
130        if (campos.x + camMaxOffset < position.x) {
131            campos.x = position.x - camMaxOffset;
132            cam->setPosition(campos);
133        }
134           if (campos.x - camMaxOffset > position.x) {
135            campos.x = position.x + camMaxOffset;
136            cam->setPosition(campos);
137        }
138
139
140
141
142    }
143
144        // Move through the left and right screen boundaries
145
146        //setPosition(position);
147
148        // Reset key variables
149    moveUpPressed_ = false;
150    moveDownPressed_ = false;
151    moveLeftPressed_ = false;
152    moveRightPressed_ = false;
153    moveDownPressed_ = false;
154    firePressed_ = false;
155
156}
157
158
159
160
161
162
163void SOBFigure::moveFrontBack(const Vector2& value)
164{
165    if (value.x > 0)
166    {
167        moveUpPressed_ = true;
168        moveDownPressed_ = false;
169    }
170    else
171    {
172        moveUpPressed_ = false;
173        moveDownPressed_ = true;
174    }
175}
176
177void SOBFigure::moveRightLeft(const Vector2& value)
178{
179    if (value.x > 0)
180    {
181        moveLeftPressed_ = false;
182        moveRightPressed_ = true;
183    }
184    else
185    {
186        moveLeftPressed_ = true;
187        moveRightPressed_ = false;
188    }
189}
190
191
192
193
194
195void SOBFigure::boost(bool boost)
196{
197    firePressed_ = true;
198}
199}
Note: See TracBrowser for help on using the repository browser.