new Chicken()
- Source:
Extends
Members
IMAGES_DEAD :Array.<string>
Image path for the dead chicken sprite.
Type:
- Array.<string>
- Source:
IMAGES_WALKING :Array.<string>
Array of image paths for the chicken's walking 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
- 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
Rate at which vertical speed changes.
Used for gravity calculations.
Type:
- number
- 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:
frameDelayWalking :number
Delay in frames between changes in the walking animation.
Lower values result in faster animation.
Type:
- number
- Source:
health :number
The amount of health the chicken has.
Once it reaches 0, the chicken is considered dead.
Type:
- number
- Overrides:
- Source:
height :number
Height of the chicken in pixels.
Affects rendering and collision boundaries.
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:
isMarkedForDespawn :boolean
Indicates whether the chicken should be removed from the game world.
Used for despawn logic after death or leaving the screen.
Type:
- boolean
- Source:
isMinion :boolean
Indicates if this chicken is a minion spawned by the endboss.
Affects behavior and despawn logic.
Type:
- boolean
- Source:
lastContactWith :Object.<string, Object>
Tracks the last objects this chicken had contact with.
Used to prevent multiple collision responses.
Type:
- Object.<string, Object>
- 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 pixel offsets for more accurate collision detection.
These values shrink the hitbox compared to the visual image.
Type:
- Object
- Source:
skipFrame :number
Counter used to control animation frame skipping.
Type:
- number
- Overrides:
- Source:
speed :number
Movement speed of the chicken.
Affects how fast it walks.
Type:
- number
- Source:
speedY :number
Initial vertical velocity for jumps.
Negative values move upward.
Type:
- number
- Source:
width :number
Width of the chicken in pixels.
Affects rendering and collision boundaries.
Type:
- number
- Source:
x :number
Horizontal position of the chicken on the canvas.
Can be randomized to space out enemies.
Type:
- number
- Source:
y :number
Vertical position of the chicken on the canvas.
Default is 375 (ground level).
Type:
- number
- Source:
Methods
animate()
Starts the chicken's animation loop.
Updates the character state and triggers the corresponding behavior.
Synchronized with display refresh rate via requestAnimationFrame.
- 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:
handleDeadChicken()
Handles the behavior of the chicken in the "dead" state.
Plays the dead animation and disables the hitbox for collision detection.
- Source:
handleHitCooldown()
Activates a temporary cooldown during which the object cannot be hit again.
- Inherited From:
- Source:
handleWalkingChicken()
Handles the behavior of the chicken in the "walking" state.
Moves the chicken to the left and plays walking animation.
Animation updates are synchronized with world timing for consistent speed.
- 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:
initChickenLoops()
Initializes the chicken's animation and physics loops.
Waits for world initialization before starting animations.
Uses recursive setTimeout for initialization retry.
- 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:
updateState()
Updates the current state of the chicken based on its internal status.
Sets the state to "dead" if the chicken is dead, otherwise to "walking".
- Source: