game: add: player can leave and join game
This commit is contained in:
@ -56,7 +56,6 @@ class Game
|
||||
this.walls.forEach(wall => {
|
||||
wall.draw(ctx);
|
||||
});
|
||||
console.log(this.players)
|
||||
this.players.forEach(player => {
|
||||
player.draw(ctx);
|
||||
});
|
||||
@ -115,12 +114,11 @@ class Game
|
||||
{
|
||||
const user_id = player_data.user_id;
|
||||
|
||||
const index = this.players.find(player => player.id === user_id);
|
||||
const index = this.players.indexOf(this.players.find(player => player.id === user_id));
|
||||
|
||||
if (index === -1)
|
||||
return
|
||||
|
||||
this.players.slice(index, 1);
|
||||
this.players.splice(index, 1);
|
||||
}
|
||||
|
||||
_receive_paddle_position(data)
|
||||
@ -143,6 +141,8 @@ class Game
|
||||
this._init_game(data)
|
||||
else if (data.detail === "player_join")
|
||||
this._receive_player_join(data)
|
||||
else if (data.detail === "player_leave")
|
||||
this._receive_player_leave(data)
|
||||
}
|
||||
|
||||
_init_game(data)
|
||||
|
Reference in New Issue
Block a user