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 |
Classes
Members
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 |
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 |
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 |
void
# takeDamage(enemy) → {void}
Handle damage from colliding enemies.
Parameters:
Name | Type | Description |
---|---|---|
enemy |
Enemy
|
the enemy entity |
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 |
void