local pong done, start multiplayer implementation
This commit is contained in:
46
src/client/handleInput.ts
Normal file
46
src/client/handleInput.ts
Normal 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}
|
||||
Reference in New Issue
Block a user