Fix: render correct visible sides

This commit is contained in:
Richard Zink committed 2026-10-06 17:16:27 +02:00
1 parent 48cd7a43cf
commit eec49759fc
1 file changed
+16 -16
+16 -16
View File
@@ -71,7 +71,7 @@
} }
} }
function drawTile(wx, wy, h, water, hLeft, hFront) { function drawTile(wx, wy, h, water, hRight, hBack) {
var top1 = project(wx + GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT); var top1 = project(wx + GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT);
var top2 = project(wx + TILE - GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT); var top2 = project(wx + TILE - GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT);
var top3 = project(wx + TILE - GAP/2, wy + GAP/2, h * HEIGHT_UNIT); var top3 = project(wx + TILE - GAP/2, wy + GAP/2, h * HEIGHT_UNIT);
@@ -90,24 +90,24 @@
ctx.closePath(); ctx.closePath();
ctx.fill(); ctx.fill();
if (hLeft < h) { if (hRight < h) {
ctx.fillStyle = leftColor; ctx.fillStyle = rightColor;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(top4[0], top4[1]); ctx.moveTo(top2[0], top2[1]);
ctx.lineTo(top1[0], top1[1]); ctx.lineTo(top3[0], top3[1]);
ctx.lineTo(top1[0], top1[1] + (h - hLeft) * HEIGHT_UNIT); ctx.lineTo(top3[0], top3[1] + (h - hRight) * HEIGHT_UNIT);
ctx.lineTo(top4[0], top4[1] + (h - hLeft) * HEIGHT_UNIT); ctx.lineTo(top2[0], top2[1] + (h - hRight) * HEIGHT_UNIT);
ctx.closePath(); ctx.closePath();
ctx.fill(); ctx.fill();
} }
if (hFront < h) { if (hBack < h) {
ctx.fillStyle = rightColor; ctx.fillStyle = leftColor;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(top3[0], top3[1]); ctx.moveTo(top1[0], top1[1]);
ctx.lineTo(top4[0], top4[1]); ctx.lineTo(top2[0], top2[1]);
ctx.lineTo(top4[0], top4[1] + (h - hFront) * HEIGHT_UNIT); ctx.lineTo(top2[0], top2[1] + (h - hBack) * HEIGHT_UNIT);
ctx.lineTo(top3[0], top3[1] + (h - hFront) * HEIGHT_UNIT); ctx.lineTo(top1[0], top1[1] + (h - hBack) * HEIGHT_UNIT);
ctx.closePath(); ctx.closePath();
ctx.fill(); ctx.fill();
} }
@@ -130,10 +130,10 @@
var water = isWater(h); var water = isWater(h);
var hLeft = heightMap[(wx - TILE) + ',' + wy] || 0; var hRight = heightMap[(wx + TILE) + ',' + wy] || 0;
var hFront = heightMap[wx + ',' + (wy - TILE)] || 0; var hBack = heightMap[wx + ',' + (wy + TILE)] || 0;
drawTile(wx, wy, h, water, hLeft, hFront); drawTile(wx, wy, h, water, hRight, hBack);
} }
} }