new World()
Manages the entire game world, including character, level, audio, collisions, and rendering.
- Source:
Members
CoinCount :number
The current count of coins collected.
Type:
- number
- Source:
Intervals :Array.<number>
Array of interval IDs used for game loops and animations.
Type:
- Array.<number>
- Source:
bottleCount :number
The current count of bottles available to throw.
Type:
- number
- Source:
camera_x :number
Horizontal camera offset for scrolling effects.
Type:
- number
- Source:
canvas :HTMLCanvasElement
The HTML canvas element used for rendering.
Type:
- HTMLCanvasElement
- Source:
character :Character
The main character of the game.
Type:
- Source:
ctx :CanvasRenderingContext2D
The 2D drawing context of the canvas.
Type:
- CanvasRenderingContext2D
- Source:
keyboard :Object
Object tracking keyboard input states.
Type:
- Object
- Source:
level :Level
The level configuration for the game.
Type:
- Source:
resetManager :AudioManager
Manages all game audio, including sound effects and background music.
Type:
- Source:
showStartscreen :boolean
Flag to determine if the start screen should be displayed.
Type:
- boolean
- Source:
startGame :boolean
Flag indicating if the game has started.
Type:
- boolean
- Source:
throwTimeout :boolean
Flag to prevent immediate successive bottle throws.
Type:
- boolean
- Source:
throwableObjects :Array.<Throwableobject>
Array containing objects that the character can throw.
Type:
- Array.<Throwableobject>
- Source:
Methods
calculateXPosition() → {number}
Calculates the X position for throwing a bottle based on the character's direction.
- Source:
Returns:
The calculated X position.
- Type
- number
canThrowBottle() → {boolean}
Checks if the player can throw a bottle by verifying key input, inventory, and timeout.
- Source:
Returns:
True if a bottle can be thrown; otherwise, false.
- Type
- boolean
createBottle(xPosition)
Creates a new bottle at the specified X position and adds it to the throwable objects.
Parameters:
| Name | Type | Description |
|---|---|---|
xPosition |
number | The X position for the new bottle. |
- Source:
initializeManager()
Initializes managers for game reset, collision detection, audio, and drawing.
- Source:
prepareThrow()
Executes the steps needed to throw a bottle and updates relevant properties.
- Source:
pushInterval()
Collects enemy movement intervals so they can be managed later.
- Source:
run()
Runs the main game loop, continuously checking for collisions and other game interactions.
- Source:
setThrowTimeout()
Sets a timeout to prevent immediate successive bottle throws.
- Source:
setWorld()
Assigns this World instance to various game objects so they can access global properties.
- Source:
setWorldMobileIcon()
Assigns this World instance to mobile-specific game objects so they can access global properties.
- Source:
startAllIntervals()
Starts intervals for enemies, clouds, coins, and the character if the game has begun.
- Source:
stopAllIntervals()
Stops all intervals currently stored in the Intervals array.
- Source:
updateBottleCount()
Decrements the bottle count and updates the corresponding status bar.
- Source: