- Timestamp:
- Nov 6, 2017, 4:06:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc
r11528 r11541 18 18 { 19 19 RegisterObject(AsteroidsShip); 20 /*radius = 20;21 x = getPosition().x;22 y = getPosition().y;23 dx = 3.0f;24 dy = 3.0f;25 angle= 0.0f;*/26 20 27 speed = 830; 21 angle= 0.0f; 22 23 24 28 25 isFireing = false; 29 damping = 10;26 damping = 0.90; 30 27 31 28 lastTimeFront = 0; 32 29 lastTimeLeft = 0; 33 30 lastTime = 0; 31 32 height = this->getGame()->center_->getFieldHeight(); 33 width = this->getGame()->center_->getFieldWidth(); 34 35 force.x =0; 36 force.y =0; 37 38 velocity.x = 0; 39 velocity.y = 0; 34 40 35 41 } … … 47 53 void AsteroidsShip::tick(float dt) 48 54 { 49 / *Movement computation55 //Movement computation beachte Beschleunigung? 50 56 Vector3 pos = getPosition(); 51 57 52 dx *= damping; 53 dy *= damping; 54 55 float speed = sqrt(dx*dx+ dy*dy); 58 float speed = sqrt(velocity.x*velocity.x+ velocity.y*velocity.y); 56 59 if(speed > maxspeed) 57 60 { 58 dx *= maxspeed/speed;59 dy *= mayspeed/speed;61 velocity.x *= maxspeed/speed; 62 velocity.y *= mayspeed/speed; 60 63 } 61 64 62 x += dx;63 y += dy;65 pos.x += velocity.x*dt; 66 pos.y += velocity.y*dt; 64 67 65 if(x>W) x=0;66 if(x<0) x=W;67 if(y>H) y=0;68 if(y<0) y=H;69 setPosition(x,y,0);70 68 71 //roll? muss sich das Raumschiff drehen? 72 setOrientation(angle, x, y, 0); 69 //haelt ship innerhalb des Kamerafensters 70 if(x>width) x=0; 71 if(x<0) x=width; 72 if(y>height) y=0; 73 if(y<0) y=height); 74 73 75 74 76 //Schiessen wenn geschossen wurde 75 77 // shoot! 78 /* 76 79 if (isFireing) 77 80 ControllableEntity::fire(0); 78 79 //Leben verloren */ 80 Vector3 pos = getPosition(); 81 82 //Movement calculation 83 lastTimeFront += dt * damping; 84 lastTimeLeft += dt * damping; 85 lastTime += dt; 86 87 velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); 88 velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); 81 */ 89 82 90 83 //Execute movement 91 84 if (this->hasLocalController()) 92 85 { 93 float dist_y = velocity.y * dt; 94 //float dist_x = velocity.x * dt; 95 if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6) 96 posforeward += dist_y; 97 else 98 { 99 velocity.y = 0; 100 // restart if game ended 101 /* 102 if (getGame()) 103 if (getGame()->bEndGame) 104 { 105 getGame()->start(); 106 return; 107 }*/ 108 } 109 110 pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt; 86 force.x += 1; 87 force.y += 1; 111 88 112 89 } … … 118 95 if (camera != nullptr) 119 96 { 120 // camera->setPosition(Vector3(-pos.z, -posforeward, 0));121 camera->setOrientation(Vector3::UNIT_Z, Degree( 0));97 camera->setPosition(Vector3(0,cameradistance, 0)); 98 camera->setOrientation(Vector3::UNIT_Z, Degree(90)); 122 99 } 123 100 … … 130 107 } 131 108 109 velocity.x *= damping; 110 velocity.y *= damping; 111 132 112 setPosition(pos); 133 113 setOrientation(Vector3::UNIT_Y, Degree(270)); 134 114 135 115 SUPER(AsteroidsShip, tick, dt); 116 136 117 } 137 118 138 119 void AsteroidsShip::moveFrontBack(const Vector2& value) 139 120 { 140 141 121 velocity.x += 1; 142 122 } 143 123 144 void AsteroidsShip::move FrontBack(const Vector2& value)124 void AsteroidsShip::moveUpDown(const Vector2& value) 145 125 { 126 velocity.y +=1; 146 127 147 128 } 148 void AsteroidsShip::moveFront Back(const Vector2& value)129 void AsteroidsShip::moveFrontLeftRight(const Vector2& value) 149 130 { 150 131
Note: See TracChangeset
for help on using the changeset viewer.