add the grayscale filter to the pet when unhappy

This commit is contained in:
zyl 2024-06-25 00:55:06 -07:00
parent f1c25ec896
commit 8f0a925a33
No known key found for this signature in database

View file

@ -291,6 +291,18 @@
thePet.style.setProperty("--width", `${width}px`);
thePet.style.setProperty("--height", `${height}px`);
thePet.style.setProperty("--color", this.color);
let happinessFilter = 1 - this.happiness / MAX_HAPPINESS;
if (happinessFilter < 0.6) {
happinessFilter = 0;
}
happinessFilter = (happinessFilter - 0.6) * 2.5;
if (happinessFilter < 0) {
happinessFilter = 0;
}
thePet.style.setProperty(
"filter",
`grayscale(${happinessFilter * 100}%)`
);
if (!this.alive) {
thePet.classList.add("dead");