From: Elijah Cohen Date: Tue, 14 May 2019 21:08:55 +0000 (-0500) Subject: mobile works! X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=8ba9fc864aef6718cfba6ba5677e0e93bb4efbd5;p=pong_br mobile works! touch inputs operational, looks like the size of everything is okay too --- diff --git a/TODO.org b/TODO.org index 61b33bd..2317191 100644 --- a/TODO.org +++ b/TODO.org @@ -1,8 +1,6 @@ +important: +- second place losing message fix + list of things i should still do: - fix collisions -- fix oob -- splash page - fiddle with variables to optimize fun -- TOUCH -- fix game not ending with just robots (is this actually broken?) -- double check all messages for fitting (look to the 'magic number...' comment) diff --git a/server/constants.js b/server/constants.js index 72619d7..5d21ea4 100644 --- a/server/constants.js +++ b/server/constants.js @@ -7,7 +7,7 @@ var c = { FPS: 30, WAIT_TIME: 60000, // 1 minute MAX_GAMES: 2, // the most games allowed to go on at once, to be tweaked as needed for purposes - ROBO_TIME: 30, // time in seconds before filling out with robots + ROBO_TIME: 10, // time in seconds before filling out with robots // gamestate DYING_TIME_IN_FRAMES: 100, BOARD_RADIUS: 10, diff --git a/web/draw.js b/web/draw.js index dfd4e75..e7110d3 100644 --- a/web/draw.js +++ b/web/draw.js @@ -162,7 +162,7 @@ var drawBusy = function(ctx) { ctx.fillText("server is too busy now", 0, -7.5); ctx.fillText("press =g= or click/tap", 0, 0); // magic numbers... ctx.fillText("to play again", 0, 7.5); - ctx.restore(); + ctx.restore(); } var drawWin = function(ctx) { @@ -174,7 +174,7 @@ var drawWin = function(ctx) { ctx.fillText("WINNER!", 0, -7.5); ctx.fillText("press =g= or click/tap", 0, 0); // magic numbers... ctx.fillText("to play again", 0, 7.5); - ctx.restore(); + ctx.restore(); } var draw2nd = function(ctx) { @@ -189,6 +189,16 @@ var draw2nd = function(ctx) { ctx.restore(); } +var drawmsg = function(msg) { + clearCanvas(ctx); + ctx.save(); + ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2); + ctx.fillStyle = 'rgba(0,225,0,100)'; + ctx.textAlign = 'center'; + ctx.fillText(msg.toString(), 0, 0); + ctx.restore(); +} + var clearCanvas = function(ctx) { ctx.save(); ctx.clearRect(-ctx.canvas.width, -ctx.canvas.height, ctx.canvas.width*2, ctx.canvas.height*2); diff --git a/web/input.js b/web/input.js index 4d8f08b..7b943f6 100644 --- a/web/input.js +++ b/web/input.js @@ -44,13 +44,13 @@ function touchHandler(evt, isdn) { var touchy = evt.touches[0].clientY; // should be guaranteed to be nonempty i think var cvheight = document.getElementById("c").clientHeight; if(touchy > cvheight/2) { // may need to swap these if i'm hastily misunderstanding coordinates - keystate = 'd'; - input = 'd'; - } - else { keystate = 'u'; input = 'u'; } + else { + keystate = 'd'; + input = 'd'; + } } diff --git a/web/main.js b/web/main.js index d43b750..a3f5729 100644 --- a/web/main.js +++ b/web/main.js @@ -1,5 +1,5 @@ -const prefixurl = "ws://localhost:6789"; +const prefixurl = "ws://" + window.location.hostname + ":6789"; var theSocket = null; @@ -82,12 +82,11 @@ var main = function() { // starts everything, gets us going, setup ish document.onkeydown = function(e) {keypressHandler(e, true);}; document.onkeyup = function(e) {keypressHandler(e, false);}; - document.addEventListener('touchstart', function(e) {touchhandler(e, true);}); - document.addEventListener('touchstart', function(e) {touchhandler(e, false);}); + canvas.addEventListener('touchstart', function(e) {touchHandler(e, true);}); + canvas.addEventListener('touchend', function(e) {touchHandler(e, false);}); var interval = setInterval(function(){keySender(theSocket);}, c.MS_PER_FRAME); theSocket.onclose = function(e) {clearInterval(interval)}; } - window.addEventListener("DOMContentLoaded", e => main());