Actually I should write: beta = (int) (0.5 + (Math.toDegr.... )
Because it would decrease the chance of bad rounding.
But anyway, it's always good to know other ways of doing the same thing, thanks, @newacct !
In this game:
-The zombie class has access to the position x and y of the player.
-So I did this in the act method of Zombie class:
if(manIsLive)
move();
In the move() method, we have:
deltaX=XPlayer-getX();
deltaY=YPlayer-getY();
if(deltaY<0)
moveY=-1;
else
moveY=1;
if(deltaX==0)
moveX=0;
else
{
beta = (int) (Math.toDegrees(Math.atan(deltaY/deltaX)));
if(deltaX<0)
{
moveX=-1;
setRotation(beta+180);
}
else
{
moveX=1;
setRotation(beta);
}
}
setLocation(getX()+moveX , getY()+moveY);
Enjoy and good luck, thanks for playing! xD
Recent Comments | Show All
2011/12/4
Guns vs Zombies
2011/11/6
Guns vs Zombies