My player-objects keep getting stuck at the edges of the world, eventhough I set up these couple of codes to prevent it from happening:
As well as:
public void wallBounce()
{
if(atWorldRight()) {
xVel *= -1.1;
setLocation((int) (getX() + xVel), (int) (getY() + yVel));
}
if(atWorldLeft()) {
xVel *= -1.1;
setLocation((int) (getX() + xVel), (int) (getY() + yVel));
}
if(atWorldTop()) {
yVel *= -1.1;
setLocation((int) (getX() + xVel), (int) (getY() + yVel));
}
if(atWorldBottom()) {
yVel *= -1.1;
setLocation((int) (getX() + xVel), (int) (getY() + yVel));
}
}
Any ideas of how to fix it?
public boolean atWorldLeft() { if(getX() < 20) return true; else return false; } public boolean atWorldRight() { if(getX() > getWorld().getWidth() - 20) return true; else return false; } public boolean atWorldTop() { if(getY() < 20) return true; else return false; } public boolean atWorldBottom() { if(getY() > getWorld().getHeight() - 20) return true; else return false; }