Game Development Reference
In-Depth Information
@Override
public void dispose() {
}
}
The rest of the class is again composed of a few boilerplate methods with no functionality
whatsoever.
Before we can create the GameScreen class, we first have to implement the logic and rendering of
our world. Model-View-Controller to the rescue!
The Simulation Classes
As usual, we'll create a single class for each object in our world:
Shield blocks
ï?®
Shots
ï?®
A ship
ï?®
Invaders
ï?®
The orchestration is performed by an all-knowing World class. As we saw in Chapter 11, there's
really not such a huge difference between 2D and 3D when it comes to object representation.
Instead of GameObject and DynamicObject , we can now use GameObject3D and DynamicObject3D .
The only differences are that we use Vector3 instances instead of Vector2 instances to store
positions, velocities, and accelerations, and we use bounding spheres instead of bounding
rectangles to represent the shapes of the objects. All that's left to do is implement the behavior
of the different objects in our world.
The Shield Block Class
From the game mechanics definition, we know the size and behavior of our shield blocks. They
just sit there in our world at some location, waiting to be annihilated by a shot, either from the ship
or from an invader. There's not a lot of logic in them, so the code is rather concise. Listing 12-6
shows the internals of a shield block.
Listing 12-6. Shield.java, the Shield Block Class
package com.badlogic.androidgames.androidinvaders;
import com.badlogic.androidgames.framework.GameObject3D;
public class Shield extends GameObject3D {
static float SHIELD_RADIUS = 0.5f;
public Shield( float x, float y, float z) {
super (x, y, z, SHIELD_RADIUS );
}
}
 
Search WWH ::




Custom Search