Members
REQUIRED_IMAGE_COUNT :number
The total number of images required before the game can start.
Type:
- number
- Source:
canvas :HTMLCanvasElement
The game's rendering surface
Type:
- HTMLCanvasElement
- Source:
intervalIds :Array.<number>
Stores all interval IDs created via setStoppableInterval.
Used to manage and clear all game intervals when needed.
Type:
- Array.<number>
- Source:
keyboard :Keyboard
Stores the current input state of all relevant keys
Type:
- Source:
lastInput :number
Timestamp of the most recent user interaction.
Used for detecting idle time (e.g. long idle animation).
Starts with a 15s offset to delay initial idle checks.
Type:
- number
- Source:
level1 :Level
The current level of the game.
Initialized by initLevel.
Type:
- Source:
loadedImageCount :number
Counter for tracking how many images have finished loading.
Used to control loading screens or game start conditions.
Type:
- number
- Source:
rAFIds :Array.<number>
Stores all requestAnimationFrame IDs created via setStoppableRAF.
Used to manage and cancel all animation frames when needed.
Type:
- Array.<number>
- Source:
world :World
The main game world instance
Type:
- Source:
worldIsReady :boolean
Flag indicating whether the world is fully initialized and ready for animation loops.
Used to synchronize the start of various animation and game loops.
Type:
- boolean
- Source:
Methods
blurButton(selector)
Removes focus from all elements matching the given selector.
Parameters:
Name | Type | Description |
---|---|---|
selector |
string | A CSS selector (e.g. '.btn') |
- Source:
despawnObject(object, array, delayopt)
Removes an object from an array, optionally after a delay.
If a delay is specified, removal is deferred using setTimeout.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
object |
Object | The object to remove. | ||
array |
Array | The array from which to remove the object. | ||
delay |
number |
<optional> |
0 | Optional delay in milliseconds before removal. |
- Source:
enterFullscreen(element)
Requests fullscreen mode for the given element.
Uses vendor-prefixed methods where necessary for legacy support.
Parameters:
Name | Type | Description |
---|---|---|
element |
HTMLElement | The element to enter fullscreen mode. |
- Source:
exitFullscreen()
Exits fullscreen mode using the appropriate method for the browser.
- Source:
getElementByIdHelper(id) → {HTMLElement}
Shorthand for document.getElementById.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The ID of the HTML element to retrieve. |
- Source:
Returns:
The matching element.
- Type
- HTMLElement
handleImageLoad()
Increments the loaded image counter and checks if all required images are loaded.
Once loading is complete, hides the loading screen, starts background music,
and resets the counter for future loading sequences.
- Source:
hideControlButtons()
Hides the on-screen control buttons by adding the 'd-none' CSS class
to the element with the 'controls' class.
- Source:
hideElementById(id)
Adds the 'd-none' class to the element with the given ID using getElementByIdHelper.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The ID of the HTML element to hide. |
- Source:
hideEndscreenButtons()
Hides the endscreen buttons by adding the 'd-none' CSS class
to the element with the 'endscreen-menu' class.
- Source:
hideGameMenuButtons()
Hides the game menu buttons by adding the 'd-none' CSS class
to the element with the 'game-menu' class.
- Source:
hideInstructions()
Shows the game info and hides the control instructions.
- Updates the toggle button text to "CONTROLS"
- Shows the info section
- Hides the input instructions
- Sets controlsAreDisplayed flag to false
- Source:
hideLoadingScreen()
Hides the loading screen by adding the 'd-none' CSS class
to the element with the 'loading-screen' class.
- Source:
hideStartScreen()
Hides the start screen UI element.
Typically used at the beginning of the game to transition into gameplay.
- Source:
init()
Initializes the game by assigning the canvas element
and triggering the initial UI instruction toggle sequence.
Called once on page load.
- Source:
initMuteDefaultUsingStorage()
Initializes the mute state based on localStorage settings.
- Checks for stored mute state in localStorage
- If no stored state exists, mutes all sounds and saves the state
- If state exists, loads it and applies the appropriate mute setting
- Updates the mute button visual state to match current settings
- Source:
initializePresentation()
Initializes the visual game state including UI reset and input timing.
Prevents premature long idle detection by delaying the idle timer.
- Source:
initializeWorld()
Initializes the game world and its level data,
then creates a new World instance using the canvas and keyboard input.
- Source:
intiLevel()
Initializes the first level of the game.
Populates it with enemies, background objects, collectibles, obstacles, and clouds.
Assigns the result to the global variable level1.
- Source:
loadFromLocalStorage()
Loads sound settings from local storage and restores them.
Applies the mute state and reconstructs the volume map for all sounds.
- Source:
prepareGameState()
Resets essential game state components before a new round starts.
Clears previous intervals, restores local storage data, and stops all sounds.
- Source:
quitDuringPlay()
Quits the game during active play unless the endscreen has already been triggered.
- Source:
quitGame()
Quits the game and returns to the start screen.
Stops all sounds and intervals, resets the UI, and re-enables start interaction.
- Source:
removeFromArray(object, array)
Removes the specified object from the given array.
If the object is not found, nothing happens.
Parameters:
Name | Type | Description |
---|---|---|
object |
Object | The object to remove. |
array |
Array | The array to modify. |
- Source:
resetUi()
Resets the user interface to the default gameplay view.
- Shows game menu buttons
- Hides endscreen buttons
- Updates the mute button visual state
- If touch controls are appropriate, displays control buttons and toggles instructions
- Source:
restartDuringPlay()
Restarts the game during active play unless the endscreen has already been triggered.
- Source:
saveToLocalStorage()
Saves the current sound settings to local storage.
Stores the mute state and individual sound volumes as serialized JSON.
- Source:
setStoppableInterval(fn, time)
Creates a setInterval and registers its ID for global tracking.
This allows all such intervals to be stopped later via stopAllLoops().
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function to execute repeatedly. |
time |
number | The interval delay in milliseconds. |
- Source:
setStoppableRAF(fn) → {void}
Creates a requestAnimationFrame call and registers its ID for global tracking.
This allows all animation frames to be cancelled when needed.
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function to execute on the next animation frame. |
- Source:
Returns:
- Type
- void
shouldShowTouchControls() → {boolean}
Determines whether the device supports touch input.
- Source:
Returns:
True if the device is touch-capable, false otherwise.
- Type
- boolean
showControlButtons()
Shows the on-screen control buttons by removing the 'd-none' CSS class
from the element with the 'controls' class.
- Source:
showElementById(id)
Removes the 'd-none' class from the element with the given ID using getElementByIdHelper.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The ID of the HTML element to show. |
- Source:
showEndscreenButtons()
Shows the endscreen buttons by removing the 'd-none' CSS class
from the element with the 'endscreen-menu' class.
- Source:
showGameMenuButtons()
Shows the game menu buttons by removing the 'd-none' CSS class
from the element with the 'game-menu' class.
- Source:
showInstructions()
Shows the control instructions and hides the game info.
- Updates the toggle button text to "GAME INFO"
- Hides the info section
- Shows the input instructions
- Sets controlsAreDisplayed flag to true
- Source:
showKeyboardInstructions()
Sets the instruction image to show keyboard control instructions.
Updates the `src` attribute of the element with ID 'input-instructions'
to display the image for keyboard-based input.
- Source:
showLoadingScreen()
Shows the loading screen by removing the 'd-none' CSS class
from the element with the 'loading-screen' class.
- Source:
showTouchInstructions()
Sets the instruction image to show touch control instructions.
Updates the `src` attribute of the element with ID 'input-instructions'
to display the image for touch-based input.
- Source:
startGame()
Starts the game by preparing the state, initializing the world,
and setting up all presentation-related elements such as sound, UI, and idle timing.
- Source:
stopAllLoops()
Clears all active animation frames and intervals.
Cancels both setInterval-based timers and requestAnimationFrame loops
to ensure clean game state transitions.
- Source:
toggleFullscreen()
Toggles fullscreen mode on or off for the element with ID 'fullscreen'.
Enters fullscreen if not already in it, otherwise exits fullscreen.
Also removes focus from any button with class 'btn'.
- Source:
toggleInfoAndControls()
Toggles between displaying game info and control instructions.
Uses the controlsAreDisplayed flag to determine which view to show.
- Source:
toggleInstructions()
Displays the appropriate control instructions based on input type.
- If the device supports touch, shows touch instructions.
- Otherwise, shows keyboard instructions.
- Source:
updateMuteButtonState()
Updates the visual state of the mute button based on the current mute status.
Adds or removes the 'btn-muted' CSS class on the mute button element
to reflect whether sound is currently muted.
- Source: