HTML and CSS Reference
In-Depth Information
In the canvasApp() function, we set up the following variables to use in the game.
The appState variable holds the current state variable:
var
var appState = STATE_INIT ;
We use the loadCount and itemsToLoad variables in exactly the same way we used them in
the audio player application—except here we will be loading more items:
var
var loadCount = 0 ;
var
var itemsToLoad = 0 ;
Thevariables alienImage , missileImage ,and playerImage willholdtheloadedimageswe
use in the game:
var
var alienImage = new
new Image ();
var
var missileImage = new
new Image ();
var
var playerImage = new
new Image ();
explodeSound and shootSound will hold the references to the HTMLAudioElement objects
we will load:
var
var explodeSound ;
var
var shootSound ;
The audioType variable will hold the extension of the valid audio file type for the browser
displaying the application:
var
var audioType ;
The mouseX and mouseY variables will hold the current x and y location of the mouse:
var
var mouseX ;
var
var mouseY ;
The player variable will hold a dynamic object with the x and y location of the player ship
(controlled with the mouse):
var
var player = { x : 250 , y : 475 };
Both the aliens and missiles arrays will hold lists of dynamic objects for displaying aliens
and missiles on the canvas:
var
var aliens = new
new Array ();
var
var missiles = new
new Array ();
Thenextfivevariablessetthenumberofaliens( ALIEN_ROWS , ALIEN_COLS ),theirstartingloc-
ation ( ALIEN_START_X , ALIEN_START_Y ), and their spacing on screen ( ALIEN_SPACING ):
Search WWH ::




Custom Search