game: add: PADDLE CAN MOVE

This commit is contained in:
2024-01-15 17:54:58 +01:00
parent a2fbfa1937
commit a30ec46685
8 changed files with 154 additions and 49 deletions

View File

@ -1,9 +1,30 @@
import { Player } from "./Player";
import { Player } from "./Player.js";
class MyPlayer extends Player
{
constructor(client, pos, nb_goal, game, time)
{
super(client.me.id, pos, nb_goal, game);
this.time = time;
this.client = client;
}
update_paddle(keys_pressed)
{
let new_pos = this.pos;
if (keys_pressed.includes("s"))
new_pos -= this.game.config.paddle_speed_per_second_max * this.time.deltaTimeSecond();
if (keys_pressed.includes("w"))
new_pos += this.game.config.paddle_speed_per_second_max * this.time.deltaTimeSecond();
new_pos = Math.max(0 + this.game.config.paddle_ratio / 2, new_pos);
new_pos = Math.min(1 - this.game.config.paddle_ratio / 2, new_pos);
this.pos = new_pos;
this.game._send_paddle(this);
}
}
export {MyPlayer }
export { MyPlayer }