Constructor
new CollisonManager(world)
Creates a CollisonManager instance.
Parameters:
| Name | Type | Description |
|---|---|---|
world |
Object | The game world instance. |
Methods
checkCollision()
Checks collisions between the character and enemies.
If the character jumps on an enemy, the enemy is hit.
Otherwise, the character takes damage and is pushed back.
checkCollisionBottleCollectib()
Collects bottles when the character collides with them.
Increases the bottle count up to a maximum of 5.
checkCollisionButtonToMouse()
Checks if the mouse is hovering over any UI icons on the canvas and updates the cursor style accordingly.
checkCollisionCoinCollectib()
Collects coins when the character collides with them.
Increases the coin count up to a maximum of 5.
checkCollisionEndbos()
Checks collisions with the endboss.
Sets the endboss to attack mode if colliding, and checks if the endboss is dead.
checkCollisionSalsaStore()
Implements the purchase logic for the Salsa Store.
If the character is colliding with the store and has enough coins,
they can purchase a bottle (if below the maximum bottle count).
checkIconsHoverState(icons) → {boolean}
Iterates through icons to check if the mouse is hovering over any of them.
Special handling is applied for the restartGameIcon, which only returns a hover state if:
- this.world.character.energy <= 0
- this.world.startGame is true
- this.world.enbossIsDead is true
Parameters:
| Name | Type | Description |
|---|---|---|
icons |
Array.<DrawableObject> | The array of icons to evaluate. |
Returns:
True if the mouse is hovering over any icon, otherwise false.
- Type
- boolean
checkThrowobjekt()
Handles the bottle-throwing logic.
Checks if a bottle can be thrown and prepares the throw if possible.
checkbottleIsBroken()
Checks if thrown bottles are broken.
Stops the throw sound, plays the bottle broken sound, and removes the broken bottle from the game.
getRelevantIcons() → {Array.<DrawableObject>}
Returns an array of icons to be checked for hover state.
Returns:
Icons that should respond to mouse hover.
- Type
- Array.<DrawableObject>
handleCharacterCollision()
Handles the collision when the character is hit.
Applies a cooldown so that the character only takes damage once every 500ms.
handleEnemyCollision(enemy)
Handles the collision when the enemy is hit.
Parameters:
| Name | Type | Description |
|---|---|---|
enemy |
Object | The enemy object. |
hasValidPosition(icon) → {boolean}
Checks if an icon has valid x/y properties for collision detection.
Parameters:
| Name | Type | Description |
|---|---|---|
icon |
DrawableObject | The icon to check. |
Returns:
True if the icon has valid position properties, otherwise false.
- Type
- boolean
isMouseOverIcon(icon) → {boolean}
Determines if the mouse coordinates are currently over the icon's bounds.
Parameters:
| Name | Type | Description |
|---|---|---|
icon |
DrawableObject | The icon to check. |
Returns:
True if the mouse is over the icon, otherwise false.
- Type
- boolean
shouldHitEnemy(enemy) → {boolean}
Determines if the enemy should be hit based on the character's position.
Parameters:
| Name | Type | Description |
|---|---|---|
enemy |
Object | The enemy object. |
Returns:
True if the enemy should be hit, otherwise false.
- Type
- boolean
shouldSkipIcon(icon) → {boolean}
Determines whether to skip checking a particular icon based on the current game state.
Parameters:
| Name | Type | Description |
|---|---|---|
icon |
DrawableObject | The icon to evaluate. |
Returns:
True if the icon should be skipped, otherwise false.
- Type
- boolean
trackMousePosition(event)
Tracks and stores the mouse position relative to the canvas.
Parameters:
| Name | Type | Description |
|---|---|---|
event |
MouseEvent | The mousemove event. |
updateCursor(isHovering)
Updates the canvas cursor style based on whether the mouse is hovering over a relevant icon.
Parameters:
| Name | Type | Description |
|---|---|---|
isHovering |
boolean | True if the mouse is hovering over an icon, otherwise false. |