HTML and CSS Reference
In-Depth Information
Space Raiders Game Structure
Space Raiders is an iconic action game where a swarm of alien invaders attack from the top
of the screen, and the player's job is to defend the world. The raiders move in horizontal lines
near the top of the screen. When each raider reaches the side of the playfield, it moves down
the screen and then switches direction.
The player controls a spaceship by moving the mouse and fires missiles using the left mouse
button. We need to play a “shoot” sound every time the player fires a missile. When the mis-
siles hit the enemy space raiders, we need to remove them from the screen and then play an
“explosion” sound. We are not limiting the number of shots the player can fire, which means
that there couldbeanynumberofshootandexplode soundsplaying simultaneously.Ourgoal
is to manage all these dynamic sounds.
State machine
This game runs using a very simple state machine. A state machine is a construct that allows
anapplication toexist inonlyonestate atatime, whichmeans itisonlydoingonething.This
kind of construct is great for single-player games because it removes the need to hold a bunch
of Booleans describing what is going on at any one moment.
Space Raiders has four states plus a variable named appState that holds the value of the cur-
rent state. Those states include:
STATE_INIT
A state to set up the loading of assets:
var
var STATE_INIT = 10 ;
STATE_LOADING
STATE_LOADING
A wait state that has the application sleep until all assets have been loaded:
var
var STATE_LOADING = 20 ;
STATE_RESET
STATE_RESET
A state to set up the initial game values:
var
var STATE_RESET = 30 ;
STATE_PLAYING
A state that handles all game-play logic:
Search WWH ::




Custom Search