sinlessclown wrote...
How do I make it so that the moving block moves to the right wall first?// from move(direction); // to setLocation(getX()+direction, getY());
// from move(direction); // to setLocation(getX()+direction, getY());
public class Moving_Block extends Platform
{
private int direction = 2;
public void act()
{
move();
moveEverythingOn();
}
private void move()
{
if (direction < 0 && getX() <= getImage().getWidth() / 2
|| direction > 0 && getX() >= getWorld().getWidth() - getImage().getWidth() / 2) {
direction = -direction;
}
setLocation(getX()+direction, getY());
}
private void moveEverythingOn()
{
setLocation(getX(), getY()-1);
Actor player = getOneIntersectingObject(Player.class);
if (player != null) player.setLocation(player.getX()+direction, player.getY());
setLocation(getX(), getY()+1);
}
} public class Moving_Block extends Platform
{
private int direction = 2;
public void act()
{
move();
}
private void move()
{
int width = getWorld().getWidth();
int wide = getImage().getWidth();
if (direction < 0 && getX() <= (width + wide) / 2 || direction > 0 && getX() >= width - 1 - wide / 2) direction = -direction;
setLocation(getX()+direction, getY()-1); // moving with shift up
Actor player = getOneIntersectingObject(Player.class);
if (player != null) player.setLocation(player.getX()+direction, player.getY());
setLocation(getX(), getY()+1); // shifting back down
}
}