Class: World

World(canvas, keyboard)

World Represents the main game world, including all game entities, objects, and the rendering loop. Manages game logic such as collision detection, object spawning, and camera movement.

Constructor

new World(canvas, keyboard)

Creates a new game world instance and initializes rendering, entities, and game loop.
Parameters:
Name Type Description
canvas HTMLCanvasElement The HTML canvas element used for rendering the game.
keyboard Keyboard The keyboard input handler for player controls.
Source:

Members

BOSS_TRIGGER_RANGE :number

Horizontal range (in pixels) from the player at which the boss encounter is triggered.
Type:
  • number
Source:

FRAME_TIME_MIN :number

Minimum frame time threshold in milliseconds. Used to determine if animations are in sync.
Type:
  • number
Source:

INTRO_LENGTH :number

Duration of the intro sequence in milliseconds before gameplay resumes.
Type:
  • number
Source:

animationDeltaMax :number

Maximum delta time between frames that exceeded minimum frame time. Used for synchronization checks.
Type:
  • number
Source:

bossHealthBars :Array.<BossHealthBar>

Collection of health bars for bosses, shown during boss fights. Empty if no boss is active.
Type:
  • Array.<BossHealthBar>
Source:

bossTriggered :boolean

Flag indicating whether the boss fight has been triggered.
Type:
  • boolean
Source:

bottleAmmo :number

Current number of bottles (ammunition) available to the player.
Type:
  • number
Source:

bottleBar :BottleBar

UI element showing the player's current bottle ammunition. Each bottle represents 20% of the bar.
Type:
Source:

bottleOnCooldown :boolean

Indicates whether throwing bottles is currently on cooldown. Prevents immediate consecutive throws.
Type:
  • boolean
Source:

cameraX :number

Horizontal camera offset in pixels. Affects how the world is rendered relative to the viewport.
Type:
  • number
Source:

canvas :HTMLCanvasElement

Reference to the HTML canvas element used for rendering.
Type:
  • HTMLCanvasElement
Source:

character :Character

The main player character instance.
Type:
Source:

characterShadow :ObjectShadow

The shadow effect that follows the character.
Type:
Source:

coinAmount :number

Current number of coins the player is holding. This value increases with each collected coin and resets when coins are converted into health after the player has taken damage.
Type:
  • number
Source:

coinBar :CoinBar

UI element showing the player's coin progress towards earning back health. The bar is filled based on World#coinAmount.
Type:
Source:

ctx :CanvasRenderingContext2D

2D rendering context for the canvas, used to draw all visual elements.
Type:
  • CanvasRenderingContext2D
Source:

deltaTime :number

Time elapsed since the last frame in normalized units (delta time). Used for frame-rate independent animations and updates.
Type:
  • number
Source:

endscreenObjects :Array.<DrawableObject>

All objects displayed on the endscreen after the game ends.
Type:
Source:

endscreenTriggered :boolean

Flag indicating whether the endscreen sequence has been triggered.
Type:
  • boolean
Source:

healthBar :HealthBar

UI health bar representing the player's current health.
Type:
Source:

introPlayed :boolean

Flag indicating whether the intro sequence has been played.
Type:
  • boolean
Source:

keyboard :Keyboard

Tracks the state of keyboard inputs for controlling the game.
Type:
Source:

lastFrameMax :number

Timestamp of the last frame that exceeded minimum frame time.
Type:
  • number
Source:

lastFrameTime :number

Timestamp of the last frame for delta time calculation.
Type:
  • number
Source:

level :Level

The current level configuration loaded into the world.
Type:
Source:

minion1IsAlive :boolean

Flags indicating whether specific minion enemies are currently alive. Used to track minion state during boss fights.
Type:
  • boolean
Source:

readyToPlay :boolean

Flag indicating whether the game is in a state where the player can start playing.
Type:
  • boolean
Source:

spawnOnCooldown :boolean

Indicates whether enemy or object spawning is currently on cooldown.
Type:
  • boolean
Source:

statusBars :Array.<(HealthBar|CoinBar|BottleBar)>

Collection of status bars that are always displayed in the UI. Typically includes the health bar, coin bar, and bottle bar.
Type:
Source:

throwableObjects :Array.<ThrowableObject>

All throwable objects currently active in the world, such as bottles in flight.
Type:
Source:

Methods

addObjectsToMap(objects)

Draws all given drawable objects onto the canvas.
Parameters:
Name Type Description
objects Array.<DrawableObject> An array of drawable objects to render.
Source:

addToMap(mo)

Draws a single movable object to the canvas. If the object faces the opposite direction, it is flipped before rendering and flipped back afterward. Also contains a commented-out call to MovableObject#drawFrame for debugging hitboxes.
Parameters:
Name Type Description
mo MovableObject The movable object to render.
Source:

draw()

Renders all visual elements of the world onto the canvas. Clears the canvas, applies camera translations, draws background and movable objects, then renders fixed UI elements and schedules the next frame via `requestAnimationFrame`.
Source:

flipImage(mo)

Flips the drawing of an object horizontally on the canvas. This is done by translating the context by the object's width (to prevent the object from appearing to "teleport" when flipped) and scaling horizontally by `-1`, then inverting its x-position.
Parameters:
Name Type Description
mo MovableObject The movable object to flip.
Source:

flipImageBack(mo)

Restores an object's original horizontal orientation after drawing. Reverses both the x-position inversion and the canvas context transformation applied in World#flipImage, ensuring the object is rendered correctly for subsequent frames.
Parameters:
Name Type Description
mo MovableObject The movable object to restore.
Source:

isInSync() → {boolean}

Checks if the game animations are running in sync with the desired frame rate.
Source:
Returns:
True if animations are in sync, false otherwise.
Type
boolean

reverseSpeed(object)

Reverses the horizontal movement direction of a given object by inverting its speed.
Parameters:
Name Type Description
object MovableObject The object whose speed should be reversed.
Source:

run()

Starts the main game loop, synchronized with the display refresh rate via requestAnimationFrame. Handles core game logic updates including: - Object throwing mechanics - Collision detection - Event triggers - Enemy spawning - Frame timing and synchronization
Source:

setDeltas()

Updates delta time values for frame-rate independent animations. Calculates both regular delta time and maximum animation delta time.
Source:

setWorld()

Links the world instance to its main entities, such as the player character and boss. This allows these entities to access world data and interact with other objects.
Source:

toggleSpriteDirection(object)

Toggles the sprite's facing direction flag for rendering. Switches MovableObject#otherDirection between `true` and `false`.
Parameters:
Name Type Description
object MovableObject The object whose sprite direction should be toggled.
Source: