|
1 | 1 | import { describe, expect, test } from "bun:test"; |
| 2 | +import { WORLD } from "../../src/constants.ts"; |
2 | 3 | import type { LevelEntitySpec } from "../../src/entities/types.ts"; |
3 | 4 | import { |
4 | 5 | buildWorld, |
| 6 | + createPlayer, |
5 | 7 | createPlayerOnFloor, |
6 | 8 | makeInput, |
7 | 9 | step, |
@@ -101,4 +103,40 @@ describe("Dash behavior", () => { |
101 | 103 | expect(jump.snapshot.vx).toBeCloseTo(325, 5); |
102 | 104 | expect(jump.snapshot.vy).toBeCloseTo(-52.5, 5); |
103 | 105 | }); |
| 106 | + |
| 107 | + test("post-dash floor snap does not embed horizontal dashes in solid ground", () => { |
| 108 | + const floorRow = 20; |
| 109 | + const floorY = floorRow * WORLD.tile; |
| 110 | + const specs: LevelEntitySpec[] = []; |
| 111 | + withFloor(specs, floorRow); |
| 112 | + const world = buildWorld(specs); |
| 113 | + const player = createPlayer(world, 104, floorY - 4); |
| 114 | + |
| 115 | + stepOnce(player, makeInput()); |
| 116 | + stepOnce(player, makeInput({ x: 1, dashPressed: true })); |
| 117 | + |
| 118 | + let landed = null as ReturnType<typeof player.getSnapshot> | null; |
| 119 | + for (let frame = 0; frame < 60; frame++) { |
| 120 | + const result = stepOnce(player, makeInput({ x: 1 })); |
| 121 | + if (result.snapshot.onGround && result.snapshot.state === "normal") { |
| 122 | + landed = result.snapshot; |
| 123 | + break; |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + expect(landed).toBeTruthy(); |
| 128 | + expect(landed!.bottom).toBe(floorY); |
| 129 | + |
| 130 | + const run = stepOnce(player, makeInput({ x: 1 })).snapshot; |
| 131 | + expect(run.x).toBeGreaterThan(landed!.x); |
| 132 | + expect(run.bottom).toBe(floorY); |
| 133 | + |
| 134 | + const duck = stepOnce(player, makeInput({ y: 1 })).snapshot; |
| 135 | + expect(duck.isCrouched).toBeTrue(); |
| 136 | + expect(duck.bottom).toBe(floorY); |
| 137 | + |
| 138 | + const stand = stepOnce(player, makeInput()).snapshot; |
| 139 | + expect(stand.isCrouched).toBeFalse(); |
| 140 | + expect(stand.bottom).toBe(floorY); |
| 141 | + }); |
104 | 142 | }); |
0 commit comments