Class: ObjectShadow

ObjectShadow(objectX, yopt)

Represents a shadow object that follows a character or object in the game.

Constructor

new ObjectShadow(objectX, yopt)

Creates a new shadow object.
Parameters:
Name Type Attributes Default Description
objectX number The initial X coordinate of the shadow
y number <optional>
395 The Y coordinate of the shadow, defaults to 395
Source:

Extends

Members

IMAGES_SHADOW :Array.<string>

Image sequence for shadow animation.
Type:
  • Array.<string>
Source:

SIDE_COLLISION_IGNORE_HEIGHT :number

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

TOP_COLLISION_MARGIN :number

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

accelerationX :number

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

currentImage :number

Index of the current frame in the animation image sequence. Used by playAnimation.
Type:
  • number
Overrides:
Source:

frameCount :number

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

health :number

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

height :number

The height of the shadow in pixels.
Type:
  • number
Source:

hitOnCooldown :boolean

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

imageCache :Object.<string, HTMLImageElement>

A cache of preloaded images for animation or performance. Keys are image paths, values are HTMLImageElement instances.
Type:
  • Object.<string, HTMLImageElement>
Overrides:
Source:

img :HTMLImageElement|undefined

The currently displayed image of the object. Set by loadImage or animation logic.
Type:
  • HTMLImageElement | undefined
Overrides:
Source:

invincibleTime :number

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

invincibleTrigger :number

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

lastHit :number

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

longIdleThreshold :number

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

offset :Object

Defines the hitbox offset for the object. Useful for shrinking or expanding collision boundaries relative to the image.
Type:
  • Object
Overrides:
Source:

otherDirection :boolean

Whether the object is facing left instead of the default right. Used for mirroring the image in rendering logic.
Type:
  • boolean
Overrides:
Source:

skipFrame :number

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

width :number

The width of the shadow in pixels.
Type:
  • number
Source:

Methods

animate()

Starts the animation loop for the shadow. Updates shadow position and animation each frame, synchronized with the display refresh rate.
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.
Overrides:
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.
Overrides:
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.
Overrides:
Source:

draw(ctx)

Draws the current image of the object onto the canvas. This is the standard rendering function used by all drawable game objects.
Parameters:
Name Type Description
ctx CanvasRenderingContext2D The canvas 2D rendering context.
Overrides:
Source:

drawFrame(ctx)

Draws a red outline representing the object's collision hitbox. Only applies to certain object types (Character, Chicken, etc.). Useful for debugging and visualizing hitboxes.
Parameters:
Name Type Description
ctx CanvasRenderingContext2D The canvas 2D rendering context.
Overrides:
Source:

getHitboxBorderBottom() → {number}

Calculates the bottom boundary of the object's hitbox.
Overrides:
Source:
Returns:
Bottom edge including offset.
Type
number

getHitboxBorderLeft() → {number}

Calculates the left boundary of the object's hitbox.
Overrides:
Source:
Returns:
Left edge including offset.
Type
number

getHitboxBorderRight() → {number}

Calculates the right boundary of the object's hitbox.
Overrides:
Source:
Returns:
Right edge including offset.
Type
number

getHitboxBorderTop() → {number}

Calculates the top boundary of the object's hitbox.
Overrides:
Source:
Returns:
Top edge including offset.
Type
number

handleHitCooldown()

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

handleShadow()

Updates the shadow position to match the character's position and plays the shadow animation.
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.
Overrides:
Source:

initShadowLoops()

Initializes the shadow's animation loop. Should be called after the shadow is fully constructed and world is set.
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.
Overrides:
Source:
Returns:
True if the object is in the air.
Type
boolean

isColliding(other) → {boolean}

Checks whether this object is colliding with another object. Uses axis-aligned bounding box (AABB) collision detection with hitbox offsets.
Parameters:
Name Type Description
other DrawableObject The object to check collision against.
Overrides:
Source:
Returns:
True if this object overlaps with the other object.
Type
boolean

isDead() → {boolean}

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

isFalling() → {boolean}

Checks whether the object is currently falling (i.e. moving downward).
Overrides:
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.
Overrides:
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.
Overrides:
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.
Overrides:
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.
Overrides:
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.
Overrides:
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.
Overrides:
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.
Overrides:
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.
Overrides:
Source:

loadImage(path)

Loads a single image and assigns it to the `img` property. Used to display a static image or initialize an animation frame.
Parameters:
Name Type Description
path string The path to the image file.
Overrides:
Source:

loadImages(arr)

Preloads an array of image paths and stores them in the image cache. Used for animations or quick access to different states. Calls the global `countLoadedImages` function on each load.
Parameters:
Name Type Description
arr Array.<string> Array of image file paths to preload.
Overrides:
Source:

moveLeft()

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

moveRight()

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

playAnimation(images)

Cycles through the given image array to create an animation effect. Updates the `img` property to the next frame in the sequence.
Parameters:
Name Type Description
images Array.<string> An array of image paths used for animation frames.
Overrides:
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.
Overrides:
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.
Overrides:
Source:

resetCurrentImage() → {number}

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

resetSkipFrame() → {number}

Resets the skipFrame counter to 0. Used to synchronize animation timing.
Overrides:
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.
Overrides:
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.
Overrides:
Source:

setThrowValues()

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

setWorld(world)

Sets the world reference for the shadow object.
Parameters:
Name Type Description
world World The game world instance
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.
Overrides:
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.
Overrides:
Source:

updateHitTimestamps()

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