diff options
-rw-r--r-- | game.js | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -244,22 +244,23 @@ function advancePhysics(deltaT) { } function setupBindings() { + var up = false, down = false; + + function padUpdate() { + padVel = (down - up) * padBaseSpeed; + socket.emit("padvec", padPos, padVel); + } + window.addEventListener("keydown", function(ev) { - if (ev.key == "w" || ev.key == "ArrowUp") { - padVel = -padBaseSpeed; - socket.emit("padvec", padPos, padVel); - } else if (ev.key == "s" || ev.key == "ArrowDown") { - padVel = padBaseSpeed; - socket.emit("padvec", padPos, padVel); - } + if (ev.key == "w" || ev.key == "ArrowUp") up = true; + else if (ev.key == "s" || ev.key == "ArrowDown") down = true; + padUpdate(); }); window.addEventListener("keyup", function(ev) { - if (ev.key == "w" || ev.key == "ArrowUp" || - ev.key == "s" || ev.key == "ArrowDown") { - padVel = 0; - socket.emit("padvec", padPos, padVel); - } + if (ev.key == "w" || ev.key == "ArrowUp") up = false; + else if (ev.key == "s" || ev.key == "ArrowDown") down = false; + padUpdate(); }); } |