- Timestamp:
- Oct 30, 2017, 4:04:29 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc
r11506 r11516 3 3 #include "core/CoreIncludes.h" 4 4 #include "core/XMLPort.h" 5 #include "Invader.h" 6 #include "InvaderEnemy.h" 5 #include "Asteroids.h" 7 6 #include "graphics/Camera.h" 7 #include "asteroids/AsteroidStone" 8 8 #include "weapons/projectiles/Projectile.h" 9 9 10 10 11 namespace orxonox … … 16 17 { 17 18 RegisterObject(AsteroidsShip); 19 /*radius = 20; 20 x = getPosition().x; 21 y = getPosition().y; 22 dx = 3.0f; 23 dy = 3.0f; 24 angle= 0.0f;*/ 18 25 19 float x = getPosition().x; 20 float y = getPosition().y; 21 float velocityx = 0.0f; 22 float velocityy = 0.0f; 23 this->bBoost_ = false; 26 speed = 830; 27 isFireing = false; 28 damping = 10; 29 30 lastTimeFront = 0; 31 lastTimeLeft = 0; 32 lastTime = 0; 33 24 34 } 35 25 36 //Destructor 26 37 AsteroidsShip::~AsteroidsShip() … … 35 46 void AsteroidsShip::tick(float dt) 36 47 { 37 //Movement computation 38 Vector3 speed = Vector3 (100, 100, 0); 39 Vector3 position = this->getPosition(); 40 position += (speed * dt); 41 this->setPosition(position); 48 /*Movement computation 49 Vector3 pos = getPosition(); 50 51 dx *= damping; 52 dy *= damping; 53 54 float speed = sqrt(dx*dx+ dy*dy); 55 if(speed > maxspeed) 56 { 57 dx *= maxspeed/speed; 58 dy *= mayspeed/speed; 59 } 60 61 x += dx; 62 y += dy; 63 64 if(x>W) x=0; 65 if(x<0) x=W; 66 if(y>H) y=0; 67 if(y<0) y=H; 68 setPosition(x,y,0); 69 42 70 //roll? muss sich das Raumschiff drehen? 71 setOrientation(angle, x, y, 0); 43 72 44 73 //Schiessen wenn geschossen wurde … … 47 76 ControllableEntity::fire(0); 48 77 49 //Leben verloren 78 //Leben verloren */ 79 Vector3 pos = getPosition(); 80 81 //Movement calculation 82 lastTimeFront += dt * damping; 83 lastTimeLeft += dt * damping; 84 lastTime += dt; 85 86 velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); 87 velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); 88 89 //Execute movement 90 if (this->hasLocalController()) 91 { 92 float dist_y = velocity.y * dt; 93 //float dist_x = velocity.x * dt; 94 if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6) 95 posforeward += dist_y; 96 else 97 { 98 velocity.y = 0; 99 // restart if game ended 100 /* 101 if (getGame()) 102 if (getGame()->bEndGame) 103 { 104 getGame()->start(); 105 return; 106 }*/ 107 } 108 109 pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt; 110 } 111 112 113 // Camera 114 Camera* camera = this->getCamera(); 115 if (camera != nullptr) 116 { 117 // camera->setPosition(Vector3(-pos.z, -posforeward, 0)); 118 camera->setOrientation(Vector3::UNIT_Z, Degree(0)); 119 } 120 121 122 123 // bring back on track! 124 if(pos.y != 0) 125 { 126 pos.y = 0; 127 } 128 129 setPosition(pos); 130 setOrientation(Vector3::UNIT_Y, Degree(270)); 131 132 SUPER(AsteroidsShip, tick, dt); 50 133 } 51 134 52 void 135 Asteroids* AsteroidsShip::getGame() 136 { 137 if (game == nullptr) 138 { 139 for (Asteroids* asteroids : ObjectList<Asteroids>()) 140 game = asteroids; 141 } 142 return game; 143 } 53 144 145 void InvaderShip::death() 146 { 147 getGame()->costLife(); 148 SpaceShip::death(); 149 } 54 150 55 151
Note: See TracChangeset
for help on using the changeset viewer.