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:
A state to set up the loading of assets:
var STATE_INIT = 10 ;
A wait state that has the application sleep until all assets have been loaded:
var STATE_LOADING = 20 ;
A state to set up the initial game values:
var STATE_RESET = 30 ;
A state that handles all game-play logic:
Search WWH ::

Custom Search