game: core: use server game calulation form
This commit is contained in:
@ -12,7 +12,6 @@ export default class extends AbstractView
|
||||
super(params, "Game");
|
||||
this.game = new Game(client, params.id);
|
||||
this.keys_pressed = [];
|
||||
this.time = new Time();
|
||||
this.my_player = undefined;
|
||||
}
|
||||
|
||||
@ -33,7 +32,13 @@ export default class extends AbstractView
|
||||
{
|
||||
let ctx = document.getElementById('canva').getContext('2d');
|
||||
|
||||
ctx.beginPath();
|
||||
|
||||
this.game.draw(ctx);
|
||||
|
||||
ctx.strokeStyle = "#000000";
|
||||
ctx.lineWidth = 10;
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
render_game()
|
||||
@ -42,8 +47,8 @@ export default class extends AbstractView
|
||||
if (this.my_player)
|
||||
this.my_player.update_paddle(this.keys_pressed);
|
||||
this.draw();
|
||||
this.time.new_frame();
|
||||
//clearInterval(loop_id);
|
||||
this.game.time.new_frame();
|
||||
clearInterval(loop_id);
|
||||
// 1 sec fps
|
||||
}, 1000 / 60);
|
||||
}
|
||||
@ -60,15 +65,9 @@ export default class extends AbstractView
|
||||
document.removeEventListener('keyup', this.keyStretchHandler);
|
||||
}
|
||||
|
||||
start_game()
|
||||
async 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;
|
||||
}
|
||||
await this.game.join()
|
||||
|
||||
let canva = document.createElement("canvas");
|
||||
|
||||
@ -78,19 +77,33 @@ export default class extends AbstractView
|
||||
|
||||
document.getElementById("app").appendChild(canva);
|
||||
|
||||
this.game.join()
|
||||
|
||||
this.register_key()
|
||||
|
||||
this.render_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,
|
||||
this.game,
|
||||
my_player.rail_start_x,
|
||||
my_player.rail_start_y,
|
||||
my_player.rail_stop_y,
|
||||
my_player.rail_stop_y,
|
||||
my_player.nb_goal,
|
||||
my_player.positon,
|
||||
);
|
||||
this.game.players[index] = this.my_player;
|
||||
}
|
||||
}
|
||||
|
||||
update_game_state()
|
||||
async update_game_state()
|
||||
{
|
||||
document.getElementById("game-state").innerText = this.game.state;
|
||||
|
||||
if (this.game.started === true && this.game.finished === false)
|
||||
this.start_game();
|
||||
await this.start_game();
|
||||
}
|
||||
|
||||
async postInit()
|
||||
@ -100,7 +113,7 @@ export default class extends AbstractView
|
||||
if (error_code)
|
||||
return error_code;
|
||||
|
||||
this.update_game_state();
|
||||
await this.update_game_state();
|
||||
}
|
||||
|
||||
async leavePage()
|
||||
|
Reference in New Issue
Block a user