hi all
I have tried to make some code that will slow down my character to a stop once I have taken my hand off the movement key. I'm not to sure were I have gone wrong. there is probably a better way of doing this but this is what I came up with at the time, so much help would be appreciated.
thanks guys
public void MovementLeft()
{
int counter = 0;
if (Greenfoot.isKeyDown("a"))
{
setLocation(getX()-4,getY());
counter = 25;
while (counter > 0)
{
if (counter <= 25 && counter > 20)
{
setLocation(getX()-4,getY());
counter --;
}
if (counter < 20 && counter > 15)
{
setLocation(getX()-3,getY());
counter --;
}
if (counter < 15 && counter > 10)
{
setLocation(getX()-2,getY());
counter --;
}
if (counter < 10 && counter > 5)
{
setLocation(getX()-1,getY());
counter --;
}
if (counter <5 && counter > 0)
{
setLocation(getX()+0,getY());
counter --;
}
}
}
}
