Class: SpaceInvaders

SpaceInvaders()

Space Invaders Game - main game code, loop, event handler

Constructor

new SpaceInvaders()

Create a new space invaders game instance
Properties:
Name Type Description
width number Width of the game in pixels
height number Height of the game in pixels
domElement Object DOM element of the game
score number Current game score
isPaused boolean Is the game paused
gameState string State of current game
player PlayerShip Player 1
bombFactory EnemyBombFactory Creates enemy bombs
enemyFleet EnemyFleet The enemy fleet of ships
bonusDropper BonusDropper Bonus drops
bubbleFactory BubbleFactory Bubbles
explosionFactory ExplosionFactory Explosions
shieldGrid ShieldGrid Shield
trophySystem Trophies Tophies
HUD HUD On screen HUD
splashScreen Object Splashscreen DOM element
gameOverScreen Object Game over DOM element
winnerScreen Object Winner DOM element
Author:
Source:

Methods

changeState(state)

Change the game state - splash, play, gameover, win
Parameters:
Name Type Description
state string The state code to change to
Source:

checkLoss() → {boolean}

Check if we have lost the game, is it game over? Player hit points < 1
Source:
Returns:
Type
boolean

checkWin() → {boolean}

Check if we have won the game, killed all the enemy ships
Source:
Returns:
Type
boolean

handleEvent(e) → {boolean}

Handle the incoming DOM events (keyup and keydown). Pass relevant key events to the PlayerShip instance
Parameters:
Name Type Description
e Event The DOM event instance
Source:
Returns:
False, prevent the browser processing these events.
Type
boolean

pauseToggle()

Toggle the pause status
Source:

restart()

Restart the game
Source:

splashToggle()

Toggle the splash screen
Source:

update()

Main update loop, calls update on other components.
Source: