Class: Throwableobject

Throwableobject()

new Throwableobject()

Represents a throwable salsa bottle in the game, extending the MovableObject class. It can be thrown in a chosen direction, rotates while in the air, and splashes upon hitting the ground.
Source:

Extends

Members

IMAGES_ROTATION :Array.<string>

An array of image paths for the bottle's rotation animation.
Type:
  • Array.<string>
Source:

IMAGES_SPLASH :Array.<string>

An array of image paths for the bottle's splash animation upon impact.
Type:
  • Array.<string>
Source:

acceleration :number

Acceleration used for gravity effects.
Type:
  • number
Inherited From:
Source:

bottleIsBroken :boolean

Indicates whether the bottle has broken (splash animation completed).
Type:
  • boolean
Source:

currentImage :number

Index of the current image in the animation cycle.
Type:
  • number
Inherited From:
Source:

enemyIsDead :boolean

Indicates if the enemy is dead. Not used for characters.
Type:
  • boolean
Inherited From:
Source:

energy :number

The energy level of the object.
Type:
  • number
Inherited From:
Source:

height :number

The height of the drawable object.
Type:
  • number
Overrides:
Source:

imageCache :Object.<string, HTMLImageElement>

A cache for storing images, with the image path as the key.
Type:
  • Object.<string, HTMLImageElement>
Inherited From:
Source:

img :HTMLImageElement

The image used for the drawable object.
Type:
  • HTMLImageElement
Inherited From:
Source:

lastHit :number

Timestamp of the last time the object was hit.
Type:
  • number
Inherited From:
Source:

moveInterval :number|undefined

Interval ID for movement-related loops.
Type:
  • number | undefined
Inherited From:
Source:

offset :Object

Offset values for adjusting collision detection or rendering.
Type:
  • Object
Inherited From:
Source:

speed :number

Horizontal speed of the object.
Type:
  • number
Inherited From:
Source:

speedY :number

Vertical speed of the object.
Type:
  • number
Overrides:
Source:

width :number

The width of the drawable object.
Type:
  • number
Overrides:
Source:

world :object

Reference to the game world.
Type:
  • object
Source:

x :number

The x-coordinate position of the drawable object.
Type:
  • number
Overrides:
Source:

y :number

The y-coordinate position of the drawable object.
Type:
  • number
Overrides:
Source:

Methods

animate()

Handles the rotation animation while the bottle is in the air. Once the bottle lands, triggers the splash animation.
Source:

animateSplash()

Plays the splash animation after the bottle hits the ground. Once the final frame is reached, marks the bottle as broken.
Source:

applyGravity()

Applies gravity to the object by updating its vertical position. The object's vertical speed is decreased by its acceleration at regular intervals.
Inherited From:
Source:

draw(ctx)

Draws the current image on the provided canvas context.
Parameters:
Name Type Description
ctx CanvasRenderingContext2D The drawing context of a canvas.
Inherited From:
Source:

hit()

Reduces the object's energy when hit. If the energy drops below zero, it is set to zero. Otherwise, the last hit timestamp is updated.
Inherited From:
Source:

isAboveGround() → {boolean}

Determines if the object is currently above the ground. Ground detection differs based on the type of object.
Inherited From:
Source:
Returns:
True if the object is above the ground, otherwise false.
Type
boolean

isColliding(obj) → {boolean}

Checks if this object is colliding with another movable object. Collision detection accounts for offset values for more accurate boundaries.
Parameters:
Name Type Description
obj MovableObject The other object to check collision against.
Inherited From:
Source:
Returns:
True if a collision is detected, otherwise false.
Type
boolean

isDead() → {boolean}

Determines if the object is dead based on its energy level.
Inherited From:
Source:
Returns:
True if the object's energy is zero, otherwise false.
Type
boolean

isHurt() → {boolean}

Checks if the object is currently in a hurt state. An object is considered hurt if it was hit within the last second.
Inherited From:
Source:
Returns:
True if the object is hurt, otherwise false.
Type
boolean

jump()

Initiates a jump by setting the vertical speed to a positive value.
Inherited From:
Source:

loadImage(path)

Loads a single image from the specified path.
Parameters:
Name Type Description
path string The path of the image to load.
Inherited From:
Source:

loadImages(arr)

Loads multiple images and stores them in the image cache.
Parameters:
Name Type Description
arr Array.<string> An array of image paths.
Inherited From:
Source:

moveLeft()

Moves the object to the left by its horizontal speed.
Inherited From:
Source:

moveRight()

Moves the object to the right by its horizontal speed.
Inherited From:
Source:

playAnimation(images)

Animates the object by cycling through a set of images. The displayed image is updated based on the current animation frame.
Parameters:
Name Type Description
images Array.<string> An array of image paths used for the animation.
Inherited From:
Source:

remove()

Removes this throwable object from the world's array of throwable objects (if present).
Source:

trow(otherDirektion)

Initiates the throwing behavior by setting vertical speed and applying gravity, then continuously updates the bottle's movement until it hits the ground.
Parameters:
Name Type Description
otherDirektion boolean Determines the horizontal direction of the throw.
Source:

updateThrowMovement(otherDirektion)

Updates the bottle's horizontal movement based on the throw direction. Stops the throwing interval and restarts animation when the bottle hits the ground.
Parameters:
Name Type Description
otherDirektion boolean Determines the horizontal direction of the throw.
Source:

Throwableobject(x, y, otherDirektion)

new Throwableobject(x, y, otherDirektion)

Constructs a new Throwableobject, loads rotation and splash images, and initiates its throwing and animation behavior.
Parameters:
Name Type Description
x number The initial x position of the bottle.
y number The initial y position of the bottle.
otherDirektion boolean If true, the bottle is thrown to the left; otherwise, to the right.
Source:

Members

IMAGES_ROTATION :Array.<string>

An array of image paths for the bottle's rotation animation.
Type:
  • Array.<string>
Source:

IMAGES_SPLASH :Array.<string>

An array of image paths for the bottle's splash animation upon impact.
Type:
  • Array.<string>
Source:

acceleration :number

Acceleration used for gravity effects.
Type:
  • number
Inherited From:
Source:

bottleIsBroken :boolean

Indicates whether the bottle has broken (splash animation completed).
Type:
  • boolean
Source:

currentImage :number

Index of the current image in the animation cycle.
Type:
  • number
Inherited From:
Source:

enemyIsDead :boolean

Indicates if the enemy is dead. Not used for characters.
Type:
  • boolean
Inherited From:
Source:

energy :number

The energy level of the object.
Type:
  • number
Inherited From:
Source:

height :number

The height of the drawable object.
Type:
  • number
Overrides:
Source:

imageCache :Object.<string, HTMLImageElement>

A cache for storing images, with the image path as the key.
Type:
  • Object.<string, HTMLImageElement>
Inherited From:
Source:

img :HTMLImageElement

The image used for the drawable object.
Type:
  • HTMLImageElement
Inherited From:
Source:

lastHit :number

Timestamp of the last time the object was hit.
Type:
  • number
Inherited From:
Source:

moveInterval :number|undefined

Interval ID for movement-related loops.
Type:
  • number | undefined
Inherited From:
Source:

offset :Object

Offset values for adjusting collision detection or rendering.
Type:
  • Object
Inherited From:
Source:

speed :number

Horizontal speed of the object.
Type:
  • number
Inherited From:
Source:

speedY :number

Vertical speed of the object.
Type:
  • number
Overrides:
Source:

width :number

The width of the drawable object.
Type:
  • number
Overrides:
Source:

world :object

Reference to the game world.
Type:
  • object
Source:

x :number

The x-coordinate position of the drawable object.
Type:
  • number
Overrides:
Source:

y :number

The y-coordinate position of the drawable object.
Type:
  • number
Overrides:
Source:

Methods

animate()

Handles the rotation animation while the bottle is in the air. Once the bottle lands, triggers the splash animation.
Source:

animateSplash()

Plays the splash animation after the bottle hits the ground. Once the final frame is reached, marks the bottle as broken.
Source:

applyGravity()

Applies gravity to the object by updating its vertical position. The object's vertical speed is decreased by its acceleration at regular intervals.
Inherited From:
Source:

draw(ctx)

Draws the current image on the provided canvas context.
Parameters:
Name Type Description
ctx CanvasRenderingContext2D The drawing context of a canvas.
Inherited From:
Source:

hit()

Reduces the object's energy when hit. If the energy drops below zero, it is set to zero. Otherwise, the last hit timestamp is updated.
Inherited From:
Source:

isAboveGround() → {boolean}

Determines if the object is currently above the ground. Ground detection differs based on the type of object.
Inherited From:
Source:
Returns:
True if the object is above the ground, otherwise false.
Type
boolean

isColliding(obj) → {boolean}

Checks if this object is colliding with another movable object. Collision detection accounts for offset values for more accurate boundaries.
Parameters:
Name Type Description
obj MovableObject The other object to check collision against.
Inherited From:
Source:
Returns:
True if a collision is detected, otherwise false.
Type
boolean

isDead() → {boolean}

Determines if the object is dead based on its energy level.
Inherited From:
Source:
Returns:
True if the object's energy is zero, otherwise false.
Type
boolean

isHurt() → {boolean}

Checks if the object is currently in a hurt state. An object is considered hurt if it was hit within the last second.
Inherited From:
Source:
Returns:
True if the object is hurt, otherwise false.
Type
boolean

jump()

Initiates a jump by setting the vertical speed to a positive value.
Inherited From:
Source:

loadImage(path)

Loads a single image from the specified path.
Parameters:
Name Type Description
path string The path of the image to load.
Inherited From:
Source:

loadImages(arr)

Loads multiple images and stores them in the image cache.
Parameters:
Name Type Description
arr Array.<string> An array of image paths.
Inherited From:
Source:

moveLeft()

Moves the object to the left by its horizontal speed.
Inherited From:
Source:

moveRight()

Moves the object to the right by its horizontal speed.
Inherited From:
Source:

playAnimation(images)

Animates the object by cycling through a set of images. The displayed image is updated based on the current animation frame.
Parameters:
Name Type Description
images Array.<string> An array of image paths used for the animation.
Inherited From:
Source:

remove()

Removes this throwable object from the world's array of throwable objects (if present).
Source:

trow(otherDirektion)

Initiates the throwing behavior by setting vertical speed and applying gravity, then continuously updates the bottle's movement until it hits the ground.
Parameters:
Name Type Description
otherDirektion boolean Determines the horizontal direction of the throw.
Source:

updateThrowMovement(otherDirektion)

Updates the bottle's horizontal movement based on the throw direction. Stops the throwing interval and restarts animation when the bottle hits the ground.
Parameters:
Name Type Description
otherDirektion boolean Determines the horizontal direction of the throw.
Source: