Currently when we kill a monster nothing special happens, and the monsters are quickly exterminated. We can take
several approaches here:
Spawn new monsters as older ones are killed
Change the current "level" switching to different backgrounds and different critters
Making new monsters appear periodically regardless of how many are killed
To illustrate our point, we'll use the first approach here - we'll spawn a new monster for each monster killed.
This is as easy as adding the following to our Monster class:
Monster.java
. . .
33 public void collision(Actor a) {
34 if (a instanceof Bullet || a instanceof Bomb) {
35 remove();
36 spawn();
37 stage.getPlayer().addScore(20);
38 }
39 }
40
41 public void spawn() {
42 Monster m = new Monster(stage);
43 m.setX( (int)(Math.random()*Stage.WIDTH) );
44 m.setY( (int)(Math.random()*Stage.PLAY_HEIGHT/2) );
45 m.setVx( (int)(Math.random()*20-10) );
46 stage.addActor(m);
47 }
48
49 public void fire() {
. . .
Do you want to be notified when new tutorials or lessons are published?
Press here