Game Development Reference
In-Depth Information
public static
Texture
shipTexture
;
public static
Vertices3
invaderModel
;
public static
Texture
invaderTexture
;
public static
Vertices3
shotModel
;
public static
Vertices3
shieldModel
;
We use
Texture
instances and
Vertices3
instances to store the models and textures of our
game's objects. We use an
Animation(0.1f,
instance to hold the frames of the explosion animation.
public static
Music
music
;
public static
Sound
clickSound
;
public static
Sound
explosionSound
;
public static
Sound
shotSound
;
We use a
Music
instance and a few
Sound
instances to store our game's audio.
public static void
load(GLGame game) {
background
=
new
Texture(game, "background.jpg",
true
);
backgroundRegion
=
new
TextureRegion(
background
, 0, 0, 480, 320);
items
=
new
Texture(game, "items.png",
true
);
logoRegion
=
new
TextureRegion(
items
, 0, 256, 384, 128);
menuRegion
=
new
TextureRegion(
items
, 0, 128, 224, 64);
gameOverRegion
=
new
TextureRegion(
items
, 224, 128, 128, 64);
pauseRegion
=
new
TextureRegion(
items
, 0, 192, 160, 64);
settingsRegion
=
new
TextureRegion(
items
, 0, 160, 224, 32);
touchRegion
=
new
TextureRegion(
items
, 0, 384, 64, 64);
accelRegion
=
new
TextureRegion(
items
, 64, 384, 64, 64);
touchEnabledRegion
=
new
TextureRegion(
items
, 0, 448, 64, 64);
accelEnabledRegion
=
new
TextureRegion(
items
, 64, 448, 64, 64);
soundRegion
=
new
TextureRegion(
items
, 128, 384, 64, 64);
soundEnabledRegion
=
new
TextureRegion(
items
, 190, 384, 64, 64);
leftRegion
=
new
TextureRegion(
items
, 0, 0, 64, 64);
rightRegion
=
new
TextureRegion(
items
, 64, 0, 64, 64);
fireRegion
=
new
TextureRegion(
items
, 128, 0, 64, 64);
pauseButtonRegion
=
new
TextureRegion(
items
, 0, 64, 64, 64);
font
=
new
Font(
items
, 224, 0, 16, 16, 20);
The
load()
method starts off by creating the UI-related stuff. It's just some texture loading and
region creation, as usual.
explosionTexture
=
new
Texture(game, "explode.png",
true
);
TextureRegion[] keyFrames =
new
TextureRegion[16];
int
frame = 0;
for
(
int
y = 0; y < 256; y += 64) {
for
(
int
x = 0; x < 256; x += 64) {
keyFrames[frame++] =
new
TextureRegion(
explosionTexture
, x, y, 64, 64);
}
}
explosionAnim
=
new
Animation(0.1f, keyFrames);