Does any one know how to change this code to let the player stop if he hits a wall on his left side?
Here's the code for stopping if the player hits a wall which is on hisright side :
public void act()
{
checkRightWall();
}
public boolean checkRightWall()
{
int playerWidth = getImage().getWidth();
int searchRightWall= (int)(playerWidth/2);
Actor rightWall = getOneObjectAtOffset(searchRightWall,0,wall.class);
if(rightWall == null)
{
return false;
}
else
{
stopAtRightWall(rightWall);
return true;
}
}
public void stopAtRightWall(Actor rightWall)
{
int playerWidth = rightWall.getImage().getWidth();
int newX = rightWall.getX() -(playerWidth + getImage().getWidth())/2;
setLocation(newX -5,getY());
}
