aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game.js25
1 files changed, 13 insertions, 12 deletions
diff --git a/game.js b/game.js
index a2d5552..fa8ff23 100644
--- a/game.js
+++ b/game.js
@@ -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();
});
}