Adding PlayerMovement class to interpolate/extrapolate position along tests (installing Jasmine)
This commit is contained in:
parent
077b29bfbd
commit
d69ce8a6a6
9 changed files with 144 additions and 2 deletions
|
@ -3,11 +3,13 @@ const API_URL = process.env.API_URL || "http://api.workadventure.localhost";
|
|||
const RESOLUTION = 3;
|
||||
const ZOOM_LEVEL = 1/*3/4*/;
|
||||
const POSITION_DELAY = 200; // Wait 200ms between sending position events
|
||||
const MAX_EXTRAPOLATION_TIME = 250; // Extrapolate a maximum of 250ms if no new movement is sent by the player
|
||||
|
||||
export {
|
||||
DEBUG_MODE,
|
||||
API_URL,
|
||||
RESOLUTION,
|
||||
ZOOM_LEVEL,
|
||||
POSITION_DELAY
|
||||
POSITION_DELAY,
|
||||
MAX_EXTRAPOLATION_TIME
|
||||
}
|
||||
|
|
23
front/src/Phaser/Game/PlayerMovement.ts
Normal file
23
front/src/Phaser/Game/PlayerMovement.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import {HasMovedEvent} from "./GameManager";
|
||||
import {MAX_EXTRAPOLATION_TIME} from "../../Enum/EnvironmentVariable";
|
||||
|
||||
export class PlayerMovement {
|
||||
public constructor(private startPosition: HasMovedEvent, private startTick: number, private endPosition: HasMovedEvent, private endTick: number) {
|
||||
}
|
||||
|
||||
public isOutdated(tick: number): boolean {
|
||||
return tick > this.endTick + MAX_EXTRAPOLATION_TIME;
|
||||
}
|
||||
|
||||
public getPosition(tick: number): HasMovedEvent {
|
||||
let x = (this.endPosition.x - this.startPosition.x) * ((tick - this.startTick) / (this.endTick - this.startTick)) + this.startPosition.x;
|
||||
let y = (this.endPosition.y - this.startPosition.y) * ((tick - this.startTick) / (this.endTick - this.startTick)) + this.startPosition.y;
|
||||
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
direction: this.endPosition.direction,
|
||||
moving: this.endPosition.moving
|
||||
}
|
||||
}
|
||||
}
|
7
front/src/Phaser/Game/PlayersPositionInterpolator.ts
Normal file
7
front/src/Phaser/Game/PlayersPositionInterpolator.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* This class is in charge of computing the position of all players.
|
||||
* Player movement is delayed by 200ms so position depends on ticks.
|
||||
*/
|
||||
export class PlayersPositionInterpolator {
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue