game: add: pladdle can move online with ping
This commit is contained in:
@ -118,23 +118,28 @@ class Game
|
||||
|
||||
if (index === -1)
|
||||
return
|
||||
|
||||
this.players.splice(index, 1);
|
||||
}
|
||||
|
||||
_receive_paddle_position(data)
|
||||
_receive_update_paddle(data)
|
||||
{
|
||||
data.players.forEach((player_data) => {
|
||||
let player = this.players.find((player) => player.id === player_data.id);
|
||||
if (player === null)
|
||||
return
|
||||
player.update_pos(player_data.position, player_data.time);
|
||||
})
|
||||
console.log(data)
|
||||
let player = this.players.find((player) => player.id === data.user_id);
|
||||
|
||||
if (player === null)
|
||||
{
|
||||
this._receive_player_join(data);
|
||||
return;
|
||||
}
|
||||
|
||||
player.update_pos(data.position.position, data.position.time);
|
||||
}
|
||||
|
||||
_receive(data)
|
||||
{
|
||||
if (data.detail === "paddle_position")
|
||||
this._receive_paddle_position(data);
|
||||
if (data.detail === "update_paddle")
|
||||
this._receive_update_paddle(data);
|
||||
else if (data.detail === "update_ball")
|
||||
this._update_ball(data);
|
||||
else if (data.detail === "init_game")
|
||||
|
Reference in New Issue
Block a user