[11503] | 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 | * Florian Zinggeler |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file FlappyOrxShip.cc |
---|
| 31 | @brief Implementation of the FlappyOrxShip class. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "FlappyOrxShip.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/XMLPort.h" |
---|
| 38 | #include "FlappyOrx.h" |
---|
| 39 | #include "graphics/Camera.h" |
---|
| 40 | #include "weapons/projectiles/Projectile.h" |
---|
[11505] | 41 | #include <math.h> |
---|
[11503] | 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
| 45 | RegisterClass(FlappyOrxShip); |
---|
| 46 | |
---|
| 47 | FlappyOrxShip::FlappyOrxShip(Context* context) : SpaceShip(context) |
---|
| 48 | { |
---|
| 49 | RegisterObject(FlappyOrxShip); |
---|
| 50 | |
---|
[11514] | 51 | this->UpwardThrust = 1; |
---|
[11521] | 52 | this->speed = 1; |
---|
[11514] | 53 | this->gravity = 1; |
---|
[11565] | 54 | isDead = true; |
---|
[11514] | 55 | |
---|
| 56 | } |
---|
[11554] | 57 | |
---|
| 58 | |
---|
[11514] | 59 | void FlappyOrxShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[11509] | 60 | { |
---|
[11514] | 61 | SUPER(FlappyOrxShip, XMLPort, xmlelement, mode); |
---|
[11509] | 62 | XMLPortParam(FlappyOrxShip, "speed", setSpeed, getSpeed, xmlelement, mode); |
---|
| 63 | XMLPortParam(FlappyOrxShip, "UpwardThrust", setUpwardThrust, getUpwardThrust, xmlelement, mode); |
---|
| 64 | XMLPortParam(FlappyOrxShip, "gravity", setGravity, getGravity, xmlelement, mode); |
---|
[11503] | 65 | } |
---|
[11514] | 66 | |
---|
[11503] | 67 | void FlappyOrxShip::tick(float dt) |
---|
[11514] | 68 | { |
---|
| 69 | SUPER(FlappyOrxShip, tick, dt); |
---|
| 70 | //Execute movement |
---|
[11566] | 71 | if (this->hasLocalController()) |
---|
[11503] | 72 | { |
---|
[11521] | 73 | if(getHealth()<0){ |
---|
[11543] | 74 | setHealth(1); |
---|
| 75 | getGame()->death(); |
---|
| 76 | death(); |
---|
[11521] | 77 | } |
---|
[11503] | 78 | Vector3 pos = getPosition(); |
---|
[11529] | 79 | |
---|
| 80 | getGame()->updatePlayerPos(pos.x); |
---|
| 81 | |
---|
| 82 | |
---|
[11566] | 83 | if(not isDead){ |
---|
| 84 | velocity.y += gravity*dt; |
---|
| 85 | if(isFlapping){ |
---|
| 86 | isFlapping = false; |
---|
| 87 | if(pos.z > -150) |
---|
| 88 | velocity.y = -UpwardThrust; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | pos += Vector3(speed + velocity.x, 0, velocity.y) * dt; |
---|
[11503] | 92 | } |
---|
| 93 | |
---|
[11566] | 94 | |
---|
[11503] | 95 | // Camera |
---|
| 96 | Camera* camera = this->getCamera(); |
---|
| 97 | if (camera != nullptr) |
---|
| 98 | { |
---|
[11543] | 99 | //camera->setPosition(Vector3(-pos.z, -pos.y, 0)); |
---|
| 100 | camera->setPosition(pos.x,-100,0); |
---|
| 101 | camera->setOrientation(Vector3::UNIT_Z, Degree(0)); |
---|
| 102 | |
---|
[11503] | 103 | } |
---|
| 104 | |
---|
[11529] | 105 | |
---|
[11503] | 106 | setPosition(pos); |
---|
[11543] | 107 | setOrientation(Vector3::UNIT_Y, Degree(270-velocity.y/10)); |
---|
| 108 | |
---|
| 109 | if(pos.z > 150){ |
---|
| 110 | getGame()->death(); |
---|
| 111 | death(); |
---|
| 112 | } |
---|
[11503] | 113 | |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | void FlappyOrxShip::updateLevel() |
---|
| 118 | { |
---|
| 119 | if (getGame()) |
---|
| 120 | getGame()->levelUp(); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | void FlappyOrxShip::moveFrontBack(const Vector2& value) |
---|
| 124 | { |
---|
| 125 | |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | void FlappyOrxShip::moveRightLeft(const Vector2& value){} |
---|
| 129 | |
---|
| 130 | void FlappyOrxShip::boost(bool boost){ |
---|
[11565] | 131 | if(isDead){ |
---|
| 132 | isDead = false; |
---|
| 133 | getGame()->bIsDead = false; |
---|
| 134 | } |
---|
[11503] | 135 | isFlapping=boost; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | void FlappyOrxShip::rotateRoll(const Vector2& value) |
---|
| 139 | { |
---|
| 140 | if (getGame()) |
---|
| 141 | if (getGame()->bEndGame) |
---|
| 142 | getGame()->end(); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | FlappyOrx* FlappyOrxShip::getGame() |
---|
| 146 | { |
---|
| 147 | if (game == nullptr) |
---|
| 148 | { |
---|
| 149 | for (FlappyOrx* flappyOrx : ObjectList<FlappyOrx>()) |
---|
| 150 | game = flappyOrx; |
---|
| 151 | } |
---|
| 152 | return game; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | void FlappyOrxShip::death() |
---|
| 156 | { |
---|
[11566] | 157 | isDead = true; |
---|
[11537] | 158 | Vector3 pos = getPosition(); |
---|
| 159 | pos.x = 0; |
---|
[11543] | 160 | pos.z = 0; |
---|
| 161 | pos.y = 0; |
---|
| 162 | velocity.y = 0; |
---|
[11537] | 163 | setPosition(pos); |
---|
[11543] | 164 | usleep(1000u); |
---|
[11503] | 165 | } |
---|
| 166 | } |
---|