Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11728


Ignore:
Timestamp:
Feb 11, 2018, 4:13:55 PM (7 years ago)
Author:
landauf
Message:

[Asteroid_HS17] fixed a bunch of bugs in the placement of stones

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Presentation_HS17_merge/src/modules/asteroids2D/Asteroids2DStone.cc

    r11669 r11728  
    3434
    3535    TO DO: 
    36     - instead of moving over the boarders of the playing field, modify the tick function so that the stones bounce back
    3736    - when to split? It does not work if you override kill() function...->damage() function?
    3837*/
     
    8281    {
    8382        Vector3 vel;
    84         vel.x = rnd(maxspeed);
     83        vel.x = rnd(-maxspeed, maxspeed);
    8584        vel.y = 0;
    86         vel.z = rnd(maxspeed);
     85        vel.z = rnd(-maxspeed, maxspeed);
    8786        return vel;
    8887    }
     
    9392        SUPER(Asteroids2DStone, tick, dt);
    9493        Vector3 pos = this->getPosition();
     94        Vector3 vel = this->getVelocity();
    9595
     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);
    96100
    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;
    107103        this->setPosition(pos);
    108 
    109104    }
    110105
Note: See TracChangeset for help on using the changeset viewer.