Animation arc-en-ciel pour le personnage: clignotement multicolore

This commit is contained in:
2025-11-28 18:55:20 +01:00
parent 5e6195fc70
commit 1a38182209

View File

@ -142,6 +142,7 @@ class Pacman {
this.speed = 0.15; this.speed = 0.15;
this.pixelX = this.x * CELL_SIZE + CELL_SIZE / 2; this.pixelX = this.x * CELL_SIZE + CELL_SIZE / 2;
this.pixelY = this.y * CELL_SIZE + CELL_SIZE / 2; this.pixelY = this.y * CELL_SIZE + CELL_SIZE / 2;
this.colorAnimation = 0;
} }
update() { update() {
@ -153,6 +154,11 @@ class Pacman {
this.mouthOpen = !this.mouthOpen; this.mouthOpen = !this.mouthOpen;
} }
this.colorAnimation += 0.3;
if (this.colorAnimation > Math.PI * 2) {
this.colorAnimation = 0;
}
const gridX = Math.floor(this.pixelX / CELL_SIZE); const gridX = Math.floor(this.pixelX / CELL_SIZE);
const gridY = Math.floor(this.pixelY / CELL_SIZE); const gridY = Math.floor(this.pixelY / CELL_SIZE);
@ -243,7 +249,8 @@ class Pacman {
const rotation = [Math.PI * 1.5, 0, Math.PI * 0.5, Math.PI]; const rotation = [Math.PI * 1.5, 0, Math.PI * 0.5, Math.PI];
ctx.rotate(rotation[this.direction]); ctx.rotate(rotation[this.direction]);
ctx.fillStyle = '#ffd700'; const hue = (this.colorAnimation * 180 / Math.PI) % 360;
ctx.fillStyle = `hsl(${hue}, 100%, 50%)`;
ctx.beginPath(); ctx.beginPath();
if (this.mouthOpen) { if (this.mouthOpen) {