game: fix: create my player only if game start

This commit is contained in:
starnakin 2024-01-15 18:15:59 +01:00
parent a30ec46685
commit ff85c1d30c
2 changed files with 11 additions and 11 deletions

View File

@ -95,7 +95,7 @@ export default class extends AbstractView
ctx.beginPath()
ctx.clearRect(0, 0, this.game.config.size_x, this.game.config.size_y);
this.draw_sides(ctx, (this.game.players_id.length +0) * 2);
this.draw_sides(ctx, (this.game.players_id.length) * 2);
this.draw_ball(ctx, this.game.ball_pos_x, this.game.ball_pos_y);
ctx.strokeStyle = "#000000";
@ -111,7 +111,7 @@ export default class extends AbstractView
this.draw_game();
this.time.new_frame()
//clearInterval(loop_id);
}, 1000 / 50);
}, 1000 / 60);
}
register_key()
@ -128,6 +128,14 @@ export default class extends AbstractView
start_game()
{
let index = this.game.players.findIndex((player) => player.id);
if (index !== -1)
{
let my_player = this.game.players[index];
this.my_player = new MyPlayer(client, my_player.pos, my_player.nb_goal, my_player.game, this.time);
this.game.players[index] = this.my_player;
}
let canva = document.createElement("canvas");
canva.height = this.game.config.size_x;
@ -158,14 +166,6 @@ export default class extends AbstractView
if (error_code)
return error_code;
let index = this.game.players.findIndex((player) => player.id);
if (index !== -1)
{
let my_player = this.game.players[index];
this.my_player = new MyPlayer(client, my_player.pos, my_player.nb_goal, my_player.game, this.time);
this.game.players[index] = this.my_player;
}
this.update_game_state();
}

View File

@ -1,4 +1,4 @@
PADDLE_SPEED_PER_SECOND_MAX = 0.2
PADDLE_SPEED_PER_SECOND_MAX = 0.6
PADDLE_RATIO = 0.3
MAP_SIZE_X = 700