feat: Add color variations for natural elements and dynamic water colors

This commit is contained in:
Kacper Kostka (aider)
2025-04-04 12:22:15 +02:00
parent a86acfff3a
commit 8ef18f52ab
6 changed files with 113 additions and 8 deletions

View File

@@ -22,19 +22,40 @@ function updateSand(x, y) {
}
function updateWater(x, y) {
// Update water color dynamically
const metadata = getMetadata(x, y);
if (metadata) {
if (metadata.waterColorTimer === undefined) {
metadata.waterColorTimer = 0;
}
metadata.waterColorTimer++;
// Change color occasionally
if (metadata.waterColorTimer > 20 && Math.random() < 0.1) {
metadata.colorIndex = Math.floor(Math.random() * 10);
metadata.waterColorTimer = 0;
}
setMetadata(x, y, metadata);
}
// Try to move down
if (getPixel(x, y + 1) === EMPTY) {
setPixel(x, y, EMPTY);
setPixel(x, y + 1, WATER);
moveMetadata(x, y, x, y + 1);
}
// Try to move down-left or down-right
else if (getPixel(x - 1, y + 1) === EMPTY) {
setPixel(x, y, EMPTY);
setPixel(x - 1, y + 1, WATER);
moveMetadata(x, y, x - 1, y + 1);
}
else if (getPixel(x + 1, y + 1) === EMPTY) {
setPixel(x, y, EMPTY);
setPixel(x + 1, y + 1, WATER);
moveMetadata(x, y, x + 1, y + 1);
}
// Try to spread horizontally
else {