Class: Cloud

Cloud()

new Cloud()

Source:

Extends

Members

SIDE_COLLISION_IGNORE_HEIGHT :number

Minimum height required to consider side collisions. Prevents unintended side collision logic for very small objects.
Type:
  • number
Inherited From:
Source:

TOP_COLLISION_MARGIN :number

Vertical margin to adjust how precisely top collisions are detected. Helps avoid flickering or false positives.
Type:
  • number
Inherited From:
Source:

accelerationX :number

Horizontal acceleration value (e.g. for running, knockback).
Type:
  • number
Inherited From:
Source:

frameCount :number

Counter for frame-based animation timing and update control. Used to synchronize updates with display refresh rate.
Type:
  • number
Inherited From:
Source:

health :number

Current health value of the object (0–100).
Type:
  • number
Inherited From:
Source:

height :number

Height of the cloud image in pixels. Affects rendering only, not collision (clouds are background elements).
Type:
  • number
Source:

hitOnCooldown :boolean

Indicates whether the object is currently in cooldown and cannot perform certain actions.
Type:
  • boolean
Inherited From:
Source:

invincibleTime :number

Duration (in seconds) the object remains invincible after taking damage.
Type:
  • number
Inherited From:
Source:

invincibleTrigger :number

Timestamp when temporary invincibility was triggered. Used to track invincibility duration.
Type:
  • number
Inherited From:
Source:

lastHit :number

Timestamp of the last time the object was damaged. Used for invincibility or damage cooldown.
Type:
  • number
Inherited From:
Source:

longIdleThreshold :number

Time threshold (in seconds) after which the object enters long idle state. Used to trigger special animations or behaviors.
Type:
  • number
Inherited From:
Source:

skipFrame :number

Counter used to control animation frame skipping.
Type:
  • number
Inherited From:
Source:

speed :number

Movement speed of the cloud in pixels per frame. Creates a slow scrolling background.
Type:
  • number
Source:

width :number

Width of the cloud image in pixels.
Type:
  • number
Source:

x :number

Horizontal position of the cloud on the canvas.
Type:
  • number
Source:

y :number

Vertical position of the cloud on the canvas. Fixed to create a parallax effect.
Type:
  • number
Source:

Methods

animate()

Starts the cloud's movement loop. Continuously moves the cloud to the left. Once it moves off-screen, it wraps around to the right side.
Source:

applyGravity()

Applies gravity to the object by continuously updating its vertical position. Gravity affects the object only when it is in the air or falling. Synchronized with display refresh rate via requestAnimationFrame.
Inherited From:
Source:

applyHorizontalForce()

Applies horizontal force to the object based on its current speed and direction. Used for knockback or sliding effects. Updates every second frame to control motion smoothness. Movement speed is scaled by deltaTime for consistent motion across different frame rates. Stops movement at level boundaries and gradually reduces speed through acceleration.
Inherited From:
Source:

disableHitbox()

Disables the object's hitbox by moving its top offset far outside the visible range. Used to prevent further collisions after death or collection.
Inherited From:
Source:

handleHitCooldown()

Activates a temporary cooldown during which the object cannot be hit again.
Inherited From:
Source:

hit(damage, directionopt, isBossopt)

Processes a hit on the object, applying damage, triggering cooldown, and handling rebound effects if the object survives.
Parameters:
Name Type Attributes Default Description
damage number The amount of damage to apply.
direction string <optional>
"left" The direction the object is knocked back toward after the hit.
isBoss boolean <optional>
false Whether the hit originated from a boss, which increases knockback.
Inherited From:
Source:

isAboveGround() → {boolean}

Checks whether the object is currently in the air. Returns true unless it is on top of an object or resting on the ground. Throwable objects are always considered above ground.
Inherited From:
Source:
Returns:
True if the object is in the air.
Type
boolean

isDead() → {boolean}

Checks whether the object has no health left.
Inherited From:
Source:
Returns:
True if health is 0.
Type
boolean

isFalling() → {boolean}

Checks whether the object is currently falling (i.e. moving downward).
Inherited From:
Source:
Returns:
True if vertical speed is negative.
Type
boolean

isHigher(other) → {boolean}

Checks whether this object is currently above another object, using multiple vertical position snapshots for more accurate detection.
Parameters:
Name Type Description
other DrawableObject The object to compare against.
Inherited From:
Source:
Returns:
True if this object was above the other in recent frames.
Type
boolean

isHurt() → {boolean}

Checks if the object is currently in a hurt (stunned) state. Based on the time passed since the last hit.
Inherited From:
Source:
Returns:
True if the stun duration is still active.
Type
boolean

isInvincible() → {boolean}

Checks if the object is currently invincible. Based on the time passed since invincibility was triggered.
Inherited From:
Source:
Returns:
True if the invincibility duration is still active.
Type
boolean

isLongIdle() → {boolean}

Checks whether the object has been idle for longer than the defined threshold. Based on the time passed since the last user input.
Inherited From:
Source:
Returns:
True if idle duration exceeds the threshold.
Type
boolean

isTouchingFromLeft(other) → {boolean}

Checks whether this object is colliding with another object from the left side. Used to detect left-side obstruction or wall collisions.
Parameters:
Name Type Description
other DrawableObject The object to test collision against.
Inherited From:
Source:
Returns:
True if touching the other object from the left.
Type
boolean

isTouchingFromRight(other) → {boolean}

Checks whether this object is colliding with another object from the right side.
Parameters:
Name Type Description
other DrawableObject The object to test collision against.
Inherited From:
Source:
Returns:
True if touching the other object from the right.
Type
boolean

isTouchingFromTop(other) → {boolean}

Checks whether this object is touching the top surface of another object. Typically used to determine whether the object is standing on something.
Parameters:
Name Type Description
other DrawableObject The object to test collision against.
Inherited From:
Source:
Returns:
True if this object is touching the other from above.
Type
boolean

jump(speedYopt)

Makes the object jump by setting its vertical speed. Also plays the jump sound via the SoundManager.
Parameters:
Name Type Attributes Default Description
speedY number <optional>
15 The upward speed to apply when jumping.
Inherited From:
Source:

moveLeft()

Moves the object to the left by decreasing its x position based on speed.
Inherited From:
Source:

moveRight()

Moves the object to the right by increasing its x position based on speed.
Inherited From:
Source:

playStateAnimation(images, frameDelay)

Plays an animation sequence at the defined frame delay. Increments the frame counter after each call.
Parameters:
Name Type Description
images Array.<string> Array of image paths representing the animation.
frameDelay number Delay in frames between each animation step.
Inherited From:
Source:

rebound(direction, momentumopt, isBossopt)

Applies a rebound force to the object based on the given knockback direction. Simulates pushback after being hit.
Parameters:
Name Type Attributes Default Description
direction string The direction to push the object ("left", "right", or "up-left").
momentum number <optional>
15 Base impulse applied to speed components.
isBoss boolean <optional>
false If true, uses a stronger momentum for boss hits.
Inherited From:
Source:

resetCurrentImage() → {number}

Resets the animation frame index to 0. Typically called when switching animations.
Inherited From:
Source:
Returns:
The new frame index (0).
Type
number

resetSkipFrame() → {number}

Resets the skipFrame counter to 0. Used to synchronize animation timing.
Inherited From:
Source:
Returns:
The new skipFrame value (0).
Type
number

secondsSince(startTimestamp) → {number}

Calculates the number of seconds that have passed since a given timestamp.
Parameters:
Name Type Description
startTimestamp number Timestamp in milliseconds to compare against the current time.
Inherited From:
Source:
Returns:
Seconds that have passed since the given timestamp.
Type
number

setHorizontalMovement()

Updates horizontal position of a thrown object. Movement is synchronized with display refresh rate for smooth animation.
Inherited From:
Source:

setThrowValues()

Sets default size and initial speed values for a thrown object.
Inherited From:
Source:

takeDamage(damage)

Applies damage to the object and ensures health does not drop below zero.
Parameters:
Name Type Description
damage number The amount of damage to subtract from health.
Inherited From:
Source:

throw()

Executes the throwing behavior of the object. Initializes size and speed, applies direction, gravity and plays sound. Movement is synchronized with display refresh rate.
Inherited From:
Source:

updateHitTimestamps()

Updates all relevant timestamps for hit, invincibility, and input.
Inherited From:
Source:

Cloud(x, num)

new Cloud(x, num)

Creates a new cloud object with the specified horizontal position and image variant.
Parameters:
Name Type Description
x number Initial horizontal position of the cloud.
num number Number of the cloud image variant (e.g. 1, 2, 3...).
Source:

Members

SIDE_COLLISION_IGNORE_HEIGHT :number

Minimum height required to consider side collisions. Prevents unintended side collision logic for very small objects.
Type:
  • number
Inherited From:
Source:

TOP_COLLISION_MARGIN :number

Vertical margin to adjust how precisely top collisions are detected. Helps avoid flickering or false positives.
Type:
  • number
Inherited From:
Source:

accelerationX :number

Horizontal acceleration value (e.g. for running, knockback).
Type:
  • number
Inherited From:
Source:

frameCount :number

Counter for frame-based animation timing and update control. Used to synchronize updates with display refresh rate.
Type:
  • number
Inherited From:
Source:

health :number

Current health value of the object (0–100).
Type:
  • number
Inherited From:
Source:

height :number

Height of the cloud image in pixels. Affects rendering only, not collision (clouds are background elements).
Type:
  • number
Source:

hitOnCooldown :boolean

Indicates whether the object is currently in cooldown and cannot perform certain actions.
Type:
  • boolean
Inherited From:
Source:

invincibleTime :number

Duration (in seconds) the object remains invincible after taking damage.
Type:
  • number
Inherited From:
Source:

invincibleTrigger :number

Timestamp when temporary invincibility was triggered. Used to track invincibility duration.
Type:
  • number
Inherited From:
Source:

lastHit :number

Timestamp of the last time the object was damaged. Used for invincibility or damage cooldown.
Type:
  • number
Inherited From:
Source:

longIdleThreshold :number

Time threshold (in seconds) after which the object enters long idle state. Used to trigger special animations or behaviors.
Type:
  • number
Inherited From:
Source:

skipFrame :number

Counter used to control animation frame skipping.
Type:
  • number
Inherited From:
Source:

speed :number

Movement speed of the cloud in pixels per frame. Creates a slow scrolling background.
Type:
  • number
Source:

width :number

Width of the cloud image in pixels.
Type:
  • number
Source:

x :number

Horizontal position of the cloud on the canvas.
Type:
  • number
Source:

y :number

Vertical position of the cloud on the canvas. Fixed to create a parallax effect.
Type:
  • number
Source:

Methods

animate()

Starts the cloud's movement loop. Continuously moves the cloud to the left. Once it moves off-screen, it wraps around to the right side.
Source:

applyGravity()

Applies gravity to the object by continuously updating its vertical position. Gravity affects the object only when it is in the air or falling. Synchronized with display refresh rate via requestAnimationFrame.
Inherited From:
Source:

applyHorizontalForce()

Applies horizontal force to the object based on its current speed and direction. Used for knockback or sliding effects. Updates every second frame to control motion smoothness. Movement speed is scaled by deltaTime for consistent motion across different frame rates. Stops movement at level boundaries and gradually reduces speed through acceleration.
Inherited From:
Source:

disableHitbox()

Disables the object's hitbox by moving its top offset far outside the visible range. Used to prevent further collisions after death or collection.
Inherited From:
Source:

handleHitCooldown()

Activates a temporary cooldown during which the object cannot be hit again.
Inherited From:
Source:

hit(damage, directionopt, isBossopt)

Processes a hit on the object, applying damage, triggering cooldown, and handling rebound effects if the object survives.
Parameters:
Name Type Attributes Default Description
damage number The amount of damage to apply.
direction string <optional>
"left" The direction the object is knocked back toward after the hit.
isBoss boolean <optional>
false Whether the hit originated from a boss, which increases knockback.
Inherited From:
Source:

isAboveGround() → {boolean}

Checks whether the object is currently in the air. Returns true unless it is on top of an object or resting on the ground. Throwable objects are always considered above ground.
Inherited From:
Source:
Returns:
True if the object is in the air.
Type
boolean

isDead() → {boolean}

Checks whether the object has no health left.
Inherited From:
Source:
Returns:
True if health is 0.
Type
boolean

isFalling() → {boolean}

Checks whether the object is currently falling (i.e. moving downward).
Inherited From:
Source:
Returns:
True if vertical speed is negative.
Type
boolean

isHigher(other) → {boolean}

Checks whether this object is currently above another object, using multiple vertical position snapshots for more accurate detection.
Parameters:
Name Type Description
other DrawableObject The object to compare against.
Inherited From:
Source:
Returns:
True if this object was above the other in recent frames.
Type
boolean

isHurt() → {boolean}

Checks if the object is currently in a hurt (stunned) state. Based on the time passed since the last hit.
Inherited From:
Source:
Returns:
True if the stun duration is still active.
Type
boolean

isInvincible() → {boolean}

Checks if the object is currently invincible. Based on the time passed since invincibility was triggered.
Inherited From:
Source:
Returns:
True if the invincibility duration is still active.
Type
boolean

isLongIdle() → {boolean}

Checks whether the object has been idle for longer than the defined threshold. Based on the time passed since the last user input.
Inherited From:
Source:
Returns:
True if idle duration exceeds the threshold.
Type
boolean

isTouchingFromLeft(other) → {boolean}

Checks whether this object is colliding with another object from the left side. Used to detect left-side obstruction or wall collisions.
Parameters:
Name Type Description
other DrawableObject The object to test collision against.
Inherited From:
Source:
Returns:
True if touching the other object from the left.
Type
boolean

isTouchingFromRight(other) → {boolean}

Checks whether this object is colliding with another object from the right side.
Parameters:
Name Type Description
other DrawableObject The object to test collision against.
Inherited From:
Source:
Returns:
True if touching the other object from the right.
Type
boolean

isTouchingFromTop(other) → {boolean}

Checks whether this object is touching the top surface of another object. Typically used to determine whether the object is standing on something.
Parameters:
Name Type Description
other DrawableObject The object to test collision against.
Inherited From:
Source:
Returns:
True if this object is touching the other from above.
Type
boolean

jump(speedYopt)

Makes the object jump by setting its vertical speed. Also plays the jump sound via the SoundManager.
Parameters:
Name Type Attributes Default Description
speedY number <optional>
15 The upward speed to apply when jumping.
Inherited From:
Source:

moveLeft()

Moves the object to the left by decreasing its x position based on speed.
Inherited From:
Source:

moveRight()

Moves the object to the right by increasing its x position based on speed.
Inherited From:
Source:

playStateAnimation(images, frameDelay)

Plays an animation sequence at the defined frame delay. Increments the frame counter after each call.
Parameters:
Name Type Description
images Array.<string> Array of image paths representing the animation.
frameDelay number Delay in frames between each animation step.
Inherited From:
Source:

rebound(direction, momentumopt, isBossopt)

Applies a rebound force to the object based on the given knockback direction. Simulates pushback after being hit.
Parameters:
Name Type Attributes Default Description
direction string The direction to push the object ("left", "right", or "up-left").
momentum number <optional>
15 Base impulse applied to speed components.
isBoss boolean <optional>
false If true, uses a stronger momentum for boss hits.
Inherited From:
Source:

resetCurrentImage() → {number}

Resets the animation frame index to 0. Typically called when switching animations.
Inherited From:
Source:
Returns:
The new frame index (0).
Type
number

resetSkipFrame() → {number}

Resets the skipFrame counter to 0. Used to synchronize animation timing.
Inherited From:
Source:
Returns:
The new skipFrame value (0).
Type
number

secondsSince(startTimestamp) → {number}

Calculates the number of seconds that have passed since a given timestamp.
Parameters:
Name Type Description
startTimestamp number Timestamp in milliseconds to compare against the current time.
Inherited From:
Source:
Returns:
Seconds that have passed since the given timestamp.
Type
number

setHorizontalMovement()

Updates horizontal position of a thrown object. Movement is synchronized with display refresh rate for smooth animation.
Inherited From:
Source:

setThrowValues()

Sets default size and initial speed values for a thrown object.
Inherited From:
Source:

takeDamage(damage)

Applies damage to the object and ensures health does not drop below zero.
Parameters:
Name Type Description
damage number The amount of damage to subtract from health.
Inherited From:
Source:

throw()

Executes the throwing behavior of the object. Initializes size and speed, applies direction, gravity and plays sound. Movement is synchronized with display refresh rate.
Inherited From:
Source:

updateHitTimestamps()

Updates all relevant timestamps for hit, invincibility, and input.
Inherited From:
Source: