How can i make the first code function like the second but with the xVel,yVel variables?
private void accelerateByKeys()
{
if(Greenfoot.isKeyDown("r"))
{
xVel=0;
yVel=0;
}
if(Greenfoot.isKeyDown("d"))
{
xVel+=0.06;
setRotation(180);
}
if(Greenfoot.isKeyDown("a"))
{
xVel-=0.06;
setRotation(0);
}
if(Greenfoot.isKeyDown("s"))
{
yVel+=0.06;
setRotation(-90);
}
if(Greenfoot.isKeyDown("w"))
{
yVel-=0.06;
setRotation(90);
EngineSound.playLoop();
EngineSound.setVolume(100);
} else
{
EngineSound.pause();
}
} private void MoveShip()
{
if (Greenfoot.isKeyDown("a"))
{
turn(-4);
}
if (Greenfoot.isKeyDown("d"))
{
turn(4);
}
if (Greenfoot.isKeyDown("w"))
{
move(3);
if (Greenfoot.isKeyDown("w"))
{
EngineSound.playLoop();
EngineSound.setVolume(100);
} else
{
EngineSound.pause();
}
}protected double xVel,yVel;
