From 9d02266897293b822cd13e7082772bc86ef0087a Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Mon, 13 May 2019 15:50:50 -0500 Subject: [PATCH] chores and todo-list items for before poblication --- TODO.org | 8 ++++++++ server/TODO.org | 5 +++-- server/game.js | 6 ++++++ server/player.js | 1 + server/robot.js | 1 + web/draw.js | 47 +++++++++++++++++++++++++++++++++++++++++------ web/main.js | 17 ++++++++++------- 7 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 TODO.org diff --git a/TODO.org b/TODO.org new file mode 100644 index 0000000..61b33bd --- /dev/null +++ b/TODO.org @@ -0,0 +1,8 @@ +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/TODO.org b/server/TODO.org index a4db889..7500669 100644 --- a/server/TODO.org +++ b/server/TODO.org @@ -1,7 +1,8 @@ list of things i should still do: -- death screens -- waiting message - 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 on-screen messages for fitting (look to the 'magic number...' comment) diff --git a/server/game.js b/server/game.js index 0e43681..e9de5f3 100644 --- a/server/game.js +++ b/server/game.js @@ -28,6 +28,12 @@ Game.prototype.getNextFrame = function() { this.players[i].send_data(state); } + // check for only robots left + /*if(!this.players.some(x => !x.isARobot)) { // not true that some player isn't a robot + clearInterval(this.timeout); + health.dec(); + }*/ + // check for life and death var dead_ids = state.dead.map(d => d.id); if(dead_ids.length == state.n-1) { diff --git a/server/player.js b/server/player.js index ed64f78..0f8a7e2 100644 --- a/server/player.js +++ b/server/player.js @@ -3,6 +3,7 @@ function Player(ws) { this.status = 'x'; this.socket = ws; + this.isARobot = false; this.id = -1; // is this used? can i just delete? var _this = this; var fn = function(msg) { diff --git a/server/robot.js b/server/robot.js index 6f1fecf..0c1c356 100644 --- a/server/robot.js +++ b/server/robot.js @@ -6,6 +6,7 @@ const field = require('./field.js'); function Robot() { this.status = 'x'; + this.isARobot = true; } Robot.prototype.close = function() { diff --git a/web/draw.js b/web/draw.js index 0b3ca4d..0683686 100644 --- a/web/draw.js +++ b/web/draw.js @@ -112,15 +112,50 @@ var drawLine = function(ctx, color, c1, c2) { var drawOverlay = function(ctx, place) { ctx.save(); //ctx.font = what should it equal? mind sizes on mobile - ctx.setTransform(1,0,0,1,0,0); + ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2); ctx.fillStyle = 'rgba(225,225,225,100)' - var string1 = "you placed: " + place; - var string2 = "click or press =g= to play again" - ctx.fillText(string1, 0, 100); - ctx.fillText(string2, 0, 200); // magic number... + ctx.textAlign = 'center'; + ctx.fillText("you placed: " + place, 0, -7.5); + ctx.fillText("press =g= or click", 0, 0); // magic numbers... + ctx.fillText("to play again", 0, 7.5); ctx.restore(); } - + +var drawWaiting = function(ctx) { + ctx.save(); + ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2); + // i think that the above is unneccesary, but might as well be safe. Not like much is going on client-side + ctx.fillStyle = 'rgba(225,225,225,100)'; + ctx.textAlign = 'center'; + ctx.fillText("waiting for", 0, -5); + ctx.fillText("opponents...", 0, 5); + ctx.restore(); +} + +var drawOver = function(ctx) { + ctx.save(); + ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2); + ctx.fillStyle = 'rgba(225,225,225,100)' + ctx.textAlign = 'center'; + ctx.fillText("press =g= or click", 0, -5); + ctx.fillText("to play again", 0, 5); + ctx.restore(); + +} + +var drawBusy = function(ctx) { + clearCanvas(ctx); + ctx.save(); + ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2); + // i think that the above is unneccesary, but might as well be safe. Not like much is going on client-side + ctx.fillStyle = 'rgba(225,225,225,100)'; + ctx.textAlign = 'center'; + ctx.fillText("server is too busy now", 0, -7.5); + ctx.fillText("press =g= or click", 0, 0); // magic numbers... + ctx.fillText("to play again", 0, 7.5); + ctx.restore(); + +} var clearCanvas = function(ctx) { ctx.save(); diff --git a/web/main.js b/web/main.js index e9de705..3b6b465 100644 --- a/web/main.js +++ b/web/main.js @@ -17,21 +17,27 @@ var main = function() { // starts everything, gets us going, setup ish canvas.height = window.innerHeight; ctx = canvas.getContext('2d'); // 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.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2); ctx.lineWidth = ctx.lineWidth/5; - // this is just to have everything go easily for testing + // this is just to have everything go easily for testing, delete before final + /** var othersockets = []; for(var i=0; i main()); -- 2.39.2