fix: mirror X axis for dungeon tiles to match UB coordinate system

UB uses mirrored X: x = -(cell.X - playerX), direct Y: y = cell.Y - playerY.
Applied same transform to tile rendering, object positioning, and
entity list distance calculations in dungeon mode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-08 15:31:23 +02:00
parent 683d1cf337
commit 3857c0de79

View file

@ -3877,12 +3877,13 @@ function updateRadarWindow(msg) {
ctx.globalAlpha = isCurrentFloor ? 0.85 : 0.12;
(level.cells || []).forEach(cell => {
const dx = (cell.x - playerX) * scale;
const dy = -(cell.y - playerY) * scale; // Y flipped
// UB mirrors X: x = -(cell.x - playerX), Y is direct: y = cell.y - playerY
const dx = -(cell.x - playerX) * scale;
const dy = (cell.y - playerY) * scale;
const tileCanvas = hasTiles ? dungeonTileCanvases[String(cell.env_id)] : null;
if (tileCanvas) {
// Draw processed tile with rotation
// Draw processed tile with per-cell rotation
ctx.save();
ctx.translate(dx, dy);
ctx.rotate(cellRotation(cell.rotation));
@ -3972,11 +3973,11 @@ function updateRadarWindow(msg) {
const cosA = Math.cos(rotAngle);
const sinA = Math.sin(rotAngle);
objects.forEach(obj => {
// Use raw physics coords in dungeons, EW/NS on surface
// Use raw physics coords in dungeons (X mirrored), EW/NS on surface
let dX, dY;
if (isDungeon && obj.raw_x !== undefined) {
dX = obj.raw_x - playerX;
dY = obj.raw_y - playerY;
dX = -(obj.raw_x - playerX); // X mirrored to match UB coordinate system
dY = (obj.raw_y - playerY);
} else {
dX = obj.ew - playerEW;
dY = obj.ns - playerNS;
@ -4038,8 +4039,8 @@ function updateRadarWindow(msg) {
const withDist = objects.map(obj => {
let distMeters, dX, dY;
if (isDungeon && obj.raw_x !== undefined) {
dX = obj.raw_x - playerX;
dY = obj.raw_y - playerY;
dX = -(obj.raw_x - playerX); // X mirrored
dY = (obj.raw_y - playerY);
distMeters = Math.sqrt(dX * dX + dY * dY); // raw coords are ~meters
} else {
dX = obj.ew - playerEW;