Game Development Reference
In-Depth Information
import
com.badlogic.androidgames.framework.gl.SpriteBatcher;
import
com.badlogic.androidgames.framework.impl.GLScreen;
import
com.badlogic.androidgames.framework.math.OverlapTester;
import
com.badlogic.androidgames.framework.math.Rectangle;
import
com.badlogic.androidgames.framework.math.Vector2;
public class
GameScreen
extends
GLScreen {
static final int
GAME
_
RUNNING
= 0;
static final int
GAME_PAUSED
= 1;
static final int
GAME_OVER
= 2;
As usual, we have a couple of constants for encoding the screen's current state.
int
state;
Camera2D guiCam;
Vector2 touchPoint;
SpriteBatcher batcher;
World world;
WorldListener worldListener;
WorldRenderer renderer;
Rectangle pauseBounds;
Rectangle resumeBounds;
Rectangle quitBounds;
Rectangle leftBounds;
Rectangle rightBounds;
Rectangle shotBounds;
int
lastScore;
int
lastLives;
int
lastWaves;
String scoreString;
FPSCounter fpsCounter;
The members of the
GameScreen
are business as usual. We have a member keeping track of the
state, a camera, a vector for the touch point, a
SpriteBatcher
for rendering the 2D UI elements,
the
World
instance, along with the
WorldListener
, the
WorldRenderer
(which we are going to
write in a minute), and a couple of
Rectangles
for checking whether a UI element was touched.
In addition, three integers keep track of the last number of lives, waves, and score, so that we
don't have to update the
scoreString
each time in order to reduce GC activity. Finally, we have
an
FPSCounter
so that later on we can figure out how well the game performs.
public
GameScreen(Game game) {
super
(game);
state =
GAME_RUNNING
;
guiCam =
new
Camera2D(glGraphics, 480, 320);
touchPoint =
new
Vector2();
batcher =
new
SpriteBatcher(glGraphics, 100);
world =
new
World();
worldListener =
new
WorldListener() {
public void
shot() {
Assets.
playSound
(Assets.
shotSound
);
}