[Orxonox-commit 7111] r11728 - code/branches/Presentation_HS17_merge/src/modules/asteroids2D

landauf at orxonox.net landauf at orxonox.net
Sun Feb 11 16:13:55 CET 2018


Author: landauf
Date: 2018-02-11 16:13:55 +0100 (Sun, 11 Feb 2018)
New Revision: 11728

Modified:
   code/branches/Presentation_HS17_merge/src/modules/asteroids2D/Asteroids2DStone.cc
Log:
[Asteroid_HS17] fixed a bunch of bugs in the placement of stones

Modified: code/branches/Presentation_HS17_merge/src/modules/asteroids2D/Asteroids2DStone.cc
===================================================================
--- code/branches/Presentation_HS17_merge/src/modules/asteroids2D/Asteroids2DStone.cc	2018-02-11 14:44:49 UTC (rev 11727)
+++ code/branches/Presentation_HS17_merge/src/modules/asteroids2D/Asteroids2DStone.cc	2018-02-11 15:13:55 UTC (rev 11728)
@@ -33,7 +33,6 @@
     @brief Implementation of the Asteroids2DStone class.
 
     TO DO:  
-    - instead of moving over the boarders of the playing field, modify the tick function so that the stones bounce back
     - when to split? It does not work if you override kill() function...->damage() function?
 */ 
 
@@ -81,9 +80,9 @@
     Vector3 Asteroids2DStone::randomVelocity(float maxspeed)
     {
         Vector3 vel;
-        vel.x = rnd(maxspeed);
+        vel.x = rnd(-maxspeed, maxspeed);
         vel.y = 0;
-        vel.z = rnd(maxspeed);
+        vel.z = rnd(-maxspeed, maxspeed);
         return vel;
     }
 
@@ -92,20 +91,16 @@
     {
     	SUPER(Asteroids2DStone, tick, dt);
         Vector3 pos = this->getPosition();
+        Vector3 vel = this->getVelocity();
 
+        //ensure that the stone bounces from the playing field borders
+        if(pos.x > width/2  || pos.x < -width/2)  vel.x = -vel.x;
+        if(pos.z > height/2 || pos.z < -height/2) vel.z = -vel.z;
+        this->setVelocity(vel);
 
-        if(pos.x >= width/2){
-            pos.x = -width/2;
-        }else if(pos.x <= -width/2){
-            pos.x = -width/2;
-        }else if(pos.z >= height/2){
-            pos.z = -height/2;
-        }else if(pos.z <= -height/2){
-            pos.z = -width/2;
-        }
-
+        //2D movement, position should always = 0 on y-axis
+        if(pos.y!=0) pos.y = 0;
         this->setPosition(pos);
-
     }
 
     inline bool Asteroids2DStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)



More information about the Orxonox-commit mailing list