time for a snapshot
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { type AABB, vec } from "./given.ts";
|
||||
import { moveAndSlide } from "./moveAndSlide.ts";
|
||||
|
||||
const player: AABB = { x: 0, y: 0, w: 2, h: 2 };
|
||||
|
||||
test("no walls -> full move", () => {
|
||||
const p = moveAndSlide(player, vec(10, 5), []);
|
||||
expect(p.x).toBeCloseTo(10);
|
||||
expect(p.y).toBeCloseTo(5);
|
||||
});
|
||||
|
||||
test("head-on into the NEAREST of two walls -> stops there", () => {
|
||||
const walls: AABB[] = [
|
||||
{ x: 5, y: 0, w: 2, h: 2 }, // nearer
|
||||
{ x: 8, y: 0, w: 2, h: 2 }, // farther
|
||||
];
|
||||
const p = moveAndSlide(player, vec(10, 0), walls);
|
||||
expect(p.x).toBeCloseTo(3); // right edge (2) meets wall left edge (5)
|
||||
expect(p.y).toBeCloseTo(0);
|
||||
});
|
||||
|
||||
test("diagonal into a vertical wall -> slides down it", () => {
|
||||
// x is blocked at 3, but the downward motion keeps going for the whole frame
|
||||
const walls: AABB[] = [{ x: 5, y: -10, w: 2, h: 40 }];
|
||||
const p = moveAndSlide(player, vec(10, 10), walls);
|
||||
expect(p.x).toBeCloseTo(3);
|
||||
expect(p.y).toBeCloseTo(10);
|
||||
});
|
||||
|
||||
test("diagonal onto a floor -> slides along it", () => {
|
||||
// falls until its bottom meets the floor top (y=8 -> corner y=6), keeps moving in x
|
||||
const walls: AABB[] = [{ x: 0, y: 8, w: 20, h: 2 }];
|
||||
const p = moveAndSlide(player, vec(5, 10), walls);
|
||||
expect(p.x).toBeCloseTo(5);
|
||||
expect(p.y).toBeCloseTo(6);
|
||||
});
|
||||
Reference in New Issue
Block a user