/**
* Represents a status bar that displays the health of a character or entity.
* This class extends the DrawableObject class.
*
* @class StatusBarEndboss
* @extends DrawableObject
*/
class StatusBarEndboss extends DrawableObject {
/**
* An array of image paths representing different health levels.
*
* @type {string[]}
* @memberof StatusBarEndboss
*/
IMAGES = [
"img/2_statusbar_endboss/statusbar_0.png",
"img/2_statusbar_endboss/statusbar_20.png",
"img/2_statusbar_endboss/statusbar_40.png",
"img/2_statusbar_endboss/statusbar_60.png",
"img/2_statusbar_endboss/statusbar_80.png",
"img/2_statusbar_endboss/statusbar_100.png",
];
/**
* The current health percentage displayed on the status bar.
*
* @type {number}
* @memberof StatusBarEndboss
*/
percentage = 100;
/**
* Creates an instance of StatusBarEndboss.
* Loads the necessary images, sets the initial position, size,
* and initializes the health percentage to 100.
*
* @constructor
* @memberof StatusBarEndboss
*/
constructor() {
super();
this.loadImages(this.IMAGES);
this.x = 250;
this.y = -76;
this.width = 210;
this.height = 220;
this.setPercentage(100);
}
/**
* Sets the health percentage and updates the corresponding status bar image.
*
* @param {number} percentage - The new health percentage to display.
* @memberof StatusBarEndboss
*/
setPercentage(percentage) {
this.percentage = percentage;
const path = this.IMAGES[this.resolveImageIndex()];
this.img = this.imageCache[path];
}
/**
* Determines the index of the image to display based on the current health percentage.
*
* @returns {number} The index corresponding to the current health level.
* @memberof StatusBarEndboss
*/
resolveImageIndex() {
if (this.percentage === 100) {
return 5;
} else if (this.percentage === 80) {
return 4;
} else if (this.percentage === 60) {
return 3;
} else if (this.percentage === 40) {
return 2;
} else if (this.percentage === 20) {
return 1;
} else {
return 0;
}
}
}