Adding PlayersPositionInterpolator to interpolate/extrapolate players positions
This commit is contained in:
parent
d69ce8a6a6
commit
d72e60610e
4 changed files with 97 additions and 14 deletions
|
@ -4,7 +4,7 @@ import {PlayerMovement} from "../../../src/Phaser/Game/PlayerMovement";
|
|||
describe("Interpolation / Extrapolation", () => {
|
||||
it("should interpolate", () => {
|
||||
let playerMovement = new PlayerMovement({
|
||||
x: 100, y: 200, moving: true, direction: "right"
|
||||
x: 100, y: 200
|
||||
}, 42000,
|
||||
{
|
||||
x: 200, y: 100, moving: true, direction: "up"
|
||||
|
@ -37,4 +37,40 @@ describe("Interpolation / Extrapolation", () => {
|
|||
moving: true
|
||||
});
|
||||
});
|
||||
|
||||
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
|
||||
});
|
||||
});
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue