game: fix: create my player only if game start
This commit is contained in:
parent
a30ec46685
commit
ff85c1d30c
@ -95,7 +95,7 @@ export default class extends AbstractView
|
|||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
|
|
||||||
ctx.clearRect(0, 0, this.game.config.size_x, this.game.config.size_y);
|
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);
|
this.draw_ball(ctx, this.game.ball_pos_x, this.game.ball_pos_y);
|
||||||
|
|
||||||
ctx.strokeStyle = "#000000";
|
ctx.strokeStyle = "#000000";
|
||||||
@ -111,7 +111,7 @@ export default class extends AbstractView
|
|||||||
this.draw_game();
|
this.draw_game();
|
||||||
this.time.new_frame()
|
this.time.new_frame()
|
||||||
//clearInterval(loop_id);
|
//clearInterval(loop_id);
|
||||||
}, 1000 / 50);
|
}, 1000 / 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
register_key()
|
register_key()
|
||||||
@ -128,6 +128,14 @@ export default class extends AbstractView
|
|||||||
|
|
||||||
start_game()
|
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");
|
let canva = document.createElement("canvas");
|
||||||
|
|
||||||
canva.height = this.game.config.size_x;
|
canva.height = this.game.config.size_x;
|
||||||
@ -158,14 +166,6 @@ export default class extends AbstractView
|
|||||||
if (error_code)
|
if (error_code)
|
||||||
return 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();
|
this.update_game_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
PADDLE_SPEED_PER_SECOND_MAX = 0.2
|
PADDLE_SPEED_PER_SECOND_MAX = 0.6
|
||||||
PADDLE_RATIO = 0.3
|
PADDLE_RATIO = 0.3
|
||||||
|
|
||||||
MAP_SIZE_X = 700
|
MAP_SIZE_X = 700
|
||||||
|
Loading…
Reference in New Issue
Block a user