Hi all,
having an attempt at some programming with greenfoot, but come to a little problem. I am trying to get my code to add 3 enemies if 3 enemies are no longer present on the screen. I so far have this for the world:
and this for the enemy:
public class City extends World { /** * Constructor for objects of class City. * */ public City() { super(700, 300, 1); populateCity(); enemySwarm(); } public void populateCity() { addObject(new Ship(), 100, 120); } public void enemySwarm() { int count = 1; while (count < 4) { addObject(new enemyShip(), 800, Greenfoot.getRandomNumber(300)); count++; } } }
public class enemyShip extends Enemies { private int velocity = 3; private int outOfBoundary = 400; /** * Act - do whatever the enemyShip wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { moveLeft(); if (getX() <= getWorld().getWidth() - (getWorld().getWidth() - outOfBoundary)) { getWorld().removeObject(this); } } public void moveLeft() { setLocation(getX() - velocity, getY()); } }