new ThrowableObject()
- Source:
Extends
Members
IMAGES_ROTATION :Array.<string>
Animation frames for the bottle rotating while in the air.
Type:
- Array.<string>
- Source:
IMAGES_SPLASH :Array.<string>
Animation frames for the splash effect when the bottle hits something.
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
- 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:
acceleration :number
Vertical acceleration applied to the object (gravity effect).
Type:
- number
- Source:
accelerationX :number
Horizontal acceleration value (e.g. for running, knockback).
Type:
- number
- Inherited From:
- Source:
currentImage :number
Index of the current frame in the animation image sequence.
Used by playAnimation.
Type:
- number
- Inherited From:
- Source:
damage :number
Damage dealt by the thrown bottle upon impact.
Type:
- number
- Source:
frameCount :number
Counter for frame-based animation timing and update control.
Used to synchronize updates with display refresh rate.
Type:
- number
- Overrides:
- Source:
frameDelayIsBroken :number
Frame delay between splash animation frames when broken.
Controls animation speed.
Type:
- number
- Source:
health :number
Current health value of the object (0–100).
Type:
- number
- Inherited From:
- Source:
hitOnCooldown :boolean
Indicates whether the object is currently in cooldown and cannot perform certain actions.
Type:
- boolean
- Inherited From:
- 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>
- Inherited From:
- Source:
img :HTMLImageElement|undefined
The currently displayed image of the object.
Set by loadImage or animation logic.
Type:
- HTMLImageElement | undefined
- 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:
isBroken :number
Vertical acceleration applied to the object (gravity effect).
Type:
- number
- 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:
offset :Object
Defines the hitbox offset for collision detection.
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
- Inherited From:
- Source:
skipFrame :number
Counter used to control animation frame skipping.
Type:
- number
- Overrides:
- Source:
x :number
Horizontal position of the bottle.
Type:
- number
- Source:
y :number
Vertical position of the bottle.
Type:
- number
- Source:
Methods
animate()
Starts the animation loop for the throwable object.
Updates the current state and triggers corresponding animation logic.
Synchronized with display refresh rate via requestAnimationFrame.
Updates state and animations every third frame when in sync.
- 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:
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. |
- Inherited From:
- 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. |
- Inherited From:
- Source:
getHitboxBorderBottom() → {number}
Calculates the bottom boundary of the object's hitbox.
- Inherited From:
- Source:
Returns:
Bottom edge including offset.
- Type
- number
getHitboxBorderLeft() → {number}
Calculates the left boundary of the object's hitbox.
- Inherited From:
- Source:
Returns:
Left edge including offset.
- Type
- number
getHitboxBorderRight() → {number}
Calculates the right boundary of the object's hitbox.
- Inherited From:
- Source:
Returns:
Right edge including offset.
- Type
- number
getHitboxBorderTop() → {number}
Calculates the top boundary of the object's hitbox.
- Inherited From:
- Source:
Returns:
Top edge including offset.
- Type
- number
handleBroken()
Handles the splash animation when the bottle is broken.
Plays the splash animation frames with a controlled frame delay.
- Source:
handleHitCooldown()
Activates a temporary cooldown during which the object cannot be hit again.
- Inherited From:
- Source:
handleThrown()
Handles the rotation animation while the bottle is flying through the air.
- 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
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. |
- Inherited From:
- Source:
Returns:
True if this object overlaps with the other object.
- 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:
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. |
- Inherited From:
- 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. |
- 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:
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. |
- 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:
updateState()
Updates the current animation state based on whether the bottle is broken.
Resets animation counters if the state has changed.
- Source: