Game Class
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
()
Item Index
Methods
Methods
entityCanMoveThrough
-
entity
-
x
-
y
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:
entityCanMoveTo
-
entity
-
x
-
y
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:
entityCanSeeThrough
-
x
-
y
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:
entityMoveTo
-
entity
-
x
-
y
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
Gets all objects at tile position
Parameters:
-
x
Number -
y
Number
Returns:
onClick
-
x
-
y
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
Handles tile mouse hover events
Parameters:
-
x
Number- Mouse x coord relative to window.
-
y
Number- Mouse y coord relative to window.
onKeyAction
-
action
Handles user input actions.
Parameters:
-
action
String- Action triggered by user input.
setMapSize
-
width
-
height
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
()
Starts the game.
Properties
entityManager
EntityManager
The current entityManager.
gameOver
Bool
If true input actions are ignored.
lighting
Lighting
The current Lighting.
queueDraw
Boolean
If true the map will be drawn even if this.player.update(action)
returns false.
this.queueDraw
is set to false after every update.