]> git.eli173.com Git - pong_br/commitdiff
paddles moving... seem to be reflecting and moving properly
authorElijah Cohen <eli@eli173.com>
Tue, 7 May 2019 21:47:17 +0000 (16:47 -0500)
committerElijah Cohen <eli@eli173.com>
Tue, 7 May 2019 21:47:17 +0000 (16:47 -0500)
.gitignore
web/input.js [new file with mode: 0644]
web/main.js
web/play.html

index 18810e985d8380b03ac2b45ffa59ce1c4fc53cee..4b4f86d8b719f6464d5ce3d83f968fcb658b6608 100644 (file)
@@ -37,3 +37,4 @@ server/node_modules/*
 /web/play.html~
 /server/collisions.js~
 /server/matrix.js~
+/web/input.js~
diff --git a/web/input.js b/web/input.js
new file mode 100644 (file)
index 0000000..3dde69f
--- /dev/null
@@ -0,0 +1,31 @@
+
+
+// handles all input
+
+var keystate = 'x'; // probably redundant? yeah
+var input = 'x';
+
+function keypressHandler(evt, isdn) {
+    // "is down" (is a keydown)
+    var thekey = 'x';
+    if(evt.keyCode == '87') // 'w'
+       thekey = 'u';
+    else if(evt.keyCode == '83') // 's'
+       thekey = 'd';
+    
+    if(!isdn && thekey==keystate) {
+       keystate = 'x';
+       input = 'x';
+       return;
+    }
+
+    if(thekey == 'd' || thekey == 'u') {
+       keystate = thekey;
+       input = thekey;
+    }
+}
+
+function keySender(ws) {
+    if(keystate != 'x')
+       ws.send(keystate);
+}
index 2ab0ca24fa81e26ed9dbf5c2d3e99b38927097ba..1ff3e8c957e0fd8b4f7686ca19b1cb516db3e18e 100644 (file)
@@ -15,19 +15,34 @@ var main = function() { // starts everything, gets us going, setup ish
     canvas.width = window.innerWidth;
     canvas.height = window.innerHeight;
     ctx = canvas.getContext('2d');
-    // change the 1's to zoom in i think.. todo
-    ctx.transform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2); // change to setTransform?
+    // i need to modify the 10's here to be appropriate given the scaling of the window
+    ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2); // change to setTransform?
     ctx.lineWidth = ctx.lineWidth/5;
+
+    
     // this is just to have everything go easily for testing
     var othersockets = [];
     for(var i=0; i<c.NUM_PLAYERS -1; i++) {
        othersockets.push(new WebSocket(prefixurl));
     }
+
     
     theSocket = new WebSocket(prefixurl);
     theSocket.onmessage = function(e) {
+       canvas.width = window.innerWidth;
+       canvas.height = window.innerHeight;
+       // change the 1's to zoom in i think.. todo
+       ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2); // change to setTransform?
+       ctx.lineWidth = ctx.lineWidth/5;
+       
        draw(JSON.parse(e.data), ctx);
     }
+
+    document.onkeydown = function(e) {keypressHandler(e, true);};
+    document.onkeyup = function(e) {keypressHandler(e, false);};
+    var interval = setInterval(function(){keySender(theSocket);}, c.MS_PER_FRAME);
+
+    theSocket.onclose = function(e) {clearInterval(interval)};
 }
 
 
index c7ab97cb539580b140c7e5fad3c2f45be11ffc91..fe485064bb4174ee611f39644b404310871835a5 100644 (file)
@@ -9,6 +9,7 @@
     <script type="text/javascript" src="main.js"></script>
     <script type="text/javascript" src="field.js"></script>
     <script type="text/javascript" src="endpoints.js"></script>
+    <script type="text/javascript" src="input.js"></script>
     <style type="text/css">
       body { background-color: black; }
       #c {