Constructor
new Bird(scene)
Sets up all default values for all class variables
Parameters:
| Name | Type | Description |
|---|---|---|
scene |
the Phaser.Scene object used for adding images/sprites/physics/etc... |
- Source:
Methods
checkBoundaries()
This method makes sure that whenever the bird hits the floor, it will fire the death event. This used to
also check for the ceiling, however a newer implementation of that feature has been made which uses the default
Phaser physics to automatically prevent the bird from escaping the ceiling.
- Source:
create()
This method is called once and is used to create animations and gameObjects such as the bird.
- Source:
createHitSprite()
This method will create a sprite game-object which is used as a feedback animation for when
the bird dies/hits a pipe or the ground.
- Source:
getIdleAnimOffset(time) → {number}
Do not use this function any longer. This was the original way that the bird animated up and down
in its IDLE state. However, a better more organic implementation of an IDLE state animation has been
set up.
Parameters:
| Name | Type | Description |
|---|---|---|
time |
the time from when the game started and is given from the Phaser update method |
- Deprecated:
- Yes
- Source:
Returns:
- the offset to use either 1 or -1
- Type
- number
handleTilt(time)
This method is for rotating the bird to simulate a more organic movement.
Parameters:
| Name | Type | Description |
|---|---|---|
time |
the time from when the game started. |
- Source:
jump()
This method will reset the tilt delay start. It will give the physics body a velocityY, and will play the flap animation
- Source:
onJump()
This method is called whenever the player presses the space-bar. It's named onJump in order to
allow for future implementation of different controls such as a mouse click. This method will
check the current state of the game and if it is IDLE, it will call the initiate and jump methods
to simulate the bird jumping and starts the game loop. If the state is ALIVE, then we know that
the bird is no longer in the IDLE state and therefore will only jump. The last thing that this method
will do is prevent the player from holding down the inputs which would break the game by making it
super easy to navigate the pipes.
- Source:
onJumpRelease()
Whenever the given input has been unpressed, for example, taking finger off of the mouse button, it will set has jumped to false,
allowing the bird to jump again.
- Source:
preload()
This function is called before anything is drawn on the canvas.
This allows for asset preloading which prevents anything from drawing without
it first loading the asset.
Here it is loading the hit-spritesheet.png image from the assets folder
- Source:
resetG()
This method is used to reset the bird object to its original position/values. Used
for when the bird has "died"/collided with the floor or a pipe
- Source:
setupBird()
This function instantiates a sprite image of a bird and sets up all of the default values.
- Source:
setupIdle()
This method sets up the bird object for it's idle state. It will setup it's looping flying animation,
and will change the currentState class variable to IDLE
- Source:
startG()
This method should be called to start the game loop for the bird game-object.
It will set the class variable currentState to ALIVE and will set up the bird
game-object, so it will have gravity, will be able to collide, and will respond to player inputs.
- Source:
stopG()
This method is called whenever the bird has died by either a collision from the pipes or the floor.
It will set the class variable currentState to DEAD. It will position the hitSprite game-object and will play the hit animation using
the hitSprite game-object.
- Source:
stopIdleTween()
In case the bird had to stop animating, this method will kill the current idle animation
- Source:
update()
The update method is called every frame and if the currentState variable = RUNNING, it calls the
handlePipePool() method to check if pipe needs to be repositioned
and updating the position if needed.
- Source: