From 117a866820fc0cda8c38f8cf86a6ac1fb6ec5a4a Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Mon, 29 Aug 2016 04:21:42 +0000 Subject: [PATCH] Initial work on turn limit. --- cat.html | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- todo | 6 +++- 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/cat.html b/cat.html index 7b03cd2..90d2e46 100644 --- a/cat.html +++ b/cat.html @@ -48,6 +48,9 @@ canvas { var FONT = "BlueStone"; // canvas style did have : border:1px solid #d3d3d3; + +var debug = true; + // game vars var things = []; var score = 0; @@ -172,6 +175,8 @@ var SCREENH = 640; var GRAVITY = 0.5; +var TURNSLEFTTEXTSIZE = 12; + var TEXTSIZE = 16; // in points var TEXTSIZEMULTIPLIER = 28; // in points var TEXTSPEED = 0.5; @@ -957,6 +962,7 @@ var game = { cheat: 0, winimgsize: 0, frameNo: 0, + turnsleft: 0, screenflash: 0, @@ -1058,6 +1064,13 @@ var game = { }; })(); + + if (debug) { + window.onerror = function (errorMsg, url, lineNumber) { + alert('Error: ' + errorMsg + ' Script: ' + url + ' Line: ' + lineNumber); + }; + } + this.canvas.addEventListener('mousedown', this.handlemousedown, false); this.canvas.addEventListener('mouseup', this.handlemouseup, false); this.canvas.addEventListener('mouseout', this.handlemouseup, false); @@ -1099,6 +1112,10 @@ var game = { things[i].counter = 0; } } + + game.turnsleft--; + + game.dirty = true; }, resize : function() { @@ -1166,6 +1183,7 @@ var game = { mylevel.thinglist = new Array(); mylevel.forcelist = new Array(); mylevel.allowedthings = new Array(); + mylevel.maxturns = lev + 4; // default if (lev == 1) { mylevel.gridsize = DEF_GRIDSIZE; @@ -1304,25 +1322,30 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio); this.levels[lev].starpoints[2] = p3; }, - calcstarpoints : function( lev ) { + calclevparams : function( lev ) { var i,num; var min = 0,pointsgoal = false; + var turnsreq = 0; // calculate minimum points required to win // first pass for (i = 0; i < this.levels[lev].goals.length; i++) { switch (this.levels[lev].goals[i].type) { case "food": min += FOODPOINTS * this.levels[lev].goals[i].count; + turnsreq += this.levels[lev].goals[i].count * 0.5; break; case "llamas": // actually a bit more than this, since you need cats to get rid of llamas. min += (LLAMAPOINTS) * this.levels[lev].goals[i].count; + turnsreq += this.levels[lev].goals[i].count * 2; // assume 1 llama every 2 turns break; case "cats": // use smaller amount of catpoints min += Math.min(CATPOINTS, SLEEPYCATPOINTS) * this.levels[lev].goals[i].count; + turnsreq += this.levels[lev].goals[i].count * 2; // assume 1 cat every 2 turns break; case "goats": min += GOATPOINTS * this.levels[lev].goals[i].count; + turnsreq += this.levels[lev].goals[i].count * 1; break; case "turns": // assume you'll get a parade on most turns. @@ -1337,8 +1360,10 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio); // double the value of a minimum-score parade min += Math.min(CATPOINTS, SLEEPYCATPOINTS) * 3 * 2 * this.levels[lev].goals[i].count; break; + turnsreq += this.levels[lev].goals[i].count * 1; case "sun cycles": min += SLEEPYCATPOINTS*5 * this.levels[lev].goals[i].count; + turnsreq += this.levels[lev].gridh; break; } } @@ -1347,15 +1372,18 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio); // // second pass - overrides -/* for (i = 0; i < this.levels[lev].goals.length; i++) { switch (this.levels[lev].goals[i].type) { +/* case "points": pointsgoal = this.levels[lev].goals[i].count; break; +*/ + case "turns": + turnsreq = this.levels[lev].goals[i].count; + break; } } -*/ // adjust for level size if (this.levels[lev].gridsize != DEF_GRIDSIZE) { @@ -1371,6 +1399,10 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio); this.levels[lev].starpoints[0] = Math.floor(Math.max(min, pointsgoal)); this.levels[lev].starpoints[1] = Math.floor(Math.max(min * 2, pointsgoal*1.5)); this.levels[lev].starpoints[2] = Math.floor(Math.max(min * 3, pointsgoal*2)); + + if (turnsreq > this.levels[lev].maxturns) { + this.levels[lev].maxturns = turnsreq; + } }, initlevels : function ( ) { @@ -1444,7 +1476,7 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio); var extrastars; // calc star point cutoffs if (this.levels[i].starpoints == undefined) { - this.calcstarpoints(i); + this.calclevparams(i); } // calc stars to unlock @@ -3181,6 +3213,46 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio); }, + drawsides : function() { + var x,y,w,h,y2,h2; + var turnscol = "#00dddd"; + + /// left - turns left + x = 0; + y = BOARDY; + w = BOARDX-1; + h = GRIDH * GRIDSIZE; + + h2 = (game.turnsleft / game.levels[curlevel].maxturns) * (h-2); + y2 = y + (h - h2); + + // black background + ctx.fillStyle = "black"; + ctx.beginPath(); + ctx.rect(x+1,y+1,w-1,h-1); + ctx.stroke(); + + // turns left bar + if (game.turnsleft > 0) { + ctx.fillStyle = "blue"; + ctx.beginPath(); + ctx.rect(x+1,y2,w-1,h2); + ctx.stroke(); + + // turns left text + ctx.textAlign = "center"; + ctx.textBaseline = "top"; + shadowtext(ctx, game.turnsleft, TURNSLEFTTEXTSIZE, turnscol, x + (w/2), y2 + 2); + } + + // border + ctx.strokeStyle = "white"; + ctx.lineWidth = 2; + ctx.beginPath(); + ctx.rect(x,y,w,h); + ctx.stroke(); + }, + drawgrid : function() { /* this.context.strokeStyle = "red"; @@ -3489,6 +3561,9 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio); // generate starpoint goal banner for top of screen game.generatestargoalbanner(); + // reset turns left + game.turnsleft = game.levels[curlevel].maxturns; + wipe.start("", "in", 50); } else if (newstate == "levselect") { // reset grid size @@ -4621,6 +4696,8 @@ function mainloop() { game.clear(); // draw grid game.drawgrid(); + // draw turns left + game.drawsides(); // draw non-animating objects for (i = 0; i < things.length; i += 1) { if (!things[i].isanimating()) { diff --git a/todo b/todo index 1403c3e..fb587e5 100644 --- a/todo +++ b/todo @@ -23,8 +23,12 @@ multiplier for path length turn limit. ... then get rid of 'form x parades' goal, just have 'clear x cats' + *ticks down on L of board. + gameover if you run out + che k amoint calchlation ... then get rid of 'survive x turns' - ticks down on L of board. + replace with "get as many points as you can" + finish lev without min star points = game over ...then add more levels