class Example extends Phaser.Scene {
this.hudContainer = this.add.container(0, 0);
this.healthBarContainer = this.add.container(20, 20);
this.healthBarBg = this.add
.strokeRect(0, 0, 200, 20);
this.healthBar = this.add
.fillRect(1, 1, 160, 18);
this.healthBarLabel = this.add.text(9, 3, "PV");
this.healthBarContainer.add([
this.hudContainer.add(this.healthBarContainer);
this.scoreText = this.add
.text(config.width - 20, 20, "Score: 420")
this.hudContainer.add(this.scoreText);
this.remainingTime = this.timerDuration;
this.timerText = this.add
.text(config.width / 2, 20, formatTime(this.timerDuration))
this.hudContainer.add(this.timerText);
let elapsedSeconds = Math.floor(time / 1000);
let healthWidth = 198 * ((Math.sin(time / 500) + 1) / 2);
this.healthBar.fillStyle(0xff0000).fillRect(1, 1, healthWidth, 18);
this.scoreText.setText(`Score: ${Math.floor(time / 100)}`);
if (this.remainingTime > 0) {
this.remainingTime = this.timerDuration - elapsedSeconds;
this.timerText.setText(formatTime(this.remainingTime));
console.log("Plus de temps !");
const game = new Phaser.Game(config);
function formatTime(seconds) {
let minutes = Math.floor(seconds / 60);
let remainingSeconds = seconds % 60;
.padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`;