HTML and CSS Reference
In-Depth Information
Resetting the game
In the run() function, the STATE_RESET state calls the resetApp() function, which in turn
calls startLevel() . It also sets the volume of our two sounds to 50% ( .5 ) before setting the
appState to STATE_PLAYING :
function
function resetApp () {
startLevel ();
shootSound . volume = . 5 ;
explodeSound . valume = . 5 ;
appState = STATE_PLAYING ;
}
The startLevel() function traverses through two nested for:next loops, creating the rows
of aliens by column. Each time we create an alien, we push a dynamic object into the aliens
array with the following properties:
speed
The number of pixels the aliens will move left or right on each call to drawScreen() .
x
The starting x position of the alien on the screen. This value is set by the column ( c ) mul-
tiplied by ALIEN_SPACING , added to ALIEN_START_X .
y
The starting y position of the alien on the screen. This is set by the row ( r ) multiplied by
ALIEN_SPACING , added to ALIEN_START_Y .
width
The width of the alien image.
height
height
The height of the alien image.
Here is the code for the startLevel() function:
function
function startLevel () {
for
for ( var
var r = 0 ; r < ALIEN_ROWS ; r ++ ) {
for
for ( var
var c = 0 ; c < ALIEN_COLS ; c ++ ) {
Search WWH ::




Custom Search