[11836] | 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: |
---|
[11998] | 23 | * Sebastian Hirsch |
---|
| 24 | * Robin Jacobs |
---|
| 25 | * Co-authors: |
---|
[11836] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
[11838] | 30 | @file OrxyRoadShip.cc |
---|
| 31 | @brief Implementation of the OrxyRoadShip class. |
---|
[11836] | 32 | */ |
---|
| 33 | |
---|
[11838] | 34 | #include "OrxyRoadShip.h" |
---|
[11836] | 35 | #include "core/CoreIncludes.h" |
---|
| 36 | |
---|
| 37 | namespace orxonox |
---|
| 38 | { |
---|
[11838] | 39 | RegisterClass(OrxyRoadShip); |
---|
[11836] | 40 | |
---|
[11838] | 41 | OrxyRoadShip::OrxyRoadShip(Context* context) : SpaceShip(context) |
---|
[11836] | 42 | { |
---|
[11838] | 43 | RegisterObject(OrxyRoadShip); |
---|
[11836] | 44 | |
---|
| 45 | speed = 830; |
---|
| 46 | isFireing = false; |
---|
| 47 | damping = 10; |
---|
| 48 | |
---|
| 49 | // not sure if has to be zero? |
---|
| 50 | lastTimeFront = 0; |
---|
| 51 | lastTimeLeft = 0; |
---|
| 52 | lastTime = 0; |
---|
[11908] | 53 | steeredLeft = false; |
---|
| 54 | steeredRight = false; |
---|
| 55 | forward = false; |
---|
| 56 | backward = false; |
---|
[11836] | 57 | } |
---|
| 58 | |
---|
[11838] | 59 | void OrxyRoadShip::tick(float dt) |
---|
[11836] | 60 | { |
---|
[11908] | 61 | //orxout(user_info) << "This is some cool output!" << endl; |
---|
[11899] | 62 | |
---|
[11836] | 63 | Vector3 pos = getPosition(); |
---|
[11996] | 64 | //Vector3 pos1 = getPosition(); |
---|
[11836] | 65 | |
---|
| 66 | //Movement calculation |
---|
| 67 | lastTimeFront += dt * damping; |
---|
| 68 | lastTimeLeft += dt * damping; |
---|
| 69 | lastTime += dt; |
---|
| 70 | |
---|
[11908] | 71 | |
---|
| 72 | //velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); |
---|
| 73 | //velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); |
---|
[11836] | 74 | |
---|
| 75 | //Execute movement |
---|
[11908] | 76 | |
---|
[11836] | 77 | if (this->hasLocalController()) |
---|
| 78 | { |
---|
[11996] | 79 | //float dist_y = velocity.y * dt; |
---|
[11908] | 80 | //forward backwards movement |
---|
| 81 | if(forward){ |
---|
[11996] | 82 | if(velocity.y < 300){// Limit for max velocity |
---|
| 83 | velocity.y += 30; |
---|
[11972] | 84 | forward = false; |
---|
[11908] | 85 | } |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | }else if(backward){ |
---|
| 89 | if(velocity.y > 10){ |
---|
[11996] | 90 | velocity.y -= 30; |
---|
[11908] | 91 | }else { |
---|
| 92 | velocity.y = 0; // Prevent players from going backwards |
---|
| 93 | } |
---|
[11972] | 94 | backward = false; |
---|
[11908] | 95 | |
---|
| 96 | }else { |
---|
| 97 | velocity.y = 0.9 * velocity.y;//reduce speed |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | |
---|
[11836] | 103 | //float dist_x = velocity.x * dt; |
---|
[11908] | 104 | //if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6) |
---|
| 105 | // posforeward += dist_y; |
---|
| 106 | //else |
---|
| 107 | //{ |
---|
| 108 | //velocity.y = 0; |
---|
[11836] | 109 | // restart if game ended |
---|
| 110 | /* |
---|
| 111 | if (getGame()) |
---|
| 112 | if (getGame()->bEndGame) |
---|
| 113 | { |
---|
| 114 | getGame()->start(); |
---|
| 115 | return; |
---|
| 116 | }*/ |
---|
[11908] | 117 | //} |
---|
| 118 | |
---|
| 119 | //Left right steering |
---|
| 120 | |
---|
[11996] | 121 | if(!steeredLeft&&!steeredRight){ |
---|
| 122 | velocity.x = velocity.x *0.8; |
---|
| 123 | } |
---|
[11908] | 124 | |
---|
| 125 | if(steeredLeft){ |
---|
[11996] | 126 | steeredLeft = false; |
---|
| 127 | if(velocity.x<100){//if(!forward) Experimental for only allowing steering left and right when |
---|
| 128 | velocity.x += 6; |
---|
[11972] | 129 | steeredLeft = false; |
---|
[11996] | 130 | } |
---|
[11908] | 131 | |
---|
[11981] | 132 | }else if(steeredRight) { |
---|
[11996] | 133 | steeredRight = false; |
---|
| 134 | if(velocity.x>-100){ |
---|
| 135 | velocity.x += -6; |
---|
[11972] | 136 | steeredRight = false; |
---|
[11996] | 137 | } |
---|
[11908] | 138 | }else { |
---|
| 139 | if(velocity.x < -2 || velocity.x > 2 ){ |
---|
| 140 | velocity.x = velocity.x *0.9; |
---|
| 141 | }else{ |
---|
| 142 | velocity.x += 0; |
---|
| 143 | } |
---|
| 144 | |
---|
[11836] | 145 | } |
---|
| 146 | |
---|
[11908] | 147 | pos += Vector3(velocity.y, 0, velocity.x) * dt; |
---|
| 148 | |
---|
[11836] | 149 | } |
---|
| 150 | |
---|
| 151 | |
---|
[11908] | 152 | |
---|
[11836] | 153 | // Camera |
---|
| 154 | Camera* camera = this->getCamera(); |
---|
| 155 | if (camera != nullptr) |
---|
| 156 | { |
---|
[11934] | 157 | camera->setPosition(Vector3(0 ,50,50)); // try to get side/top view |
---|
[11908] | 158 | //camera->setOrientation(Vector3(-1,-1,0), Degree(45)); |
---|
| 159 | //camera->setOrientation(Vector3(-1,-1,-1), Degree(0)); |
---|
| 160 | camera->setOrientation(Vector3::UNIT_Z, Degree(0)); |
---|
[11836] | 161 | } |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | // bring back on track! |
---|
| 166 | if(pos.y != 0) |
---|
| 167 | { |
---|
| 168 | pos.y = 0; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | setPosition(pos); |
---|
| 172 | setOrientation(Vector3::UNIT_Y, Degree(270)); |
---|
| 173 | |
---|
| 174 | // Level up! |
---|
| 175 | if (pos.x > 42000) |
---|
| 176 | { |
---|
| 177 | updateLevel(); |
---|
| 178 | setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0) |
---|
| 179 | } |
---|
| 180 | |
---|
[11838] | 181 | SUPER(OrxyRoadShip, tick, dt); |
---|
[11836] | 182 | } |
---|
| 183 | |
---|
[11838] | 184 | void OrxyRoadShip::updateLevel() |
---|
[11836] | 185 | { |
---|
| 186 | lastTime = 0; |
---|
| 187 | if (getGame()) |
---|
| 188 | getGame()->levelUp(); |
---|
| 189 | } |
---|
| 190 | |
---|
[11838] | 191 | void OrxyRoadShip::moveFrontBack(const Vector2& value) |
---|
[11836] | 192 | { |
---|
[11908] | 193 | this->steering_.z -= value.x ; |
---|
| 194 | if(value.x > 0){ |
---|
| 195 | forward = true; |
---|
| 196 | backward = false; |
---|
| 197 | }else if(value.x < 0){ |
---|
| 198 | forward = false; |
---|
| 199 | backward = true; |
---|
| 200 | } |
---|
| 201 | |
---|
[11836] | 202 | //lastTimeFront = 0; |
---|
| 203 | //desiredVelocity.y = value.y * speed * 42; |
---|
| 204 | |
---|
| 205 | } |
---|
| 206 | |
---|
[11838] | 207 | void OrxyRoadShip::moveRightLeft(const Vector2& value) |
---|
[11836] | 208 | { |
---|
[11908] | 209 | this->steering_.x += value.x; |
---|
| 210 | if(value.x==-1){ |
---|
| 211 | steeredLeft = false; |
---|
| 212 | steeredRight = true; |
---|
[11935] | 213 | //orxout(user_info) << "Steering RIGHT "<<steering_.x << endl; |
---|
[11908] | 214 | }else { |
---|
| 215 | steeredRight = false; |
---|
| 216 | steeredLeft = true; |
---|
[11935] | 217 | //orxout(user_info) << "Steering LEFT "<<steering_.x << endl; |
---|
[11908] | 218 | |
---|
[11972] | 219 | } |
---|
[11908] | 220 | |
---|
| 221 | //lastTimeLeft = 0; |
---|
| 222 | //desiredVelocity.x = value.x * speed; |
---|
[11836] | 223 | } |
---|
[11838] | 224 | void OrxyRoadShip::boost(bool bBoost) |
---|
[11836] | 225 | { |
---|
[11908] | 226 | //bool boosting = bBoost; |
---|
[11836] | 227 | } |
---|
| 228 | |
---|
[11838] | 229 | inline bool OrxyRoadShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) |
---|
[11836] | 230 | { |
---|
| 231 | |
---|
| 232 | removeHealth(100); |
---|
| 233 | this->death(); |
---|
| 234 | return false; |
---|
| 235 | } |
---|
| 236 | |
---|
[11838] | 237 | OrxyRoad* OrxyRoadShip::getGame() |
---|
[11836] | 238 | { |
---|
| 239 | if (game == nullptr) |
---|
| 240 | { |
---|
[11838] | 241 | for (OrxyRoad* race : ObjectList<OrxyRoad>()) |
---|
[11836] | 242 | { |
---|
| 243 | game = race; |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | return game; |
---|
| 247 | } |
---|
| 248 | |
---|
[11838] | 249 | void OrxyRoadShip::death() |
---|
[11836] | 250 | { |
---|
| 251 | getGame()->costLife(); |
---|
| 252 | SpaceShip::death(); |
---|
| 253 | } |
---|
| 254 | } |
---|