- Timestamp:
- Dec 4, 2017, 4:17:43 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DStone.cc
r11616 r11637 44 44 { 45 45 RegisterObject(Asteroids2DStone); 46 this->size = 1;46 this->size = rand()%3+1; 47 47 this->width = 1043; 48 48 this->height = 646; 49 49 this->setPosition(randomPosition(this->width, this->height)); 50 this->setCollisionTypeStr("dynamic"); 51 this->setVelocity(randomVelocity(MAX_SPEED)); 52 } 53 54 Asteroids2DStone::Asteroids2DStone(Context* c, int sze, Vector3 pos) : Pawn(c) 55 { 56 RegisterObject(Asteroids2DStone); 57 this->size = sze; 58 this->width = 1043; 59 this->height = 646; 60 this->setPosition(pos); 61 this->setCollisionTypeStr("dynamic"); 50 62 this->setVelocity(randomVelocity(MAX_SPEED)); 51 63 } … … 74 86 SUPER(Asteroids2DStone, tick, dt); 75 87 Vector3 pos = this->getPosition(); 76 if(pos.x >= width/2 || pos.x <= -width/2 || pos.z >= height/2 || pos.z <= -height/2) 77 { 78 Quaternion orientation = this->getOrientation(); 79 orientation.w -= 180; 80 this->setOrientation(Vector3::UNIT_Y, Degree(orientation.w)); 88 89 if(pos.x >= width/2){ 90 pos.x = -width/2; 91 }else if(pos.x <= -width/2){ 92 pos.x = -width/2; 93 }else if(pos.z >= height/2){ 94 pos.z = -height/2; 95 }else if(pos.z <= -height/2){ 96 pos.z = -width/2; 81 97 } 82 98 99 this->setPosition(pos); 100 83 101 } 102 103 inline bool Asteroids2DStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) 104 { 105 if(orxonox_cast<Asteroids2DShip*>(otherObject)) 106 { 107 this->split(); 108 } 109 return false; 110 } 111 112 void Asteroids2DStone::split() 113 { 114 if(size == 1) 115 { 116 this->death(); 117 118 }else if(size == 2){ 119 Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 1, this->getPosition()); 120 newStone1->addTemplate("stone1"); 121 Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 1, this->getPosition()); 122 newStone2->addTemplate("stone1"); 123 }else{ 124 Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 2, this->getPosition()); 125 newStone1->addTemplate("stone1"); 126 Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 2, this->getPosition()); 127 newStone2->addTemplate("stone1"); 128 } 129 } 130 131 84 132 85 133
Note: See TracChangeset
for help on using the changeset viewer.