gma.moveable

Provides functionality for a moveable shape

Package gma/entities/moveable
Inheritance chain gma.shapes.rectangle
Descendants gma.character, gma.enemy, gma.platformEnemy, gma.jumpingEnemy, gma.patrolEnemy

Tags

shape, moveable

Properties

yState

Flag saying whether character is jumping, falling or neither

Type gma.constant
Default FALLING

xState

Flag saying whether character is going left, right or neither

Type gma.constant
Default STILL

lastXState

Flag saying what direction character was going last before becoming horizontally still

Type gma.constant
Default self.xState

velocity

Number representing how fast the character is moving vertically

Type Number
Default 0

jumpVelocity

Number representing the initial velocity of a jump

Type Number
Default 4

Methods

getMovement (moveAmount) -> Amount to move as [x, y]
Looks at the character’s state and determines how far it should move
This result will then be checked for collisions and may be modified
If the character is jumping :
  • Keep going up if haven’t reached targetY
  • else set vertical state to FALLING
If we’re falling, then we go down
If horizontal state is not STILL, then we add horizontal movement.
Parameters
moveAmount Number The amount the character should move
animate (delta, manager)
Changes character’s position according to it’s state
First it asks getMovement how much we should move
Then it determines how far we can move given the environment
It will then change the state of the character accordingly
It will then determine if the character is on top of ground
and set vertical state to FALLING or STILL accordingly
Parameters
delta Number Time since last animation
manager gma.manager  
findGround (manager)

Finds any ground the character is on and changes state accordingly

Parameters
manager gma.manager
updatePositions (vector)

Changes it’s position, centre, points and edges.

Parameters
vector [x, y] Vector representing the amount character can move
getRotation ( ) -> Number
Gets rotation in radians
kill ( )
Kills the entity. Should be overwritten to do something useful.

Table Of Contents

Fork me on GitHub