• 07-13-2012, 08:51 PM
EscSequenceAlpha
Ok so I bought a book that takes me through creating the astroids game. They gave me code in chapter 3 but I dont quite understand how velocity works... perhaps someone could help explain this to me. Ok so we create the astriods

Code:

```for (int n = 0; n<ASTEROIDS; n++) {                         ast[n] = new Asteroid();                         ast[n].setRotationVelocity(rand.nextInt(3)+1);                         ast[n].setX((double)rand.nextInt(600)+20);                         ast[n].setY((double)rand.nextInt(440)+20);                         ast[n].setMoveAngle(rand.nextInt(360));                         double ang = ast[n].getMoveAngle() - 90;                         ast[n].setVelX(calcAngleMoveX(ang));                         ast[n].setVelY(calcAngleMoveY(ang));                 }```
we set the move angle (lets say its heading north, 0)
now we calculate "ang" which is move angle - 90 (west, 270)
we then use ang to calculate the angleMove

public double calcAngleMoveX(double angle)
{
return (double) (Math.cos(angle * Math.PI / 180));
}

what is it that this method is returning? (the book just uses terms like update x & y value), is this method returning the updated angle of movement? how do you work that out from current angle - 90?

now we use this value to calculate velocity (setVel above) - what is velocity, the speed of the object? how do we work that out from the new move angle?

also, because setvelx and setvely use the same base "calcAngleMoveX(ang)" wont x and y be the same?

I dont understand any of this stuff... could one you smart guys explain it all in simple terms so I can visualise how the objects are able to move around. points for whoever explains it the clearest
• 07-14-2012, 10:57 AM
kjkrum