HTML and CSS Reference
In-Depth Information
setTextStyle()
Sets the base text style before text is written to the game screen.
renderScoreBoard()
Is called on each frame tick. It displays the updated score, number of ships re-
maining, and the current FPS for the game.
checkKeys()
Checks the
keyPressList
array, and then modifies the player ship attributes based
on the values found to be
true
.
update()
Is called from
GAME_STATE_PLAY_LEVEL
. It in turn calls the
update()
function for each
individual display object array.
Individual display object
update()
functions
The unique functions listed below update each different type of display object.
These functions (with the exception of
updatePlayer()
) will loop through the
respective array of objects associated with its type of display object, and update
the
x
and
y
values with
dx
and
dy
values. The
updateSaucer()
function contains
the logic necessary to check whether to create a new saucer, and whether any
current saucers on the screen should fire a missile at the player.
•
updatePlayer()
•
updatePlayerMissiles()
•
updateRocks()
•
updateSaucers()
•
updateSaucerMissiles()
•
updateParticles()
render()
Is called from
GAME_STATE_PLAY_LEVEL
. It in turn calls the
render()
function for each
individual display object array.
Individual display object
render()
functions
Like the
update()
functions, the unique functions listed below render each
different type of display object. Again, with the exception of the
render
Player()
object (because there is only a single player ship), each of these func-
tions will loop through the array of objects associated with its type and draw
them to the game screen. As we saw when drawing the player ship earlier in
this chapter, we will draw each object by moving and translating the canvas
to the point at which we want to draw our logical object. We will then trans-
form our object (if necessary) and paint the paths to the game screen.
•
renderPlayer()
•
renderPlayerMissiles()
•
renderRocks()