In my current project i have an actor (called Runner) which cannot cannot move through walls. i want another actor that covers the whole screen except a circle (called Cover) to stay directly above the other. i used the same movement code so they will both move in sync. The only problem is when the Runner hits a wall the cover continues to move. How do i get the Runner's location and sync it with the Cover's location? my movement for the runner is:
public void slideAround()
{
int x = getX();
int y = getY();
if(Greenfoot.isKeyDown("right"))
{
setRotation(90);
setLocation(x + speed, y);
if(hitWalls())
{
setLocation(x - speed, y);
}
}
if(Greenfoot.isKeyDown("left"))
{
setRotation(270);
setLocation(x - speed, y);
if(hitWalls())
{
setLocation(x + speed, y);
}
}
if(Greenfoot.isKeyDown("up"))
{
setRotation(0);
setLocation(x , y - speed);
if(hitWalls())
{
setLocation(x , y + speed);
}
}
if(Greenfoot.isKeyDown("down"))
{
setRotation(180);
setLocation(x , y + speed);
if(hitWalls())
{
setLocation(x , y - speed);
}
}
}
