--- /dev/null
+
+
+// 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);
+}
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)};
}
<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 {