local pong done, start multiplayer implementation

This commit is contained in:
LuckyLaszlo
2022-10-26 22:21:55 +02:00
parent a831b7954c
commit d7aa2b633b
14 changed files with 350 additions and 323 deletions

46
src/client/handleInput.ts Normal file
View File

@@ -0,0 +1,46 @@
import * as g from "./pong.js"
import * as d from "./draw.js";
let gridDisplay = false;
function handleInput()
{
var keys = g.pong.keys;
if (keys.length == 0)
return;
if (keys.indexOf("g") != -1)
{
if (gridDisplay)
{
g.pong.clear();
d.drawStatic();
}
gridDisplay = !gridDisplay;
g.pong.deleteKey("g");
}
playerMove(keys);
}
function playerMove(keys: string[])
{
g.player1.dir.y = 0;
if (keys.indexOf("w") != -1) {
g.player1.dir.y += -1;
}
if (keys.indexOf("s") != -1) {
g.player1.dir.y += 1;
}
g.player1.moveAndCollide([g.wall_top, g.wall_bottom]);
g.player2.dir.y = 0;
if (keys.indexOf("ArrowUp".toLowerCase()) != -1) {
g.player2.dir.y += -1;
}
if (keys.indexOf("ArrowDown".toLowerCase()) != -1) {
g.player2.dir.y += 1;
}
g.player2.moveAndCollide([g.wall_top, g.wall_bottom]);
}
export {handleInput, gridDisplay}