hi! im coding a game where the player has to dodge falling asteroids. i changed my code to have a 1/100 chance to spawn a new asteroid, but now my program stops after the asteroid reaches the edge of the world.
asteroid code:
game world code:
public void act() { move(); Player p = (Player)getWorld().getObjects(Player.class).get(0); p = (Player)getOneIntersectingObject(Player.class); if (p != null && GameWorld.getImmunity() == false) { int hp = p.getHP(); hp--; GameWorld.changePoints(-50); GameWorld.hpCounter.setValue(hp); getWorld().removeObject(this); if(hp == 0) { Greenfoot.setWorld(new LoseWorld()); } } } public void move() { setLocation(getX(), getY() + speed); if(isAtEdge()) { getWorld().removeObject(this); GameWorld.changePoints(5); } }
public void act() { int random = Greenfoot.getRandomNumber(100); if (random == 0) { addAsteroid(); } timer.setValue(timeLeft - t.millisElapsed()/1000); if(timer.getValue() == 0) { Greenfoot.setWorld(new LoseWorld()); } } public void addAsteroidp() { int randX = Greenfoot.getRandomNumber(getBackground().getWidth()); addObject(new Asteroid(), randX, WIDTH/10); }