Stack voxels per height level instead of smooth animation

This commit is contained in:
Richard Zink committed 2026-10-06 17:19:24 +02:00
1 parent 49c558bef9
commit c89cca37bf
1 file changed
+21 -13
+21 -13
View File
@@ -40,12 +40,12 @@
return [sx, sy];
}
function getHeight(x, y, time) {
function getHeight(x, y) {
var h = 0;
h += Math.sin(x * 0.03 + time * 0.5) * 3;
h += Math.cos(y * 0.03 + time * 0.4) * 3;
h += Math.sin(x * 0.05 + y * 0.03 + time * 0.3) * 1.5;
h += Math.cos(y * 0.05 - x * 0.03 + time * 0.6) * 1;
h += Math.sin(x * 0.03) * 3;
h += Math.cos(y * 0.03) * 3;
h += Math.sin(x * 0.05 + y * 0.03) * 1.5;
h += Math.cos(y * 0.05 - x * 0.03) * 1;
return Math.round(h);
}
@@ -53,7 +53,6 @@
return h <= -2;
}
var time = 0;
var tiles = [];
function generateTiles() {
@@ -65,7 +64,7 @@
for (var y = -rangeY; y <= rangeY; y++) {
var wx = x * TILE;
var wy = y * TILE;
var h = getHeight(wx, wy, time);
var h = getHeight(wx, wy);
tiles.push({ x: wx, y: wy, h: h });
}
}
@@ -130,10 +129,21 @@
var water = isWater(h);
var hRight = heightMap[(wx + TILE) + ',' + wy] || 0;
var hBack = heightMap[wx + ',' + (wy + TILE)] || 0;
drawTile(wx, wy, h, water, hRight, hBack);
for (var level = 1; level <= h; level++) {
var hRight;
if (level > (heightMap[(wx + TILE) + ',' + wy] || 0)) {
hRight = level - 1;
} else {
hRight = level;
}
var hBack;
if (level > (heightMap[wx + ',' + (wy + TILE)] || 0)) {
hBack = level - 1;
} else {
hBack = level;
}
drawTile(wx, wy, level, true, hRight, hBack);
}
}
}
@@ -151,8 +161,6 @@
ctx.fillStyle = '#001020';
ctx.fillRect(0, 0, W, H);
time += 0.02;
generateTiles();
drawTiles();