Class Player
Defined in: Player.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Player()
A class to represent the player on the screen
|
Field Attributes | Field Name and Description |
---|---|
The rate to fall at
|
|
True when the player is on the ground, false otherwise
|
|
The constant or half PI
|
|
The amount of time to spend in the air when jumping
|
|
The maximum height of the jump
|
|
The current position on the sine wave that defines the jump arc
|
|
The speed to progress alone the sine wave that defines
the jumping arc
|
|
True if the player is moving left, false otherwise
|
|
A reference to the level object
|
|
True if the player is moving right, false otherwise
|
|
The distance between the player and the edge of the screen
|
|
the players running speed
|
Method Attributes | Method Name and Description |
---|---|
keyDown(event)
Called when a key is pressed
|
|
keyUp(event)
Called when a key is pressed
|
|
startupPlayer(level)
Initialises this object
|
|
update(dt, context, xScroll, yScroll)
Updates the object
|
|
Updates the current animation depending on the movement
of the player.
|
Field Detail
{Number}
fallMultiplyer
The rate to fall at
{Boolean}
grounded
True when the player is on the ground, false otherwise
{Number}
halfPI
The constant or half PI
{Number}
jumpHangTime
The amount of time to spend in the air when jumping
{Number}
jumpHeight
The maximum height of the jump
{Number}
jumpSinWavePos
The current position on the sine wave that defines the jump arc
{Number}
jumpSinWaveSpeed
The speed to progress alone the sine wave that defines
the jumping arc
{Boolean}
left
True if the player is moving left, false otherwise
{Level}
level
A reference to the level object
{Boolean}
right
True if the player is moving right, false otherwise
{Number}
screenBorder
The distance between the player and the edge of the screen
{Number}
speed
the players running speed
Method Detail
keyDown(event)
Called when a key is pressed
- Parameters:
- event
- Event Object
keyUp(event)
Called when a key is pressed
- Parameters:
- event
- Event Object
startupPlayer(level)
Initialises this object
- Parameters:
- level
update(dt, context, xScroll, yScroll)
Updates the object
- Parameters:
- {Number} dt
- The time since the last frame in seconds
- {CanvasRenderingContext2D} context
- The drawing context
- {Number} xScroll
- The global scrolling value of the x axis
- {Number} yScroll
- The global scrolling value of the y axis
updateAnimation()
Updates the current animation depending on the movement
of the player. This accounts for the fact that both
the left and right arrow keys can be pressed at the
same time.