gitflarePublicPartly agent-ready40
shadow-fight-web-version
No description yet.
- LicenseApache-2.0
- LanguageJavaScript
- Last landed
132be7cOct 23, 2026
Make the player visible with a procedural 3D humanoid
132be7cimport test from 'node:test';import assert from 'node:assert/strict';import { computeCamera, multiply, targetPose, PALETTES, POSES, UNIT } from './pose.mjs';import { createMatch } from './game/engine.mjs';import { LEVELS } from './game/levels.mjs';import { drawOrder, clampToArena, frameCamera } from './render-utils.mjs';import { humanoidParts, resolveDt, keyLightDir, sphereMesh, screenBounds, shadowDiscs } from './humanoid.mjs';import { normalizeStage } from './render3d.mjs';import { stage } from './stage.mjs'; function camFor(state, aspect) { const arenaW = ((state.level && state.level.arena && state.level.arena.width) || 960) * UNIT; const fighters = state.fighters.map((f) => ({ ...f, x: clampToArena(f.x * UNIT, arenaW) / UNIT })); const need = frameCamera(fighters.map((f) => f.x * UNIT), aspect, Math.PI / 4, arenaW).distance * 1.1; const cam = computeCamera({ ...state, fighters }, aspect, { minDistance: Math.max(5.5, need), maxDistance: Math.max(10, need) }); return { fighters, vp: multiply(cam.projection, cam.view) };} test('render options object (as passed by main.mjs) yields a finite dt', () => { const a = resolveDt({ time: 10 }, null); assert.ok(Number.isFinite(a.dt) && a.dt > 0); const b = resolveDt({ time: 10.016 }, a.time); assert.ok(Math.abs(b.dt - 0.016) < 1e-9); assert.equal(resolveDt(0.02, 5).dt, 0.02); assert.ok(Number.isFinite(resolveDt(undefined, null).dt));}); test('both fighters on load are inside the camera frame with non-zero size', () => { for (const level of LEVELS) { const state = createMatch(level); for (const aspect of [16 / 9, 1, 9 / 16]) { const { fighters, vp } = camFor(state, aspect); fighters.forEach((f, i) => { const parts = humanoidParts(f, targetPose(f, 0), PALETTES[i]); for (const p of parts) for (const v of p.matrix) assert.ok(Number.isFinite(v)); const b = screenBounds(parts, vp); assert.ok(b.minX >= -1 && b.maxX <= 1 && b.minY >= -1 && b.maxY <= 1, JSON.stringify(b)); assert.ok(b.maxY - b.minY > 0.2 && b.maxX - b.minX > 0.02, 'visible size'); }); } }}); test('humanoid has body, head, limbs and follows poses', () => { const f = { x: 300, y: 0, facing: 1 }; const names = (p) => humanoidParts(f, p, PALETTES[0]); const idle = names(POSES.idle), kick = names(POSES.kickHit), hit = names(POSES.hit); for (const n of ['torso', 'head', 'pelvis', 'lUpperArm', 'rForeArm', 'lThigh', 'rShin', 'lHand', 'rFoot', 'neck', 'hair']) assert.ok(idle.some((p) => p.name === n), n); const foot = (ps) => ps.find((p) => p.name === 'lFoot').matrix[13]; assert.ok(foot(kick) > foot(idle) + 0.2, 'kick raises the foot'); assert.notDeepEqual(hit.find((p) => p.name === 'head').matrix, idle.find((p) => p.name === 'head').matrix);}); test('layer order draws the player last, over stage and opponent', () => { const st = normalizeStage(stage, LEVELS[0]); const o = drawOrder(st.boxes.length, 2, 0); assert.deepEqual(o[o.length - 1], { kind: 'fighter', index: 0 }); assert.ok(o.slice(0, st.boxes.length).every((e) => e.kind === 'layer'));}); test('stage does not occlude fighters and lighting comes from above', () => { const st = normalizeStage(stage, LEVELS[0]); for (const b of st.boxes) { const front = b.position[2] + b.size[2] / 2, back = b.position[2] - b.size[2] / 2, top = b.position[1] + b.size[1] / 2; assert.ok(back < -0.5 || top <= 0.001 || front < -0.5, b.name); } assert.ok(keyLightDir(st.lightDir)[1] > 0); assert.ok(shadowDiscs(4, 0).every((d) => d.position[1] > 0));}); test('sphere mesh has unit normals and valid indices', () => { const m = sphereMesh(); for (let i = 0; i < m.vertices.length; i += 6) assert.ok(Math.abs(Math.hypot(m.vertices[i + 3], m.vertices[i + 4], m.vertices[i + 5]) - 1) < 1e-5); assert.ok(Math.max(...m.indices) < m.vertices.length / 6);});