HTML and CSS Reference
In-Depth Information
The Player Object
The player objectcontainsmanyofthevariablesweencounteredearlierinthischapterwhen
wediscussedanimating, rotating,andmovingtheplayershipaboutthegamescreen.Wehave
also added in three new variables that you have not seen before:
player . maxVelocity = 5 ;
player . width = 20 ;
player . height = 20 ;
player . halfWidth = 10 ;
player . halfHeight = 10 ;
player . rotationalVelocity = 5
player . thrustAcceleration = . 05 ;
player . missileFrameDelay = 5 ;
player . thrust = false
false ;
The new variables are halfWidth , halfHeight , and missileFrameDelay . halfWidth and
halfHeight simplystorehalfthewidthandhalftheheightvalues,sotheseneednotbecalcu-
lated on each frame tick in multiple locations inside the code. The missileFrameDelay vari-
able contains the number of frame ticks the game will count between firing player missiles.
This way, the player cannot simply fire a steady stream of ordnance and destroy everything
with little difficulty.
The player.thrust variable will be set to true when the player presses the up key.
Search WWH ::




Custom Search