fix: game: 2d work
This commit is contained in:
@ -13,7 +13,7 @@ export class MyPlayer extends PongPlayer
|
||||
* @param {[Number]} score
|
||||
* @param {Position} position
|
||||
*/
|
||||
constructor(client, game, score, rail, position = new Position())
|
||||
constructor(client, game, score, rail, position = new Position(0.5))
|
||||
{
|
||||
super(client, game, client.me.id, client.me.username, client.me.avatar, score, rail, position, true);
|
||||
/**
|
||||
@ -62,22 +62,22 @@ export class MyPlayer extends PongPlayer
|
||||
*/
|
||||
updatePaddle(keys_pressed)
|
||||
{
|
||||
let new_pos = this.position;
|
||||
let new_location = this.position.location;
|
||||
|
||||
keys_pressed.forEach(key => {
|
||||
if (this.downKeys.includes(key))
|
||||
new_pos += this.game.config.paddle_speed_per_second_max * this.game.time.deltaTimeSecond();
|
||||
new_location += this.game.config.PADDLE_SPEED_PER_SECOND_MAX * this.game.time.deltaTimeSecond();
|
||||
if (this.upKeys.includes(key))
|
||||
new_pos -= this.game.config.paddle_speed_per_second_max * this.game.time.deltaTimeSecond();
|
||||
new_location -= this.game.config.PADDLE_SPEED_PER_SECOND_MAX * this.game.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);
|
||||
new_location = Math.max(0 + this.game.config.PADDLE_RATIO / 2, new_location);
|
||||
new_location = Math.min(1 - this.game.config.PADDLE_RATIO / 2, new_location);
|
||||
|
||||
if (this.position === new_pos)
|
||||
if (this.position.location === new_location)
|
||||
return;
|
||||
|
||||
this.position = new_pos;
|
||||
this.position.location = new_location;
|
||||
|
||||
this._sendPaddlePosition();
|
||||
}
|
||||
|
Reference in New Issue
Block a user