BasicNinja

BasicNinja

A BasicNinja moves around in a tiled map using velocity, basic jumping and collisions are handled, and it can wall slide, wall jump, and double jump. A BasicNinja is a MapMover/MapTraveler but it does not extend either, rather is directly built from just an extension of TravelerSkeleton


Constructor

new BasicNinja(x, y, width, height, map, caopt, dontCloneMapopt, dtopt, tileWopt, tileHopt, mapRowsopt, mapColumnsopt, useBlitMathSpecificArraysopt)

Constructs a new BasicNinja

Parameters:
Name Type Attributes Default Description
x Number

The x position of the BasicNinja

y Number

The y position of the BasicNinja

width Number

The width of the BasicNinja

height Number

The height of the BasicNinja

map Array

2D Array that the BasicNinja is to collide with, 0 or [0,0] as a value in the 2D array denotes a walkable spot. The 2d Array should have all integer values, or all values of [y,x] style inner arrays.

ca CanvasAnimation <optional>
null

CanvasAnimation for the BasicNinja

dontCloneMap Boolean <optional>
false

Default is false

dt Number <optional>
.6666666667

Default is tabageos.TimeKeeper._sae

tileW Number <optional>

The width of each tile, default is the same as width.

tileH Number <optional>

The height of each tile, default is the same as height.

mapRows Number <optional>

The amount of rows in map

mapColumns Number <optional>

The amount of columns in map

useBlitMathSpecificArrays Boolean <optional>

This ultimately is set based on the actual value types in map

Members

_atCeiling

If 1 then the BasicNinja is colliding top

_autoAnimate

_canvasAnimation

A reference to the CanvasAnimation for this class.

_gravityLevel

Default is .285

_grounded

If 1 then the BasicNinja is colliding bottom

_jumps

When _jumps is 0 gravity is not applied, by default _jumps is 1 for BasicNinja.

_jumpSpeed

Defines the height of jump

_map

The 2D Array that the BasicNinja is to collide with

_pLeft

Inherited from MapMover, if 1 then the BasicNinja is colliding left

_pRight

if 1 then the BasicNinja is colliding right

_th

The tile height of each tile the values in _map represent, default is 16.

_tw

The tile width of each tile the values in _map represent, default is 16.

_unGrounded

If 1 then the BasicNinja is not colliding bottom

_walkSpeed

Defines the speed of movement

_wallObject :Rectangle

An optional Rectangle defining a wall the BasicNinja should not pass. Set boundingMethod to one of the tabageos.BoundMethods and define this rectangle to have the BasicNinja collide with the Rectangle. By default the boundingMethod is tabageos.BoundMethods.bounceOff, so if you just define a _wallObject Rectangle it would bounce off that defined space. By default a _wallObject is not defined.

Type:

boundingMethod

By default this is set to tabageos.BoundMethods.bounceOff. See _wallObject.

destination

down

state of 4

forceGrounded

health

Property for health to be used manually.

stand

state of 1

up

state of 3

walk

state of 2

Methods

_addedToChangeDirectionAnimation(left, right, up, down, keepAniIndex, noIdle)

This method becomes part of this class' CanvasAnimation's changeDirectionAnimation method. This Class is using this functionality to add onwall animation and flip animation. It's ready for 'onwallleft' 'onwallright' and 'flipleft' and 'flipright'.

Simply define a 'onwallleft' and 'onwallright' animation for the CanvasAnimation passed to this class, and this class automatically changes to those when the BasicNinja is on a wall. If you don't define those then the left and right animations would be used when on a wall. Same for flip.

Parameters:
Name Type Description
left
right
up
down
keepAniIndex Boolean
noIdle Boolean

autoAnimation()

_autoAnimate must be set to 1.

the functionality of this method happens in the update method if _autoAnimate is true, but you can also call this method if needed, for example if you need to animate outside of the move call.

updates the position of the _canvasAnimation and calls its changeDirectionAnimation function then animate and blit. if there is no _canvasAnimation then _directCanvasObject.context.fillRect is used with this x y width height.

isGroundedOnMap(last, curr, veloc, map, tw, th) → {Number}

Used by the update method to determine bottom collision

Parameters:
Name Type Description
last MoverPoint

_lastPos

curr MoverPoint

_pos

veloc MoverPoint

_veloc

map Array

_map

tw Number

tile width, _tw

th Number

tile height, _th

Returns:

The y point of collision

Type
Number

isHeadHitOnMap(last, curr, veloc, map, tw, th) → {Number}

Used by the update method to determine top collision

Parameters:
Name Type Description
last MoverPoint

_lastPos

curr MoverPoint

_pos

veloc MoverPoint

_veloc

map Array

_map

tw Number

tile width, _tw

th Number

tile height, _th

Returns:

The y point of collision

Type
Number

isLeftPushingOnMap(last, curr, veloc, map, tw, th) → {Number}

Used by the update method to determine left collision

Parameters:
Name Type Description
last MoverPoint

_lastPos

curr MoverPoint

_pos

veloc MoverPoint

_veloc

map Array

_map

tw Number

tile width, _tw

th Number

tile height, _th

Returns:

The x point of collision

Type
Number

isRightPushingOnMap(last, curr, veloc, map, tw, th) → {Number}

Used by the update method to determine right collision

Parameters:
Name Type Description
last MoverPoint

_lastPos

curr MoverPoint

_pos

veloc MoverPoint

_veloc

map Array

_map

tw Number

tile width, _tw

th Number

tile height, _th

Returns:

The x point of collision

Type
Number

move(left, right, up, down, dontApplyForceopt)

Moves the BasicNinja by _walkSpeed, also handling collisions with _map and double jumps, wall slides and wall jumps.

Parameters:
Name Type Attributes Default Description
left Boolean

To move left

right Boolean

To move right

up Boolean

To move up

down Boolean

To move down

dontApplyForce Boolean <optional>
false

Make it behave as a MapMover, default is false

update(dontApplyToXYopt, dontApplyForceopt, dontCollideopt)

Updates forceApplier and _veloc and handles collisions. This method is called inside of the move method. To manually move the Class you could update _veloc yourself then call this method. The move method changes _veloc and calls this method. This is the method that is handling collision with the _map and with _wallObject.

Parameters:
Name Type Attributes Default Description
dontApplyToXY Boolean <optional>
false

If true the x and y are not updated, just _pos.

dontApplyForce Boolean <optional>
false

If true forceApplier is not used, and it opperates as a MapMover without traveling ability (ease, wander, etc...)

dontCollide Boolean <optional>
false

If true it will not collide with the map