Initial work on turn limit.
This commit is contained in:
parent
8ac5bc1e7c
commit
117a866820
85
cat.html
85
cat.html
|
@ -48,6 +48,9 @@ canvas {
|
||||||
var FONT = "BlueStone";
|
var FONT = "BlueStone";
|
||||||
// canvas style did have : border:1px solid #d3d3d3;
|
// canvas style did have : border:1px solid #d3d3d3;
|
||||||
|
|
||||||
|
|
||||||
|
var debug = true;
|
||||||
|
|
||||||
// game vars
|
// game vars
|
||||||
var things = [];
|
var things = [];
|
||||||
var score = 0;
|
var score = 0;
|
||||||
|
@ -172,6 +175,8 @@ var SCREENH = 640;
|
||||||
var GRAVITY = 0.5;
|
var GRAVITY = 0.5;
|
||||||
|
|
||||||
|
|
||||||
|
var TURNSLEFTTEXTSIZE = 12;
|
||||||
|
|
||||||
var TEXTSIZE = 16; // in points
|
var TEXTSIZE = 16; // in points
|
||||||
var TEXTSIZEMULTIPLIER = 28; // in points
|
var TEXTSIZEMULTIPLIER = 28; // in points
|
||||||
var TEXTSPEED = 0.5;
|
var TEXTSPEED = 0.5;
|
||||||
|
@ -957,6 +962,7 @@ var game = {
|
||||||
cheat: 0,
|
cheat: 0,
|
||||||
winimgsize: 0,
|
winimgsize: 0,
|
||||||
frameNo: 0,
|
frameNo: 0,
|
||||||
|
turnsleft: 0,
|
||||||
|
|
||||||
screenflash: 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('mousedown', this.handlemousedown, false);
|
||||||
this.canvas.addEventListener('mouseup', this.handlemouseup, false);
|
this.canvas.addEventListener('mouseup', this.handlemouseup, false);
|
||||||
this.canvas.addEventListener('mouseout', this.handlemouseup, false);
|
this.canvas.addEventListener('mouseout', this.handlemouseup, false);
|
||||||
|
@ -1099,6 +1112,10 @@ var game = {
|
||||||
things[i].counter = 0;
|
things[i].counter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
game.turnsleft--;
|
||||||
|
|
||||||
|
game.dirty = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
resize : function() {
|
resize : function() {
|
||||||
|
@ -1166,6 +1183,7 @@ var game = {
|
||||||
mylevel.thinglist = new Array();
|
mylevel.thinglist = new Array();
|
||||||
mylevel.forcelist = new Array();
|
mylevel.forcelist = new Array();
|
||||||
mylevel.allowedthings = new Array();
|
mylevel.allowedthings = new Array();
|
||||||
|
mylevel.maxturns = lev + 4; // default
|
||||||
|
|
||||||
if (lev == 1) {
|
if (lev == 1) {
|
||||||
mylevel.gridsize = DEF_GRIDSIZE;
|
mylevel.gridsize = DEF_GRIDSIZE;
|
||||||
|
@ -1304,25 +1322,30 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
|
||||||
this.levels[lev].starpoints[2] = p3;
|
this.levels[lev].starpoints[2] = p3;
|
||||||
},
|
},
|
||||||
|
|
||||||
calcstarpoints : function( lev ) {
|
calclevparams : function( lev ) {
|
||||||
var i,num;
|
var i,num;
|
||||||
var min = 0,pointsgoal = false;
|
var min = 0,pointsgoal = false;
|
||||||
|
var turnsreq = 0;
|
||||||
// calculate minimum points required to win
|
// calculate minimum points required to win
|
||||||
// first pass
|
// first pass
|
||||||
for (i = 0; i < this.levels[lev].goals.length; i++) {
|
for (i = 0; i < this.levels[lev].goals.length; i++) {
|
||||||
switch (this.levels[lev].goals[i].type) {
|
switch (this.levels[lev].goals[i].type) {
|
||||||
case "food":
|
case "food":
|
||||||
min += FOODPOINTS * this.levels[lev].goals[i].count;
|
min += FOODPOINTS * this.levels[lev].goals[i].count;
|
||||||
|
turnsreq += this.levels[lev].goals[i].count * 0.5;
|
||||||
break;
|
break;
|
||||||
case "llamas":
|
case "llamas":
|
||||||
// actually a bit more than this, since you need cats to get rid of llamas.
|
// actually a bit more than this, since you need cats to get rid of llamas.
|
||||||
min += (LLAMAPOINTS) * this.levels[lev].goals[i].count;
|
min += (LLAMAPOINTS) * this.levels[lev].goals[i].count;
|
||||||
|
turnsreq += this.levels[lev].goals[i].count * 2; // assume 1 llama every 2 turns
|
||||||
break;
|
break;
|
||||||
case "cats": // use smaller amount of catpoints
|
case "cats": // use smaller amount of catpoints
|
||||||
min += Math.min(CATPOINTS, SLEEPYCATPOINTS) * this.levels[lev].goals[i].count;
|
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;
|
break;
|
||||||
case "goats":
|
case "goats":
|
||||||
min += GOATPOINTS * this.levels[lev].goals[i].count;
|
min += GOATPOINTS * this.levels[lev].goals[i].count;
|
||||||
|
turnsreq += this.levels[lev].goals[i].count * 1;
|
||||||
break;
|
break;
|
||||||
case "turns":
|
case "turns":
|
||||||
// assume you'll get a parade on most 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
|
// double the value of a minimum-score parade
|
||||||
min += Math.min(CATPOINTS, SLEEPYCATPOINTS) * 3 * 2 * this.levels[lev].goals[i].count;
|
min += Math.min(CATPOINTS, SLEEPYCATPOINTS) * 3 * 2 * this.levels[lev].goals[i].count;
|
||||||
break;
|
break;
|
||||||
|
turnsreq += this.levels[lev].goals[i].count * 1;
|
||||||
case "sun cycles":
|
case "sun cycles":
|
||||||
min += SLEEPYCATPOINTS*5 * this.levels[lev].goals[i].count;
|
min += SLEEPYCATPOINTS*5 * this.levels[lev].goals[i].count;
|
||||||
|
turnsreq += this.levels[lev].gridh;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1347,15 +1372,18 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
|
||||||
//
|
//
|
||||||
|
|
||||||
// second pass - overrides
|
// second pass - overrides
|
||||||
/*
|
|
||||||
for (i = 0; i < this.levels[lev].goals.length; i++) {
|
for (i = 0; i < this.levels[lev].goals.length; i++) {
|
||||||
switch (this.levels[lev].goals[i].type) {
|
switch (this.levels[lev].goals[i].type) {
|
||||||
|
/*
|
||||||
case "points":
|
case "points":
|
||||||
pointsgoal = this.levels[lev].goals[i].count;
|
pointsgoal = this.levels[lev].goals[i].count;
|
||||||
break;
|
break;
|
||||||
|
*/
|
||||||
|
case "turns":
|
||||||
|
turnsreq = this.levels[lev].goals[i].count;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// adjust for level size
|
// adjust for level size
|
||||||
if (this.levels[lev].gridsize != DEF_GRIDSIZE) {
|
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[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[1] = Math.floor(Math.max(min * 2, pointsgoal*1.5));
|
||||||
this.levels[lev].starpoints[2] = Math.floor(Math.max(min * 3, pointsgoal*2));
|
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 ( ) {
|
initlevels : function ( ) {
|
||||||
|
@ -1444,7 +1476,7 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
|
||||||
var extrastars;
|
var extrastars;
|
||||||
// calc star point cutoffs
|
// calc star point cutoffs
|
||||||
if (this.levels[i].starpoints == undefined) {
|
if (this.levels[i].starpoints == undefined) {
|
||||||
this.calcstarpoints(i);
|
this.calclevparams(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// calc stars to unlock
|
// 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() {
|
drawgrid : function() {
|
||||||
/*
|
/*
|
||||||
this.context.strokeStyle = "red";
|
this.context.strokeStyle = "red";
|
||||||
|
@ -3489,6 +3561,9 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
|
||||||
// generate starpoint goal banner for top of screen
|
// generate starpoint goal banner for top of screen
|
||||||
game.generatestargoalbanner();
|
game.generatestargoalbanner();
|
||||||
|
|
||||||
|
// reset turns left
|
||||||
|
game.turnsleft = game.levels[curlevel].maxturns;
|
||||||
|
|
||||||
wipe.start("", "in", 50);
|
wipe.start("", "in", 50);
|
||||||
} else if (newstate == "levselect") {
|
} else if (newstate == "levselect") {
|
||||||
// reset grid size
|
// reset grid size
|
||||||
|
@ -4621,6 +4696,8 @@ function mainloop() {
|
||||||
game.clear();
|
game.clear();
|
||||||
// draw grid
|
// draw grid
|
||||||
game.drawgrid();
|
game.drawgrid();
|
||||||
|
// draw turns left
|
||||||
|
game.drawsides();
|
||||||
// draw non-animating objects
|
// draw non-animating objects
|
||||||
for (i = 0; i < things.length; i += 1) {
|
for (i = 0; i < things.length; i += 1) {
|
||||||
if (!things[i].isanimating()) {
|
if (!things[i].isanimating()) {
|
||||||
|
|
6
todo
6
todo
|
@ -23,8 +23,12 @@ multiplier for path length
|
||||||
|
|
||||||
turn limit.
|
turn limit.
|
||||||
... then get rid of 'form x parades' goal, just have 'clear x cats'
|
... 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'
|
... 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
|
...then add more levels
|
||||||
|
|
Loading…
Reference in New Issue