player pos is checked
This commit is contained in:
@ -16,6 +16,7 @@ class Game
|
||||
this.client = client;
|
||||
this.id = id;
|
||||
this.keys_pressed = [];
|
||||
this.last_pos = null
|
||||
}
|
||||
|
||||
async init()
|
||||
@ -57,6 +58,7 @@ class Game
|
||||
{
|
||||
if (this._socket === undefined)
|
||||
return;
|
||||
|
||||
const loop_id = setInterval(() => {
|
||||
if (this._socket.readyState === WebSocket.OPEN)
|
||||
{
|
||||
@ -66,24 +68,25 @@ class Game
|
||||
}, 500);
|
||||
}
|
||||
|
||||
_send_paddle(my_player)
|
||||
_send_paddle(position, time)
|
||||
{
|
||||
this._send({"detail": "update_my_paddle_pos", "position": my_player.pos});
|
||||
if (this.last_pos !== null && this.last_pos.time >= time)
|
||||
return;
|
||||
|
||||
this.last_pos = {"time": time, "position": position};
|
||||
|
||||
this._send({"detail": "update_my_paddle_pos", ...this.last_pos});
|
||||
}
|
||||
|
||||
_update_paddles(data)
|
||||
{
|
||||
data.forEach(player_data => {
|
||||
let player = this.players.find(player_data2 => player_data2.id === player_data)
|
||||
|
||||
console.log(data)
|
||||
data.players.forEach((player_data) => {
|
||||
let player = this.players.find((player) => player.id === player_data.id);
|
||||
if (player === null)
|
||||
{
|
||||
console.error("error 1000: je ne comprends pas");
|
||||
return;
|
||||
}
|
||||
|
||||
player.pos = player_data.pos;
|
||||
});
|
||||
return
|
||||
player.update_pos(player_data.position, player_data.time);
|
||||
})
|
||||
}
|
||||
|
||||
_update_ball(data)
|
||||
@ -96,6 +99,7 @@ class Game
|
||||
|
||||
_update(data)
|
||||
{
|
||||
console.log("bozo2", data)
|
||||
if (data.detail === "update_paddles")
|
||||
this._update_paddles(data);
|
||||
else if (data.detail === "update_ball")
|
||||
|
Reference in New Issue
Block a user