So I´m trying to make a scroller game where the player only moves vertically and the objects(obstacles) move horizontally. But now I´m having trouble making the obstacles stop if the player is running into them.
In my Player class I have:
Now I want to access that method in my GroundGrassLeft class:
I´m struggling in the getPlayerX() method in which I want to access the vMovement() method from the Player class.
Could anyone help me?
public int vMovement()
{
if(Greenfoot.isKeyDown("d"))
{
x += 4;
}
if(Greenfoot.isKeyDown("a"))
{
x -= 4;
}
if(x < 0)
{
x = 0;
}
return x;
}public class GroundGrassLeft extends Actor
{
int i = 0;
int x = 0;
int a = 4;
int j = 0;
public GroundGrassLeft(int j)
{
i = j;
}
public void act()
{
setLocation(16 * i - 9 - x, getY());
x = 9;
}
public static void getPlayerX()
{
List player = getObjectsInRange(1000, Player.class);
Actor a = (Actor) player.get(0);
x = a.
}
}
