Members
canvas
Global canvas and game world variables.
Methods
checkCollisionBottle() → {void}
Checks for collisions between thrown bottles and enemies.
This method iterates over all throwable objects (bottles) and, for each bottle,
checks if it is colliding with any enemy in the current level. If a collision is
detected and the enemy is not already dead:
- The enemy is hit.
- The "chicken hit" sound effect is played.
- The bottle is marked as broken.
- The throwing sound is stopped.
Additionally, if the enemy's height equals 400, the end boss's status bar is updated
to reflect the enemy's current energy.
Returns:
- Type
- void
checkOrientation()
Checks if the device is in portrait mode on mobile with a narrow screen,
displaying a popup if necessary.
getButtons() → {Object}
Gathers HTML button elements by their IDs.
Returns:
An object containing button references.
- Type
- Object
handleButtonPress(button, key, value)
Binds mouse and touch events to a button to update the corresponding key in the keyboard object.
Parameters:
| Name | Type | Description |
|---|---|---|
button |
HTMLElement | The button element. |
key |
string | The key in the keyboard object to update. |
value |
boolean | The value to assign to the key when pressed. |
handleHomeButtonPress(homeButton)
Handles the home button press event by stopping and resetting the game if it is active.
Parameters:
| Name | Type | Description |
|---|---|---|
homeButton |
HTMLElement | The home button element. |
init()
Initializes the game by setting up the canvas, world, button listeners, and orientation checks.
setupButtonListeners()
Retrieves HTML button references and sets up event listeners for them.
setupListenersForButtons(buttons)
Sets up mouse and touch event listeners for each button, linking them to the keyboard object.
Parameters:
| Name | Type | Description |
|---|---|---|
buttons |
Object | An object containing button references. |
toggleGame() → {void}
Starts the game and initializes all required game components.
This method performs the following actions:
- Sets the game state to "started" (startGame = true).
- Resets the game via the ResetManager.
- Starts all intervals required by the game.
- Resets the end boss state (enbossIsDead = false).
- Plays the background sound if it is not muted; otherwise, unmutes it.
- Source:
Returns:
- Type
- void