API Docs for:
Show:

Game Class

Defined in: src/game.js:4

Container for all game objects. Handles updating the state of game objects each turn. Listens for player input to trigger and resolve new turns.

Constructor

Game

()

Defined in src/game.js:4

Methods

entityCanMoveThrough

(
  • entity
  • x
  • y
)
Bool

Defined in src/game.js:219

Checks if an entity can move through a map tile. This does NOT check for entities on the tile blocking movement. This is where code for special cases changing an entity's ability to pass through a tile should be placed. Things like flying, swimming and ghosts moving through walls.

Parameters:

  • entity Entity
    • The entity to check.
  • x Number
    • The x map tile coord to check.
  • y Number
    • The y map tile coord to check.

Returns:

Bool:

entityCanMoveTo

(
  • entity
  • x
  • y
)
Bool

Defined in src/game.js:239

Checks if an entity can move through and into a map tile and that tile is un-occupied.

Parameters:

  • entity Entity
    • The entity to check.
  • x Number
    • The x map tile coord to check.
  • y Number
    • The y map tile coord to check.

Returns:

Bool:

entityCanSeeThrough

(
  • x
  • y
)
Bool

Defined in src/game.js:275

Checks if a map tile can be seen through. This is where code for special cases like smoke, fog, x-ray vision can be implemented by checking the entity param.

Parameters:

  • x Number
    • The x map tile coord to check.
  • y Number
    • The y map tile coord to check.

Returns:

Bool:

entityMoveTo

(
  • entity
  • x
  • y
)

Defined in src/game.js:258

Changes the position of an entity on the map. Updates entity position in this.entityManager and calls tile.onEntityEnter. this.entityCanMoveTo() should always be checked first.

Parameters:

  • entity Entity
    • The entity to move.
  • x Number
    • The tile map x coord to move to.
  • y Number
    • The tile map y coord to move to.

getObjectsAtPostion

(
  • x
  • y
)
Array

Defined in src/game.js:199

Gets all objects at tile position

Parameters:

  • x Number
  • y Number

Returns:

Array:

onClick

(
  • x
  • y
)

Defined in src/game.js:159

Handles tile mouse click events.

Parameters:

  • x Number
    • Mouse x coord relative to window.
  • y Number
    • Mouse y coord relative to window.

onHover

(
  • x
  • y
)

Defined in src/game.js:180

Handles tile mouse hover events

Parameters:

  • x Number
    • Mouse x coord relative to window.
  • y Number
    • Mouse y coord relative to window.

onKeyAction

(
  • action
)

Defined in src/game.js:135

Handles user input actions.

Parameters:

  • action String
    • Action triggered by user input.

setMapSize

(
  • width
  • height
)

Defined in src/game.js:109

Sets the size of the map resizing this.map and this.entityManager.

Parameters:

  • width Number
    • Width in tilse to set map and entityManager to.
  • height Number
    • Height in tilse to set map and entityManager to.

start

()

Defined in src/game.js:122

Starts the game.

Properties

console

Console

Defined in src/game.js:66

The current console.

entityManager

EntityManager

Defined in src/game.js:45

The current entityManager.

gameOver

Bool

Defined in src/game.js:94

If true input actions are ignored.

input

Input

Defined in src/game.js:80

The current input.

lighting

Lighting

Defined in src/game.js:52

The current Lighting.

map

Array2d

Defined in src/game.js:38

The current map.

mouse

Mouse

Defined in src/game.js:87

The current mouse.

player

Player

Defined in src/game.js:73

The current player.

queueDraw

Boolean

Defined in src/game.js:101

If true the map will be drawn even if this.player.update(action) returns false. this.queueDraw is set to false after every update.

renderer

Renderer

Defined in src/game.js:59

The current renderer.