1 import {HasMovedEvent} from "./GameManager";
2 import {MAX_EXTRAPOLATION_TIME} from "../../Enum/EnvironmentVariable";
3 import {PositionInterface} from "../../Connection";
5 export class PlayerMovement {
6 public constructor(private startPosition: PositionInterface, private startTick: number, private endPosition: HasMovedEvent, private endTick: number) {
9 public isOutdated(tick: number): boolean {
10 //console.log(tick, this.endTick, MAX_EXTRAPOLATION_TIME)
12 // If the endPosition is NOT moving, no extrapolation needed.
13 if (this.endPosition.moving === false && tick > this.endTick) {
17 return tick > this.endTick + MAX_EXTRAPOLATION_TIME;
20 public getPosition(tick: number): HasMovedEvent {
21 // Special case: end position reached and end position is not moving
22 if (tick >= this.endTick && this.endPosition.moving === false) {
23 return this.endPosition;
26 let x = (this.endPosition.x - this.startPosition.x) * ((tick - this.startTick) / (this.endTick - this.startTick)) + this.startPosition.x;
27 let y = (this.endPosition.y - this.startPosition.y) * ((tick - this.startTick) / (this.endTick - this.startTick)) + this.startPosition.y;
32 direction: this.endPosition.direction,