Game Development Reference
In-Depth Information
its state time. The invader will then stop moving, and only update its state time based on the
current delta time.
The World Class
The World class is the mastermind in all of this. It stores the ship, the invaders, and the shots,
and it is responsible for updating them and checking on collisions. It's much the same as in
Super Jumper, with a few minor differences. The initial placement of the shield blocks, as well as
the invaders, is also a responsibility of the World class. We create a WorldListener interface to
inform any outside parties of events within our world, such as an explosion or a shot that's been
fired. This will allow us to play sound effects, just like in Super Jumper. It helps to go through the
code one method at a time. Listing 12-10 shows the code.
Listing 12-10. World.java, the World Class, Tying Everything Together
package com.badlogic.androidgames.androidinvaders;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import com.badlogic.androidgames.framework.math.OverlapTester;
public class World {
public interface WorldListener {
public void explosion();
public void shot();
}
We want outside parties to know when an explosion takes place or when a shot is fired. For
this, we define a listener interface, which we can implement and register with a World instance
that will be called when one of these events happen. This is much like Super Jumper, just with
different events.
final static float WORLD _ MIN _ X = −14;
final static float WORLD _ MAX _ X = 14;
final static float WORLD _ MIN _ Z = −15;
We also have a couple of constants that define the extents of the world, as discussed earlier in
the “Defining the Game World� section.
WorldListener listener;
int waves = 1;
int score = 0;
float speedMultiplier = 1;
final List<Shot> shots = new ArrayList<Shot>();
final List<Invader> invaders = new ArrayList<Invader>();
final List<Shield> shields = new ArrayList<Shield>();
 
Search WWH ::




Custom Search