[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 | |
---|
| 51 | UpwardThrust = 250; |
---|
[11509] | 52 | speed = 50; |
---|
[11503] | 53 | gravity = 20; |
---|
[11509] | 54 | void AutonomousDrone::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 55 | { |
---|
| 56 | SUPER(AutonomousDrone, XMLPort, xmlelement, mode); |
---|
| 57 | XMLPortParam(FlappyOrxShip, "speed", setSpeed, getSpeed, xmlelement, mode); |
---|
| 58 | XMLPortParam(FlappyOrxShip, "UpwardThrust", setUpwardThrust, getUpwardThrust, xmlelement, mode); |
---|
| 59 | XMLPortParam(FlappyOrxShip, "gravity", setGravity, getGravity, xmlelement, mode); |
---|
| 60 | } |
---|
[11503] | 61 | } |
---|
| 62 | void FlappyOrxShip::tick(float dt) |
---|
| 63 | { //Execute movement |
---|
| 64 | if (this->hasLocalController()) |
---|
| 65 | { |
---|
| 66 | |
---|
| 67 | Vector3 pos = getPosition(); |
---|
| 68 | velocity.y += gravity; |
---|
| 69 | if(isFlapping){ |
---|
| 70 | isFlapping = false; |
---|
| 71 | velocity.y = -UpwardThrust; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | pos += Vector3(speed + velocity.x, 0, velocity.y) * dt; |
---|
| 76 | |
---|
| 77 | if(pos.z < -150 || pos.z > 150){ |
---|
| 78 | pos.z=0; |
---|
| 79 | velocity.y = 0; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | // restart if game ended |
---|
| 83 | if (getGame()) |
---|
| 84 | if (getGame()->bEndGame) |
---|
| 85 | { |
---|
| 86 | getGame()->start(); |
---|
| 87 | return; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | // Camera |
---|
| 91 | Camera* camera = this->getCamera(); |
---|
| 92 | if (camera != nullptr) |
---|
| 93 | { |
---|
| 94 | camera->setPosition(Vector3(-pos.z, -pos.y, 0)); |
---|
| 95 | camera->setOrientation(Vector3::UNIT_Z, Degree(90)); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | setPosition(pos); |
---|
| 99 | setOrientation(Vector3::UNIT_Y, Degree(270)); |
---|
| 100 | |
---|
| 101 | } |
---|
| 102 | |
---|
[11509] | 103 | |
---|
[11503] | 104 | SUPER(FlappyOrxShip, tick, dt); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void FlappyOrxShip::updateLevel() |
---|
| 108 | { |
---|
| 109 | if (getGame()) |
---|
| 110 | getGame()->levelUp(); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | void FlappyOrxShip::moveFrontBack(const Vector2& value) |
---|
| 114 | { |
---|
| 115 | |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | void FlappyOrxShip::moveRightLeft(const Vector2& value){} |
---|
| 119 | |
---|
| 120 | void FlappyOrxShip::boost(bool boost){ |
---|
| 121 | isFlapping=boost; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | void FlappyOrxShip::rotateRoll(const Vector2& value) |
---|
| 125 | { |
---|
| 126 | if (getGame()) |
---|
| 127 | if (getGame()->bEndGame) |
---|
| 128 | getGame()->end(); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | FlappyOrx* FlappyOrxShip::getGame() |
---|
| 132 | { |
---|
| 133 | if (game == nullptr) |
---|
| 134 | { |
---|
| 135 | for (FlappyOrx* flappyOrx : ObjectList<FlappyOrx>()) |
---|
| 136 | game = flappyOrx; |
---|
| 137 | } |
---|
| 138 | return game; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | void FlappyOrxShip::death() |
---|
| 142 | { |
---|
| 143 | |
---|
| 144 | } |
---|
| 145 | } |
---|