"use strict"; const { describe, it } = require("node:test"); const assert = require("node:assert/strict"); const fs = require("fs"); const path = require("path"); const vm = require("vm"); function loadLegacyGlobals () { const root = path.join(__dirname, ".."); const context = { console, Math, module: {}, exports: {} }; context.global = context; vm.createContext(context); for (const rel of ["src/textureColumn.js", "src/levels.js", "src/tiles.js", "src/world.js"]) { const code = fs.readFileSync(path.join(root, rel), "utf8"); vm.runInContext(code, context, { filename: rel }); } return context; } describe("World.rayCast", () => { it("hits a solid wall ahead of spawn looking slightly south of east", () => { const g = loadLegacyGlobals(); g.World.loadLevel(0); const spawn = g.World.spawnPoint(); // Looking roughly south into the map (legacy +Y) const hit = g.World.rayCast(spawn.x, spawn.y, 0.1); assert.ok(hit); assert.ok(hit.tile); assert.equal(hit.tile.Solid, true); assert.ok(hit.distance > 0); assert.ok(hit.tileX >= 0 && hit.tileX <= 1); }); it("tileX stays in [0,1] for many angles", () => { const g = loadLegacyGlobals(); g.World.loadLevel(0); const spawn = g.World.spawnPoint(); for (let i = 0; i < 64; i++) { const ang = (i / 64) * Math.PI * 2; const hit = g.World.rayCast(spawn.x, spawn.y, ang); assert.ok(hit.tileX >= 0 && hit.tileX <= 1, "tileX out of range at " + ang); } }); });