[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> |
---|
[11595] | 42 | #include <ctime> |
---|
[11503] | 43 | |
---|
| 44 | namespace orxonox |
---|
| 45 | { |
---|
| 46 | RegisterClass(FlappyOrxShip); |
---|
| 47 | |
---|
| 48 | FlappyOrxShip::FlappyOrxShip(Context* context) : SpaceShip(context) |
---|
| 49 | { |
---|
| 50 | RegisterObject(FlappyOrxShip); |
---|
| 51 | |
---|
[11514] | 52 | this->UpwardThrust = 1; |
---|
[11521] | 53 | this->speed = 1; |
---|
[11514] | 54 | this->gravity = 1; |
---|
[11565] | 55 | isDead = true; |
---|
[11595] | 56 | deathTime = 0; |
---|
[11514] | 57 | |
---|
| 58 | } |
---|
[11554] | 59 | |
---|
| 60 | |
---|
[11514] | 61 | void FlappyOrxShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[11509] | 62 | { |
---|
[11514] | 63 | SUPER(FlappyOrxShip, XMLPort, xmlelement, mode); |
---|
[11509] | 64 | XMLPortParam(FlappyOrxShip, "speed", setSpeed, getSpeed, xmlelement, mode); |
---|
| 65 | XMLPortParam(FlappyOrxShip, "UpwardThrust", setUpwardThrust, getUpwardThrust, xmlelement, mode); |
---|
| 66 | XMLPortParam(FlappyOrxShip, "gravity", setGravity, getGravity, xmlelement, mode); |
---|
[11503] | 67 | } |
---|
[11514] | 68 | |
---|
[11503] | 69 | void FlappyOrxShip::tick(float dt) |
---|
[11514] | 70 | { |
---|
| 71 | SUPER(FlappyOrxShip, tick, dt); |
---|
| 72 | //Execute movement |
---|
[11566] | 73 | if (this->hasLocalController()) |
---|
[11503] | 74 | { |
---|
[11521] | 75 | if(getHealth()<0){ |
---|
[11543] | 76 | setHealth(1); |
---|
| 77 | getGame()->death(); |
---|
| 78 | death(); |
---|
[11521] | 79 | } |
---|
[11503] | 80 | Vector3 pos = getPosition(); |
---|
[11529] | 81 | |
---|
| 82 | getGame()->updatePlayerPos(pos.x); |
---|
| 83 | |
---|
| 84 | |
---|
[11566] | 85 | if(not isDead){ |
---|
| 86 | velocity.y += gravity*dt; |
---|
| 87 | if(isFlapping){ |
---|
| 88 | isFlapping = false; |
---|
| 89 | if(pos.z > -150) |
---|
| 90 | velocity.y = -UpwardThrust; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | pos += Vector3(speed + velocity.x, 0, velocity.y) * dt; |
---|
[11503] | 94 | } |
---|
| 95 | |
---|
[11566] | 96 | |
---|
[11503] | 97 | // Camera |
---|
| 98 | Camera* camera = this->getCamera(); |
---|
| 99 | if (camera != nullptr) |
---|
| 100 | { |
---|
[11543] | 101 | //camera->setPosition(Vector3(-pos.z, -pos.y, 0)); |
---|
| 102 | camera->setPosition(pos.x,-100,0); |
---|
| 103 | camera->setOrientation(Vector3::UNIT_Z, Degree(0)); |
---|
| 104 | |
---|
[11503] | 105 | } |
---|
| 106 | |
---|
[11529] | 107 | |
---|
[11503] | 108 | setPosition(pos); |
---|
[11543] | 109 | setOrientation(Vector3::UNIT_Y, Degree(270-velocity.y/10)); |
---|
| 110 | |
---|
| 111 | if(pos.z > 150){ |
---|
| 112 | getGame()->death(); |
---|
| 113 | death(); |
---|
| 114 | } |
---|
[11503] | 115 | |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | void FlappyOrxShip::updateLevel() |
---|
| 120 | { |
---|
| 121 | if (getGame()) |
---|
| 122 | getGame()->levelUp(); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | void FlappyOrxShip::moveFrontBack(const Vector2& value) |
---|
| 126 | { |
---|
| 127 | |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | void FlappyOrxShip::moveRightLeft(const Vector2& value){} |
---|
| 131 | |
---|
[11595] | 132 | int FlappyOrxShip::timeUntilRespawn(){ |
---|
| 133 | return 2-time(0)+deathTime; |
---|
| 134 | } |
---|
| 135 | |
---|
[11503] | 136 | void FlappyOrxShip::boost(bool boost){ |
---|
[11595] | 137 | |
---|
| 138 | |
---|
| 139 | if(isDead&&timeUntilRespawn()<=0){ |
---|
[11565] | 140 | isDead = false; |
---|
[11576] | 141 | getGame()->setDead(false); |
---|
[11565] | 142 | } |
---|
[11503] | 143 | isFlapping=boost; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | void FlappyOrxShip::rotateRoll(const Vector2& value) |
---|
| 147 | { |
---|
| 148 | if (getGame()) |
---|
| 149 | if (getGame()->bEndGame) |
---|
| 150 | getGame()->end(); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | FlappyOrx* FlappyOrxShip::getGame() |
---|
| 154 | { |
---|
| 155 | if (game == nullptr) |
---|
| 156 | { |
---|
| 157 | for (FlappyOrx* flappyOrx : ObjectList<FlappyOrx>()) |
---|
| 158 | game = flappyOrx; |
---|
| 159 | } |
---|
| 160 | return game; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | void FlappyOrxShip::death() |
---|
| 164 | { |
---|
[11566] | 165 | isDead = true; |
---|
[11595] | 166 | |
---|
| 167 | deathTime = time(0); |
---|
| 168 | |
---|
| 169 | orxout()<<"death time: "<<deathTime<<std::endl; |
---|
[11537] | 170 | Vector3 pos = getPosition(); |
---|
| 171 | pos.x = 0; |
---|
[11543] | 172 | pos.z = 0; |
---|
| 173 | pos.y = 0; |
---|
| 174 | velocity.y = 0; |
---|
[11537] | 175 | setPosition(pos); |
---|
[11543] | 176 | usleep(1000u); |
---|
[11503] | 177 | } |
---|
| 178 | } |
---|