Im new to greenfoot and want to remake the mobile game "Twocars" but i have truble with the "smooth" movements of the cars
import greenfoot.*;
public class Blauesauto extends Actor
{
boolean rightPressed = false;
int Position = 0;
int verschiebung = 88;
public void act()
{
if (rightPressed==false && Greenfoot.isKeyDown("right") && Position == 0)
{
nachlinks();
Position = 1;
rightPressed = true;
}
if (rightPressed==false && Greenfoot.isKeyDown("right") && Position == 1)
{
nachrechts();
Position = 0;
rightPressed = true;
}
if(rightPressed==true && !Greenfoot.isKeyDown("right"))
{
rightPressed = false;
}
if( getOneIntersectingObject(Blauerkreis.class) != null)
{
}
}
void nachlinks()
{
for ( int i = 0; i < verschiebung; i++)
{
setLocation(getX()-1,getY());
}
}
int smoothlinkscounter= 0;
void smoothnachlinks()
{
smoothlinkscounter++;
if (smoothlinkscounter % 30 == 0)
{
setLocation(getX()-1,getY());
turn(-1);
}
}
void nachrechts()
{
for ( int i = 0; i < verschiebung; i++)
{
setLocation(getX()+1,getY());
}
}
}
