- 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/AsteroidsStone.cc
r11506 r11516 32 32 */ 33 33 34 #include "InvaderEnemy.h" 35 34 #include "AsteroidsStone.h" 36 35 #include "core/CoreIncludes.h" 37 #include "Invader.h" 38 #include "InvaderShip.h" 36 #include "Asteroids.h" 37 #include "AsteroidsShip.h" 38 #include <cmath> 39 #include "util/Math.h" 39 40 40 41 namespace orxonox 41 42 { 42 RegisterClass( InvaderEnemy);43 RegisterClass(AsteroidsStone); 43 44 44 InvaderEnemy::InvaderEnemy(Context* context) : Pawn(context)45 AsteroidsStone::AsteroidsStone(Context* context) : MovableEntity(context) 45 46 { 46 RegisterObject(InvaderEnemy); 47 enableCollisionCallback(); 48 lifetime = 0; 47 RegisterObject(AsteroidsStone); 48 49 maxspeed = 50.0f; 50 //Random Spawn? pos= random? 51 this->setPosition(rnd(0, fieldWidth_), rnd(0, fieldHeigth_), 0); 52 if(r){ 53 this.r = r*0.5; 54 }else{ 55 this.r = rnd(15, 50); 56 } 57 58 //random Geschwindigkeit und Richtung 59 velocity.x = rnd(0, maxspeed); 60 velocity.y = rnd(0, maxspeed); 61 } 62 //Bis hier geschrieben 63 void AsteroidsStone::tick(float dt) 64 { 65 Vector3 pos = this->getPosition(); 66 pos.x += velocity.x*dt; 67 pos.y += velocity.y*dt; 68 setPosition(pos); 69 SUPER(AsteroidsStone, tick, dt); 49 70 } 50 71 51 void InvaderEnemy::tick(float dt) 52 { 53 lifetime += dt; 54 // die after 5 seconds. 55 if (lifetime > 5000) 56 removeHealth(2000); 57 58 if (player != nullptr) 59 { 60 float newZ = 2/(pow(std::abs(getPosition().x - player->getPosition().x) * 0.01f, 2) + 1) * (player->getPosition().z - getPosition().z); 61 setVelocity(Vector3(1000.f - level * 100 , 0, newZ)); 62 } 63 SUPER(InvaderEnemy, tick, dt); 64 } 65 66 inline bool InvaderEnemy::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) 72 inline bool AsteroidsStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) 67 73 { 68 74 if(orxonox_cast<InvaderShip*>(otherObject)) … … 71 77 } 72 78 73 Invader* InvaderEnemy::getGame()74 {75 if (game == nullptr)76 {77 for (Invader* invader : ObjectList<Invader>())78 game = invader;79 }80 return game;81 }82 79 83 void InvaderEnemy::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)84 {85 Pawn::damage(damage, healthdamage, shielddamage, originator, cs);86 if (getGame() && orxonox_cast<InvaderShip*>(originator) != nullptr && getHealth() <= 0)87 getGame()->addPoints(42);88 }89 80 }
Note: See TracChangeset
for help on using the changeset viewer.