Class

Game

Game(bridge, dispatcher, context)

Represents the main game class responsible for managing game entities, controls, and rendering.
Constructor

# new Game(bridge, dispatcher, context)

Create a new game instance.
Parameters:
Name Type Description
bridge Object The execution context bridge e.g. "web" or IPC handler.
dispatcher Object The dispatcher object for custom game events.
context Object The canvas rendering context.

View Source browser/lib/Game.js, line 21

Classes

Game

Members

array

# ammoPickups

ammoPickups - array containing all ammo pickup item entities

View Source browser/lib/Game.js, line 169

Ballistics

# ballistics

ballistics - game ballistics handler

View Source browser/lib/Game.js, line 193

string | Object

# bridge

bridge - the execution context bridge

View Source browser/lib/Game.js, line 36

Camera

# camera

camera - the game camera

View Source browser/lib/Game.js, line 72

CanvasRenderingContext2D

# context

context - the canvas rendering context

View Source browser/lib/Game.js, line 66

number

# currentLevel

currentLevel - the current game level

View Source browser/lib/Game.js, line 96

Object

# dispatcher

dispatcher - the game custom event dispatcher

View Source browser/lib/Game.js, line 42

array

# enemies

enemies - array containing all enemy entities

View Source browser/lib/Game.js, line 163

array

# entities

entities - array containing all game entities

View Source browser/lib/Game.js, line 151

number

# frame

frame - the current game frame ID

View Source browser/lib/Game.js, line 48

boolean

# gameover

gameover - whether or not the current game is over

View Source browser/lib/Game.js, line 102

Object

# handlers

handlers - the game handlers e.g. storage

View Source browser/lib/Game.js, line 60

array

# healthPickups

healthPickups - array containing all health pickup item entities

View Source browser/lib/Game.js, line 175

Objet

# keyboard

keyboard - the game default keyboard configuration

View Source browser/lib/Game.js, line 78

Objet

# levelPassed

levelPassed - whether or not the current level was passed

View Source browser/lib/Game.js, line 108

Map

# map

map - the game map generator

View Source browser/lib/Game.js, line 90

Objet

# mouse

mouse - the game default mouse configuration

View Source browser/lib/Game.js, line 84

HTMLElement

# overlay

overlay - the game-end overlay

View Source browser/lib/Game.js, line 114

Player

# player

player - the entity representing the player

View Source browser/lib/Game.js, line 145

number

# selectedWeaponIndex

selectedWeaponIndex - the current selected mapped weapon index

View Source browser/lib/Game.js, line 187

array

# staminaPickups

staminaPickups - array containing all stamina pickup item entities

View Source browser/lib/Game.js, line 181

Stats

# stats

Statistics counter for FPS

View Source browser/lib/Game.js, line 120

boolean

# stopped

stopped - Whether or not the game loop is stopped

View Source browser/lib/Game.js, line 54

array

# walls

walls - array containing all wall entities

View Source browser/lib/Game.js, line 157

Methods

# areAllEnemiesDead(entity) → {boolean}

Determine whether or not all enemies are dead based on the enemy entity's allEnemiesDead property.
Parameters:
Name Type Description
entity Enemy the entity representing the enemy

View Source browser/lib/Game.js, line 587

boolean

# attach(handler, instance) → {void}

Attach a handler to the game, e.g. a storage handler
Parameters:
Name Type Description
handler string the handler key
instance Object the handler object

View Source browser/lib/Game.js, line 204

void

# canUpdateEntity(entity) → {boolean}

Determines whether or not the given entity has an update() method implementation.
Parameters:
Name Type Description
entity Object

View Source browser/lib/Game.js, line 472

boolean

# createAmmoPickups() → {this}

Create a new ammo pickup items for the map.

View Source browser/lib/Game.js, line 528

this

# createEnemies() → {this}

Create new enemy entities.

View Source browser/lib/Game.js, line 493

this

# createHealthPickups() → {this}

Create a new health pickup items for the map.

View Source browser/lib/Game.js, line 543

this

# createKeyboardMouseControls() → {void}

Create game keyboard-mouse controls and register event listeners.

View Source browser/lib/Game.js, line 641

void

# createPlayer() → {this}

Create a new player entity.

View Source browser/lib/Game.js, line 481

this

# createStaminaPickups() → {this}

Create a new stamina pickup items for the map.

View Source browser/lib/Game.js, line 558

this

# createVolumeControls() → {void}

Create volume slider controls for game audio.

View Source browser/lib/Game.js, line 712

void

# createWalls() → {this}

Create a new walls for the map.

View Source browser/lib/Game.js, line 513

this

# displayGameEnd() → {void}

Display the game-end overlay.

View Source browser/lib/Game.js, line 596

void

# generateMap(levelIndex) → {this}

Generate a new map based on the passed level index.
Parameters:
Name Type Default Description
levelIndex number 0 the level to generate the map for

View Source browser/lib/Game.js, line 458

this

# isPlayerDead(entity) → {boolean}

Determine whether or not the player is dead.
Parameters:
Name Type Description
entity Player the entity representing the player

View Source browser/lib/Game.js, line 575

boolean

# loop() → {void}

Start the game loop

View Source browser/lib/Game.js, line 218

void

# newGameEntities() → {void}

Create new game entities and params.

View Source browser/lib/Game.js, line 140

void

# onDispatch() → {void}

Handles all custom dispatcher events during the game loop.

View Source browser/lib/Game.js, line 428

void

# onRender() → {void}

Handles all entity render events during the game loop.

View Source browser/lib/Game.js, line 410

void

# onResize() → {void}

Handles all resize events during the game loop.

View Source browser/lib/Game.js, line 444

void

# onUpdate() → {void}

Handle all entity update events during the game loop.

View Source browser/lib/Game.js, line 374

void

# async pause() → {void}

Pause the game

View Source browser/lib/Game.js, line 299

void

# restart() → {void}

Restart the game

View Source browser/lib/Game.js, line 256

void

# run() → {void}

Run the game frames

View Source browser/lib/Game.js, line 245

void

# setWeaponHotKey() → {void}

Set the active weapon hotkey for the UI.

View Source browser/lib/Game.js, line 617

void

# setup(params, loop) → {void}

Setup a new game
Parameters:
Name Type Description
params Object
level number the level to setup
loop boolean whether or not to start the game loop immediately

View Source browser/lib/Game.js, line 341

void

# async start(stopped, nextLevel, savedLevel) → {void}

Start the game
Parameters:
Name Type Default Description
stopped boolean whether or not the game is stopped
nextLevel boolean false whether or not to start the next level
savedLevel number | null null whether or not to start from a saved level

View Source browser/lib/Game.js, line 273

void

# async stop() → {void}

Stop the game

View Source browser/lib/Game.js, line 324

void

# toggleStats(panel) → {void}

Toggle the FPS stats counter.
Parameters:
Name Type Default Description
panel number 0 0 = fps, 1 = ms, 2 = mb, 3+ = custom

View Source browser/lib/Game.js, line 741

void