game: core: use draw method instead draw_CLASSNAME

This commit is contained in:
2024-01-16 23:27:56 +01:00
parent 516ccdc297
commit e0990db8d1
5 changed files with 128 additions and 78 deletions

View File

@ -1,18 +1,51 @@
class Player
{
constructor(id, pos, nb_goal, game)
constructor(id, pos, nb_goal, game, rail_start_x, rail_start_y, rail_stop_x, rail_stop_y)
{
this.id = id;
this.pos = pos;
this.nb_goal = nb_goal;
this.game = game;
this.rail_start_x = rail_start_x;
this.rail_start_y = rail_start_y;
this.rail_stop_x = rail_stop_x;
this.rail_stop_y = rail_stop_y;
this.rail_size = Math.abs(this.rail_stop_x - this.rail_start_x) + Math.abs(this.rail_stop_y - this.rail_start_y)
this.paddle_size = this.rail_size * this.game.config.paddle_ratio;
this.diff_x = this.rail_stop_x - this.rail_start_x,
this.diff_y = this.rail_stop_y - this.rail_start_y;
}
update_pos(new_position, time)
{
this.pos = new_position;
}
draw(ctx)
{
let paddle_pos_x = this.rail_start_x + this.diff_x * this.pos,
paddle_pos_y = this.rail_start_y + this.diff_y * this.pos;
console.log(this)
let start_x = paddle_pos_x - (this.diff_x * (this.paddle_size / 2 / this.rail_size)),
start_y = paddle_pos_y - (this.diff_y * (this.paddle_size / 2 / this.rail_size)),
stop_x = paddle_pos_x + (this.diff_x * (this.paddle_size / 2 / this.rail_size)),
stop_y = paddle_pos_y + (this.diff_y * (this.paddle_size / 2 / this.rail_size));
console.log(start_x, stop_x);
console.log(start_y, stop_y)
ctx.moveTo(start_x, start_y);
ctx.lineTo(stop_x, stop_y);
ctx.moveTo(this.rail_stop_x, this.rail_stop_y);
}
}
export { Player }