Class

Player

Player(spawn)

Player entity
Constructor

# new Player(spawn)

Create a new player entity.
Parameters:
Name Type Description
spawn Object the player spawn coordinates
x number the player spawn x-coordinate
y number the player spawn y-coordinate

View Source browser/lib/Entity/Player.js, line 12

Classes

Player

Members

number

# angle

angle - the entity's angle.

View Source browser/lib/Entity/Player.js, line 51

string

# bounding

bounding - the entity's bounding behavior.

View Source browser/lib/Entity/Player.js, line 33

number

# health

health - the entity's health.

View Source browser/lib/Entity/Player.js, line 99

number

# incrementer

incrementer - the entity's speed incrementer.

View Source browser/lib/Entity/Player.js, line 63

boolean

# invincible

invincible - the entity's damage state.

View Source browser/lib/Entity/Player.js, line 93

number

# position

position - the entity's position.

View Source browser/lib/Entity/Player.js, line 57

boolean

# sleep

sleep - the entity's render state.

View Source browser/lib/Entity/Player.js, line 87

number

# speed

speed - the entity's speed.

View Source browser/lib/Entity/Player.js, line 69

boolean

# stamina

stamina - entity stamina boost enabled.

View Source browser/lib/Entity/Player.js, line 75

number

# staminaAmount

staminaAmount - the amount of speed to boost by.

View Source browser/lib/Entity/Player.js, line 81

string

# type

type - the type of entity.

View Source browser/lib/Entity/Player.js, line 27

number

# x

x - the entity's x coordinate.

View Source browser/lib/Entity/Player.js, line 39

number

# y

y - the entity's y coordinate.

View Source browser/lib/Entity/Player.js, line 45

Methods

# boostSpeed(amount) → {void}

Boost player speed when stamina entity is picked up.
Parameters:
Name Type Description
amount number the amount of speed to boost by

View Source browser/lib/Entity/Player.js, line 238

void

# refillHealth(amount, pickup) → {void}

Refill player health when health entity is picked up or used.
Parameters:
Name Type Default Description
amount number the amount of health to restore
pickup boolean false if false, then player is using a stored item

View Source browser/lib/Entity/Player.js, line 253

void

# render(context) → {void}

Render the player entity on the canvas. This is called every frame/repaint to render the entity. Note that this is an animated entity, therefore the x,y coordinates will change on update.
Parameters:
Name Type Description
context CanvasRenderingContext2D the canvas rendering context

View Source browser/lib/Entity/Player.js, line 124

void

# takeDamage(enemy) → {void}

Handle damage from colliding enemies.
Parameters:
Name Type Description
enemy Enemy the enemy entity

View Source browser/lib/Entity/Player.js, line 208

void

# update(game) → {void}

Update the player entity for rendering, collision and behaviour. Checks the render state, sets the player entity's speed, angle and direction, detects collision between the player and walls, checks damage and updates the player entity's position. This is called every frame/repaint.
Parameters:
Name Type Description
game Game the managed game instance

View Source browser/lib/Entity/Player.js, line 139

void