It's working for the right walls, but for some reason not for the left....
Can someone explain?
Yours,
Dennis
// Methods for checking if the char is walking against a . If it does, it has to stop moving in the direction
public boolean checkRightWalls()
{
int spriteWidth = getImage().getWidth();
int xDistance = (int)(spriteWidth/2);
Actor rightWall = getOneObjectAtOffset(xDistance, 0, Wall.class);
if (rightWall == null)
{
return false;
}
else
{
stopByRightWall(rightWall);
return true;
}
}
public void stopByRightWall (Actor rightWall)
{
int wallWidth = rightWall.getImage().getWidth();
int newX = rightWall.getX() -(wallWidth + getImage().getWidth())/2;
setLocation(newX - 2, getY());
}
//niet door LINKER muur heenlopen
public boolean checkLeftWalls()
{
int spriteWidth = getImage().getWidth();
int xDistance = (int)(spriteWidth/2);
Actor leftWall = getOneObjectAtOffset(xDistance, 0, Wall.class);
if (leftWall == null)
{
return false;
}
else
{
System.out.println("I see a left wall");
stopByLeftWall(leftWall);
return true;
}
}
public void stopByLeftWall (Actor leftWall)
{
int wallWidth = leftWall.getImage().getWidth();
int newX = leftWall.getX() +(wallWidth + getImage().getWidth())/2;
setLocation(newX + 2, getY());
}

