From: Elijah Cohen Date: Tue, 7 May 2019 21:47:17 +0000 (-0500) Subject: paddles moving... seem to be reflecting and moving properly X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=d7ba8f02e4f5b8315d1b1125e13469cd0c08af46;p=pong_br paddles moving... seem to be reflecting and moving properly --- diff --git a/.gitignore b/.gitignore index 18810e9..4b4f86d 100644 --- a/.gitignore +++ b/.gitignore @@ -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 index 0000000..3dde69f --- /dev/null +++ b/web/input.js @@ -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); +} diff --git a/web/main.js b/web/main.js index 2ab0ca2..1ff3e8c 100644 --- a/web/main.js +++ b/web/main.js @@ -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 +