I need help to respawn the aliens in my scenario http://www.greenfoot.org/scenarios/9060 in a proper way can anyone help please
.
public void spawnAliens(){ //this is the chance a new alien is spawned per act if(Greenfoot.getRandomNumber(200)==0) addObject(new Alien(), getWidth(), Greenfoot.getRandomNumber(getHeight()+1)); }
int wave = 0; public void act(){ if(numOfAliens()==0){ wave++; nextWave(wave); } public int numOfAliens(){ return getObjects(Alien.class).size(); } public void nextWave(int wave){ if(wave==1){ //insert here the spawning of the aliens like: addObject(new Alien(), getWidth(), getHeight()/4); addObject(new Alien(), getWidth(), getHeight()/2); addObject(new Alien(), getWidth(), 3*getHeight()/4); //this is like you "painted" the first wave }else if(wave==2){ //same here. change the number of aliens and their place }else if(wave==3){ //and here } //etc. } }
public int numOfAliens(){ List<Alien.class>aliens = getObjects(Alien.class); return aliens.size(); }
import java.awt.Color; import greenfoot.*; public class Text{ airport myWorld; public Text(airport world){//if you create a new text you have to give him an object of class airport, which is your world in this case. That way he is able to use the worlds methods and values myWorld = world; paintMe(); } public void act(){ paintMe(); } public void paintMe(){ GreenfootImage myImage = new GreenfootImage("Wave - "+myWorld.wave,//the text 50, // the size Color.BLACK, //its color new Color(0,0,0,0));//its background color. here it its transparent setImage(myImage); }
// in the world class // add instance fields Text waveText = new Text("Wave - 1"); int wave = 1;// you should already have this one // in constructor (or 'prepare' method) addObject(waveText, 100, 20); // location of your choosing // when a new wave is to be introduced (in the world class) wave++; waveText.setText("Wave - "+wave); // the Text class import greenfoot.*; import java.awt.Color; public class Text extends Actor { public Text(String text) { setText(text); } public void setText(String text) { setImage(new GreenfootImage(text, 24, Color.black, new Color(0, 0, 0, 0))); } }