game: fix: support horizontal player
This commit is contained in:
parent
6ca02fc4d5
commit
8bbfd96dd6
@ -20,7 +20,35 @@ class MyPlayer extends Player
|
||||
*/
|
||||
this.client = client;
|
||||
|
||||
this.increment_sign = this.rail.start.y > this.rail.stop.y ? 1 : -1;
|
||||
this.upKeys = [];
|
||||
this.downKeys = [];
|
||||
console.log(rail.start.x, rail.stop.x)
|
||||
if (rail.start.x != rail.stop.x)
|
||||
{
|
||||
if (rail.start.x < rail.stop.x)
|
||||
{
|
||||
this.upKeys.push("a");
|
||||
this.downKeys.push("d");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.upKeys.push("d");
|
||||
this.downKeys.push("a");
|
||||
}
|
||||
}
|
||||
if (rail.start.y != rail.stop.y)
|
||||
{
|
||||
if (rail.start.y > rail.stop.y)
|
||||
{
|
||||
this.upKeys.push("w");
|
||||
this.downKeys.push("s");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.upKeys.push("s");
|
||||
this.downKeys.push("w");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,10 +58,13 @@ class MyPlayer extends Player
|
||||
{
|
||||
let new_pos = this.position;
|
||||
|
||||
if (keys_pressed.includes("s"))
|
||||
new_pos -= this.game.config.paddle_speed_per_second_max * this.game.time.deltaTimeSecond() * 1.0 * this.increment_sign;
|
||||
if (keys_pressed.includes("w"))
|
||||
new_pos += this.game.config.paddle_speed_per_second_max * this.game.time.deltaTimeSecond() * 1.0 * this.increment_sign;
|
||||
keys_pressed.forEach(key => {
|
||||
if (this.downKeys.includes(key))
|
||||
new_pos += 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_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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user