2020-06-02 10:48:04 +02:00
|
|
|
import "jasmine";
|
|
|
|
import {PlayerMovement} from "../../../src/Phaser/Game/PlayerMovement";
|
|
|
|
|
|
|
|
describe("Interpolation / Extrapolation", () => {
|
|
|
|
it("should interpolate", () => {
|
|
|
|
let playerMovement = new PlayerMovement({
|
2020-06-02 13:44:42 +02:00
|
|
|
x: 100, y: 200
|
2020-06-02 10:48:04 +02:00
|
|
|
}, 42000,
|
|
|
|
{
|
|
|
|
x: 200, y: 100, moving: true, direction: "up"
|
|
|
|
},
|
|
|
|
42200
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
expect(playerMovement.isOutdated(42100)).toBe(false);
|
|
|
|
expect(playerMovement.isOutdated(43000)).toBe(true);
|
|
|
|
|
|
|
|
expect(playerMovement.getPosition(42100)).toEqual({
|
|
|
|
x: 150,
|
|
|
|
y: 150,
|
|
|
|
direction: 'up',
|
|
|
|
moving: true
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(playerMovement.getPosition(42200)).toEqual({
|
|
|
|
x: 200,
|
|
|
|
y: 100,
|
|
|
|
direction: 'up',
|
|
|
|
moving: true
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(playerMovement.getPosition(42300)).toEqual({
|
|
|
|
x: 250,
|
|
|
|
y: 50,
|
|
|
|
direction: 'up',
|
|
|
|
moving: true
|
|
|
|
});
|
|
|
|
});
|
2020-06-02 13:44:42 +02:00
|
|
|
|
|
|
|
it("should not extrapolate if we stop", () => {
|
|
|
|
let playerMovement = new PlayerMovement({
|
|
|
|
x: 100, y: 200
|
|
|
|
}, 42000,
|
|
|
|
{
|
|
|
|
x: 200, y: 100, moving: false, direction: "up"
|
|
|
|
},
|
|
|
|
42200
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(playerMovement.getPosition(42300)).toEqual({
|
|
|
|
x: 200,
|
|
|
|
y: 100,
|
|
|
|
direction: 'up',
|
|
|
|
moving: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should should keep moving until it stops", () => {
|
|
|
|
let playerMovement = new PlayerMovement({
|
|
|
|
x: 100, y: 200
|
|
|
|
}, 42000,
|
|
|
|
{
|
|
|
|
x: 200, y: 100, moving: false, direction: "up"
|
|
|
|
},
|
|
|
|
42200
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(playerMovement.getPosition(42100)).toEqual({
|
|
|
|
x: 150,
|
|
|
|
y: 150,
|
|
|
|
direction: 'up',
|
|
|
|
moving: true
|
|
|
|
});
|
|
|
|
});
|
2020-06-02 10:48:04 +02:00
|
|
|
})
|