server reconciliation OK (a little rubberbanding)

This commit is contained in:
LuckyLaszlo
2022-11-23 10:43:12 +01:00
parent 2b9058ad49
commit 7d5895a6cc
10 changed files with 110 additions and 33 deletions

View File

@@ -50,8 +50,11 @@ class GameSession {
clearInterval(s.gameLoopInterval);
clearInterval(s.clientsUpdateInterval);
}
handleInput(client: ClientPlayer, input: en.InputEnum) {
handleInput(client: ClientPlayer, inputEvent: ev.EventInput) {
const gc = this.components;
const input = inputEvent.input;
client.lastInputId = inputEvent.inputId;
client.racket.dir.y = 0;
if (input === en.InputEnum.up) {
client.racket.dir.y += -1;
@@ -96,9 +99,11 @@ class GameSession {
type: en.EventTypes.gameUpdate,
playerLeft: {y: gc.playerLeft.pos.y},
playerRight: {y: gc.playerRight.pos.y},
ball: {x: gc.ball.pos.x, y: gc.ball.pos.y, speed: gc.ball.speed}
ball: {x: gc.ball.pos.x, y: gc.ball.pos.y, speed: gc.ball.speed},
lastInputId: 0
};
s.playersMap.forEach( (client) => {
update.lastInputId = client.lastInputId;
client.socket.send(JSON.stringify(update));
});
}