Changeset 11541 for code/branches/Asteroid_HS17/src
- Timestamp:
- Nov 6, 2017, 4:06:54 PM (7 years ago)
- Location:
- code/branches/Asteroid_HS17/src/modules/asteroids
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc
r11528 r11541 69 69 70 70 //spawnt durch den Timer Asteroiden, denk dran, dass falls ein Asteroid stirbt er in 2 teile geteilt wird 71 Asteroids::spawnStone(){ 72 if(getPlayer() == nullptr){ 73 return; 74 } 71 void Asteroids::spawnStone() 72 { 73 if(getPlayer() == nullptr) return; 75 74 76 75 AsteroidsStone* newStone; … … 78 77 newStone->addTemplate("asteroidsstone"); 79 78 newStone->setAsteroidsPlayer(player); 80 }81 82 void Invader::spawnEnemy()83 {84 if (getPlayer() == nullptr)85 return;86 87 for (int i = 0; i < (3*log10(static_cast<double>(level)) + 1); i++)88 {89 InvaderEnemy* newPawn;90 if (rand() % 42/(1 + level*level) == 0)91 {92 newPawn = new InvaderEnemyShooter(this->center_->getContext());93 newPawn->addTemplate("enemyinvadershooter");94 }95 else96 {97 newPawn = new InvaderEnemy(this->center_->getContext());98 newPawn->addTemplate("enemyinvader");99 }100 newPawn->setInvaderPlayer(player);101 newPawn->level = level;102 // spawn enemy at random points in front of player.103 newPawn->setPosition(player->getPosition() + Vector3(500.f + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200));104 }105 79 } 106 80 … … 155 129 { 156 130 lives = 0; 157 }; 131 } 132 158 133 void Asteroids::start() 159 134 { -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsCenterPoint.h
r11528 r11541 60 60 { return Vector2(this->width_, this->height_); } 61 61 62 float getFieldWidth() const 63 {return this->width_;} 64 65 float getFieldHeight() const 66 {return this->height_;} 67 62 68 private: 63 69 void checkGametype(); -
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 -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h
r11528 r11541 72 72 int lives; 73 73 float angle, radius; 74 float speed,damping, posforeward;74 float damping, posforeward; 75 75 bool isFireing; 76 float dx, dy; 77 const float maxspeed = 500; 78 const float cameradistance = 100; 76 79 77 80 //Nachschauen wie gross das Spielfeld ist! 78 float H = 1000; 79 float W = 1000; 81 float height; 82 float width; 83 84 80 85 81 86 protected: … … 88 93 Camera* camera; 89 94 float lastTimeFront, lastTimeLeft, lastTime; 90 struct Ve locity95 struct Vector 91 96 { 92 97 float x; 93 98 float y; 94 } velocity, desiredVelocity;99 }force, velocity 95 100 96 101 }; -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc
r11528 r11541 39 39 #include "util/Math.h" 40 40 41 41 42 namespace orxonox 42 43 { … … 47 48 RegisterObject(AsteroidsStone); 48 49 49 50 51 50 maxspeed = 50.0f; 52 //Random Spawn? pos= random? 51 //Random Spawn? pos= random? -> spawn durch timer in der Asteroids Klasse 53 52 this->setPosition(rnd(0, fieldWidth_), rnd(0, fieldHeigth_), 0); 54 if(r){55 this.r = r*0.5;56 }else{57 this.r = rnd(15, 50);58 }59 53 60 54 //random Geschwindigkeit und Richtung 61 55 velocity.x = rnd(0, maxspeed); 62 56 velocity.y = rnd(0, maxspeed); 57 this->context = context; 63 58 } 59 60 void Asteroids::death() 61 { 62 if(this->size == 1){ 63 Pawn::death(); 64 }else if(this->size == 2){ 65 Pawn::death(); 66 67 //Wie mache ich das ? Eigentlich in der game Klasse? sonst zeigt der Pointer auf einen falschen Bereich 68 69 for(int i = 0; i<2; i++) 70 { 71 AsteroidsStone* newStone; 72 newStone = new AsteroidsStone(this->context); 73 newStone->addTemplate("asteroidsstone"); 74 newStone->setAsteroidsPlayer(player); 75 } 76 77 } 78 } 79 80 64 81 //Bis hier geschrieben 65 82 void AsteroidsStone::tick(float dt) … … 67 84 Vector3 pos = this->getPosition(); 68 85 pos.x += velocity.x*dt; 69 pos.y += velocity.y*dt; 86 pos.z += velocity.y*dt; 87 88 if(pos.y != 0){ 89 pos.y=0; 90 } 70 91 setPosition(pos); 71 92 SUPER(AsteroidsStone, tick, dt); -
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h
r11528 r11541 38 38 39 39 #include "worldentities/Pawn.h" 40 #include "core/object/Context.h" 40 41 41 42 namespace orxonox … … 47 48 virtual void tick(float dt) override; 48 49 49 // Radius of the asteroid50 float r;50 //Es gibt 3 Groessen von Meteroiden gross, mittel, klein, gross ->2 mittleren, mittel -> 2 kleinen, kleine-> verschwinden 51 int size; 51 52 int level; 52 53 virtual void setAsteroidsPlayer(AsteroidsShip* player){this->player = player;} 53 54 55 54 56 protected: 57 58 virtual void death() override; 59 55 60 56 61 //herausfinden->ueber Kamera Einstellung wie bei Pong? … … 59 64 Vector2 velocity; 60 65 float maxspeed; 66 67 private: 68 Context* context; 61 69 }; 62 70 }
Note: See TracChangeset
for help on using the changeset viewer.