Improve moviment !
This commit is contained in:
@@ -91,3 +91,56 @@ Deno.test("the position is sent on the tick it lands, so the server sees it touc
|
||||
InputManager.keys_down.clear();
|
||||
assert(landings >= 5, `landed ${landings} times`);
|
||||
});
|
||||
|
||||
Deno.test("opening a screen while walking stops the player", () => {
|
||||
const { player } = setup();
|
||||
const client = player.client as unknown as { screen: unknown };
|
||||
InputManager.keys_down.add("KeyW");
|
||||
for (let tick = 0; tick < 5; tick++) player.tick();
|
||||
client.screen = {};
|
||||
player.tick();
|
||||
const z = player.z;
|
||||
for (let tick = 0; tick < 20; tick++) player.tick();
|
||||
InputManager.keys_down.clear();
|
||||
assertEquals(player.z, z);
|
||||
assertEquals([player.vx, player.vz], [0, 0]);
|
||||
});
|
||||
|
||||
Deno.test("sneaking doesn't walk off edges, from any direction, but still jumps off them", () => {
|
||||
for (const [key, yaw] of [["KeyW", 0], ["KeyW", Math.PI / 4], ["KeyD", 0], ["KeyS", 1], ["KeyA", 2.5]] as const) {
|
||||
// a 3x3 platform with nothing around it
|
||||
const { player } = setup();
|
||||
const level = player.level as unknown as { has_collision: (x: number, y: number, z: number) => boolean };
|
||||
level.has_collision = (x, y, z) => y === -1 && x >= 0 && x < 3 && z >= 0 && z < 3;
|
||||
player.set_position(1.5, 0, 1.5);
|
||||
player.yaw = yaw;
|
||||
run(player, 1, () => false);
|
||||
InputManager.keys_down.add("KeyC");
|
||||
InputManager.keys_down.add(key);
|
||||
for (let tick = 0; tick < 60; tick++) player.tick();
|
||||
assertEquals(player.y, 0, `fell off with ${key} at yaw ${yaw}`);
|
||||
assert(player.on_ground);
|
||||
|
||||
InputManager.keys_down.add("Space");
|
||||
for (let tick = 0; tick < 60; tick++) player.tick();
|
||||
InputManager.keys_down.clear();
|
||||
assert(player.y < -1, "jumped off");
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("stepping from the edge of a block onto the one diagonal to it doesn't fall between them", () => {
|
||||
// floor only at (0, 0) and (1, 1)
|
||||
const { player } = setup();
|
||||
const level = player.level as unknown as { has_collision: (x: number, y: number, z: number) => boolean };
|
||||
level.has_collision = (x, y, z) => y === -1 && ((x === 0 && z === 0) || (x === 1 && z === 1));
|
||||
// on the +x edge of the first block, hanging over it, then walking diagonally to the other
|
||||
player.set_position(1, 0, 0.3);
|
||||
run(player, 1, () => false);
|
||||
player.yaw = -3 * Math.PI / 4;
|
||||
InputManager.keys_down.add("KeyW");
|
||||
for (let tick = 0; tick < 20 && !(player.x > 1.3 && player.z > 1.3); tick++) player.tick();
|
||||
InputManager.keys_down.clear();
|
||||
assert(player.x > 1.3 && player.z > 1.3, "got over the second block");
|
||||
assertEquals(player.y, 0);
|
||||
assert(player.on_ground);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user