I have been having trouble with adding more meteors for a game I am making. I want to add meteors moving from right to left. Below is my code than you for anyone who tries to help.
public class MyWorld extends World
[code]public class MyWorld extends World
{
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1, false);
prepare();
}
public void act()
{
addMeteor();
}
public void addMeteor()
{
addObject(new Meteors(),Greenfoot.getRandomNumber(400), 0);
}
private void prepare()
{
Rocket Rocket = new Rocket();
addObject(new Rocket(), 100,200);
Rocket.setLocation(0,200);
}
}
public class Obstacles extends Actor
{
/**
* Act - do whatever the Obstacles wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
}
public void move()
{
setLocation(getX()-10,getY());
}
public void remove()
{
if (this.isAtEdge() == true)
{
World world;
world = getWorld();
world.removeObject(this);
return;
}
}
}public class Meteors extends Obstacles
{
public void act()
{
move();
remove();
}
}
