2020-06-02 10:48:04 +02:00
|
|
|
import "jasmine";
|
2022-01-05 11:47:31 +01:00
|
|
|
import { PlayerMovement } from "../../../src/Phaser/Game/PlayerMovement";
|
2020-06-02 10:48:04 +02:00
|
|
|
|
|
|
|
describe("Interpolation / Extrapolation", () => {
|
|
|
|
it("should interpolate", () => {
|
2022-01-05 11:47:31 +01:00
|
|
|
const playerMovement = new PlayerMovement(
|
|
|
|
{
|
|
|
|
x: 100,
|
|
|
|
y: 200,
|
|
|
|
},
|
|
|
|
42000,
|
2020-06-02 10:48:04 +02:00
|
|
|
{
|
2021-10-29 16:44:51 +02:00
|
|
|
x: 200,
|
|
|
|
y: 100,
|
2021-10-29 23:30:02 +02:00
|
|
|
oldX: 100,
|
|
|
|
oldY: 200,
|
2021-10-29 16:44:51 +02:00
|
|
|
moving: true,
|
2022-01-05 11:47:31 +01:00
|
|
|
direction: "up",
|
2020-06-02 10:48:04 +02:00
|
|
|
},
|
|
|
|
42200
|
2022-01-05 11:47:31 +01:00
|
|
|
);
|
2020-06-02 10:48:04 +02:00
|
|
|
|
|
|
|
expect(playerMovement.isOutdated(42100)).toBe(false);
|
|
|
|
expect(playerMovement.isOutdated(43000)).toBe(true);
|
|
|
|
|
|
|
|
expect(playerMovement.getPosition(42100)).toEqual({
|
|
|
|
x: 150,
|
|
|
|
y: 150,
|
2021-10-29 23:30:02 +02:00
|
|
|
oldX: 100,
|
|
|
|
oldY: 200,
|
2022-01-05 11:47:31 +01:00
|
|
|
direction: "up",
|
|
|
|
moving: true,
|
2020-06-02 10:48:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(playerMovement.getPosition(42200)).toEqual({
|
|
|
|
x: 200,
|
|
|
|
y: 100,
|
2021-10-29 23:30:02 +02:00
|
|
|
oldX: 100,
|
|
|
|
oldY: 200,
|
2022-01-05 11:47:31 +01:00
|
|
|
direction: "up",
|
|
|
|
moving: true,
|
2020-06-02 10:48:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(playerMovement.getPosition(42300)).toEqual({
|
|
|
|
x: 250,
|
|
|
|
y: 50,
|
2021-10-29 23:30:02 +02:00
|
|
|
oldX: 100,
|
|
|
|
oldY: 200,
|
2022-01-05 11:47:31 +01:00
|
|
|
direction: "up",
|
|
|
|
moving: true,
|
2020-06-02 10:48:04 +02:00
|
|
|
});
|
|
|
|
});
|
2020-06-02 13:44:42 +02:00
|
|
|
|
|
|
|
it("should not extrapolate if we stop", () => {
|
2022-01-05 11:47:31 +01:00
|
|
|
const playerMovement = new PlayerMovement(
|
|
|
|
{
|
|
|
|
x: 100,
|
|
|
|
y: 200,
|
|
|
|
},
|
|
|
|
42000,
|
2020-06-02 13:44:42 +02:00
|
|
|
{
|
2021-10-29 16:44:51 +02:00
|
|
|
x: 200,
|
|
|
|
y: 100,
|
2021-10-29 23:30:02 +02:00
|
|
|
oldX: 100,
|
|
|
|
oldY: 200,
|
2021-10-29 16:44:51 +02:00
|
|
|
moving: false,
|
2022-01-05 11:47:31 +01:00
|
|
|
direction: "up",
|
2020-06-02 13:44:42 +02:00
|
|
|
},
|
|
|
|
42200
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(playerMovement.getPosition(42300)).toEqual({
|
|
|
|
x: 200,
|
|
|
|
y: 100,
|
2021-10-29 23:30:02 +02:00
|
|
|
oldX: 100,
|
|
|
|
oldY: 200,
|
2022-01-05 11:47:31 +01:00
|
|
|
direction: "up",
|
|
|
|
moving: false,
|
2020-06-02 13:44:42 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-30 11:48:59 +01:00
|
|
|
it("should keep moving until it stops", () => {
|
2022-01-05 11:47:31 +01:00
|
|
|
const playerMovement = new PlayerMovement(
|
|
|
|
{
|
|
|
|
x: 100,
|
|
|
|
y: 200,
|
|
|
|
},
|
|
|
|
42000,
|
2020-06-02 13:44:42 +02:00
|
|
|
{
|
2021-10-29 16:44:51 +02:00
|
|
|
x: 200,
|
|
|
|
y: 100,
|
2021-10-29 23:30:02 +02:00
|
|
|
oldX: 100,
|
|
|
|
oldY: 200,
|
2021-10-29 16:44:51 +02:00
|
|
|
moving: false,
|
2022-01-05 11:47:31 +01:00
|
|
|
direction: "up",
|
2020-06-02 13:44:42 +02:00
|
|
|
},
|
|
|
|
42200
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(playerMovement.getPosition(42100)).toEqual({
|
|
|
|
x: 150,
|
|
|
|
y: 150,
|
2021-10-29 23:30:02 +02:00
|
|
|
oldX: 100,
|
|
|
|
oldY: 200,
|
2022-01-05 11:47:31 +01:00
|
|
|
direction: "up",
|
|
|
|
moving: false,
|
2020-06-02 13:44:42 +02:00
|
|
|
});
|
|
|
|
});
|
2022-01-05 11:47:31 +01:00
|
|
|
});
|