game: fix: reload view work

This commit is contained in:
starnakin 2024-02-27 09:38:37 +01:00 committed by AdrienLSH
parent 049c7a500d
commit 16180520de

View File

@ -12,9 +12,7 @@ export default class extends AbstractView
constructor(params)
{
super(params, "Game");
this.game = new Game(client, params.id, this.on_goal, this.on_finish);
this.keys_pressed = [];
this.my_player = undefined;
this.game_id = params.id;
}
keyReleaseHandler(event)
@ -76,7 +74,7 @@ export default class extends AbstractView
clearInterval(loop_id);
this.my_player?.update_paddle(this.keys_pressed);
this.render_game();
this.game?.time.new_frame();
this.game?.time?.new_frame();
//clearInterval(loop_id);
// 1 sec fps
}, 1000 / 60);
@ -170,8 +168,6 @@ export default class extends AbstractView
data = [{x: 0, y: 0}, ...data];
console.log(data);
data.push({x: Math.round((this.game.stop_timestamp - this.game.start_timestamp) / 1000),
y: data[data.length - 1].y});
@ -234,6 +230,10 @@ export default class extends AbstractView
async postInit()
{
this.game = new Game(client, this.game_id, this.on_goal, this.on_finish);
this.keys_pressed = [];
this.my_player = undefined;
let error_code = await this.game.init();
if (error_code)
@ -249,6 +249,7 @@ export default class extends AbstractView
this.game.leave();
this.game = undefined;
}
this.game = undefined;
this.unregister_key();
}