I'm trying to create faithful space acceleration, but with int values it gets ridiculous. I want to set the location of my object using doubles so that it doesn't zoom off forever.
double xVelocity = 0, yVelocity = 0;
double xAcceleration = 0, yAcceleration = 0;
double thrust = 0.01;
public Starship(int rotation)
{
setRotation(rotation);
}
public void act()
{
checkKeys();
moveStars();
checkHit();
weaponFireDelay++;
xVelocity = xVelocity + xAcceleration;
yVelocity = yVelocity + yAcceleration;
this.setLocation(getX() + (int) xVelocity, getY() + (int) yVelocity);
}if (Greenfoot.isKeyDown("up") || Greenfoot.isKeyDown("w"))
{
xAcceleration = ((90 - this.getRotation())/90) * thrust;
yAcceleration = (this.getRotation()/90) * thrust;
}this.setLocation(getX() + (int) xVelocity, getY() + (int) yVelocity);