Skip to content

Commit

Permalink
client side interpolation, and server pos received visualised in debu…
Browse files Browse the repository at this point in the history
…g view
  • Loading branch information
keshav2010 committed Apr 27, 2024
1 parent 9458bd0 commit 8fd6b36
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions public/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,19 @@ export class GameScene extends BaseScene {
renderDebugPath() {
const painter = this.GetObject<Phaser.GameObjects.Graphics>("obj_brush")!;
painter.clear();
const soldierPhaserObjs = <Map<PlayerId, soldierIdToPhaserMap>>(
this.data.get("playerSoldiersGameObject")
);
for (let [playerId, soldierMap] of soldierPhaserObjs) {
for (let [soldierId, soldierPhaserObj] of soldierMap) {
const serverPos = <{ x: number; y: number }>(
soldierPhaserObj.getData("serverPosition")
);
painter.lineStyle(3, 0x000000, 1);
painter.strokeCircle(serverPos.x, serverPos.y, 32!);
}
}

const clientId = networkManager.getClientId();
const sessionState = networkManager.getState();
if (!sessionState || !clientId) return;
Expand All @@ -620,13 +633,7 @@ export class GameScene extends BaseScene {
clientId
);
playerState?.soldiers.forEach((value) => {
painter.lineStyle(1, 0x00ffee, 1);
painter.strokeCircle(
value.currentPositionX,
value.currentPositionY,
value.radius!
);

painter.lineStyle(3, 0xffffff, 1);
painter.strokeCircle(
value.expectedPositionX,
value.expectedPositionY,
Expand All @@ -643,6 +650,7 @@ export class GameScene extends BaseScene {
);
});
}

update(delta: number) {
this.renderDebugPath();
this.controls?.update(delta);
Expand All @@ -656,8 +664,8 @@ export class GameScene extends BaseScene {
soldierPhaserObj.getData("serverPosition")
);
soldierPhaserObj.setPosition(
Phaser.Math.Linear(soldierPhaserObj.x, serverPos.x, 0.5),
Phaser.Math.Linear(soldierPhaserObj.y, serverPos.y, 0.5)
Phaser.Math.Linear(soldierPhaserObj.x, serverPos.x, 0.15),
Phaser.Math.Linear(soldierPhaserObj.y, serverPos.y, 0.15)
);
}
}
Expand Down

0 comments on commit 8fd6b36

Please sign in to comment.