Constructor
new Ninja(x, y, w, h, floorHeight, g)
Constructs an instance of a Ninja object
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x position of the ninja |
y |
number | The y position of the ninja |
w |
number | The width of the ninja |
h |
number | The height of the ninja |
floorHeight |
number | The floor height |
g |
number | The strength of gravity on the ninja |
Methods
collideWith(obstacle) → {boolean}
Checks to see if the ninja has collided with a specified obstacle. This
is done by checking to see if any boundaries overlap.
Parameters:
Name | Type | Description |
---|---|---|
obstacle |
Obstacle | The obstacle to check for collision |
Returns:
True when the objects has collided with the ninja
- Type
- boolean
draw()
Draws the ninja on the canvas in the appropriate position. If the sprite
images have not loaded properly this will adjust and just draw a simple
rectangle in it's place.
drop()
Drops the ninja back down to the ground from a jump faster than usual.
This is done by setting a large downward velocity of 25. Gravity and
other physics will then act as normal to bring the ninja to the ground.
jump()
Makes the ninja jump. This is done by giving the ninja an upwards
velocity of 15.
Also plays the sound file for jumping.
Also plays the sound file for jumping.
reset()
Resets the ninja.
setSounds(sounds)
Sets the sounds for the ninja.
Parameters:
Name | Type | Description |
---|---|---|
sounds |
Array.<p5.SoundFile> | The sounds the ninja makes |
setSprites(spriteIdle, spriteRun, spriteJump)
Sets the sprite images for the idle, running an jumping positions.
Parameters:
Name | Type | Description |
---|---|---|
spriteIdle |
Array.<p5.Image> | The sprite idle images |
spriteRun |
Array.<p5.Image> | The sprite run images |
spriteJump |
Array.<p5.Image> | The sprite jump images |
update()
Updates the objects location during the physics loop. This function will
calculate the height of the object during jumps as well as the spin angle