Game Development Reference
In-Depth Information
Listing 11-15. The Properties Declared for the Game Class
// Hero
p.heroShip = null;
p.heroBulletPool = null;
p.heroBullets = null;
// Enemies
p.enemyPool = null;
p.enemies = null;
p.enemyBulletPool = null;
p.enemyBullets = null;
p.enemyLastSpawnTime = null;
p.enemySpawnWaiter = 2000;
// SPRITES
p.stars = null;
p.explosionPool = null;
p.healthMeter = null;
p.lifeBox = null;
p.scoreboard = null;
// GAME VARIABLES
p.leftWall = null;
p.rightWall = null;
p.ceiling = null;
p.floor = null;
p.betweenLevels = true;
p.numLives = 3;
p.delta = null;
// Controls
p.leftKeyDown = false;
p.rightKeyDown = false;
p.upKeyDown = false;
p.downKeyDown = false;
A series of variables are first set up for the hero and enemies. These properties hold the instances of each ship,
all bullets in play, and a few values to determine the speed at which the enemies will attack. The next series declares a
group of properties that will hold references to all other sprites and HUD elements in the game.
Next up are some values that will be used during gameplay to evaluate scenarios and sprite positions. The walls
create the bounds that the hero ship is allowed to move in. The betweenLevels Boolean property decides if the game
loop should continue or wait a moment while the hero ship explodes and resets. The numLives variable is used to
determine if the player should continue playing after exploding. Finally, the delta property is set from the ticker that
runs the game and is used to calculate the positions of the moving sprites. This will be explained in the upcoming
“Using Delta for Time Based Movement” section.
Search WWH ::




Custom Search