Changeset 11728 for code/branches/Presentation_HS17_merge/src
- Timestamp:
- Feb 11, 2018, 4:13:55 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Presentation_HS17_merge/src/modules/asteroids2D/Asteroids2DStone.cc
r11669 r11728 34 34 35 35 TO DO: 36 - instead of moving over the boarders of the playing field, modify the tick function so that the stones bounce back37 36 - when to split? It does not work if you override kill() function...->damage() function? 38 37 */ … … 82 81 { 83 82 Vector3 vel; 84 vel.x = rnd( maxspeed);83 vel.x = rnd(-maxspeed, maxspeed); 85 84 vel.y = 0; 86 vel.z = rnd( maxspeed);85 vel.z = rnd(-maxspeed, maxspeed); 87 86 return vel; 88 87 } … … 93 92 SUPER(Asteroids2DStone, tick, dt); 94 93 Vector3 pos = this->getPosition(); 94 Vector3 vel = this->getVelocity(); 95 95 96 //ensure that the stone bounces from the playing field borders 97 if(pos.x > width/2 || pos.x < -width/2) vel.x = -vel.x; 98 if(pos.z > height/2 || pos.z < -height/2) vel.z = -vel.z; 99 this->setVelocity(vel); 96 100 97 if(pos.x >= width/2){ 98 pos.x = -width/2; 99 }else if(pos.x <= -width/2){ 100 pos.x = -width/2; 101 }else if(pos.z >= height/2){ 102 pos.z = -height/2; 103 }else if(pos.z <= -height/2){ 104 pos.z = -width/2; 105 } 106 101 //2D movement, position should always = 0 on y-axis 102 if(pos.y!=0) pos.y = 0; 107 103 this->setPosition(pos); 108 109 104 } 110 105
Note: See TracChangeset
for help on using the changeset viewer.