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