*only increase chance of goal items if you haven't already met the goal.

*make increase chance work for "special" things!!! (eg. white cat)
*stop increasing goal progress once we hit the required amount
*seperate goal names and goal associated things
This commit is contained in:
Rob Pearce 2016-08-30 19:46:40 +10:00
parent 62f7b20a88
commit b5dedbe0ad
2 changed files with 84 additions and 27 deletions

View File

@ -96,6 +96,10 @@ var GOALVERB = {
'whitecat': 'Attack', 'whitecat': 'Attack',
}; };
var GOALNAME = {
'whitecat': 'white cat',
};
var prizetypes = [ var prizetypes = [
"tissues", "shears", "magiccarpet", "tissues", "shears", "magiccarpet",
]; ];
@ -1390,7 +1394,15 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
//console.log("progress()"); //console.log("progress()");
for (i = 0 ; i < this.levels[curlevel].goals.length; i++ ) { for (i = 0 ; i < this.levels[curlevel].goals.length; i++ ) {
//console.log("this goal type is " + this.levels[curlevel].goals[i].type); //console.log("this goal type is " + this.levels[curlevel].goals[i].type);
// already met the goal?
if (this.levels[curlevel].goals[i].progress >= this.levels[curlevel].goals[i].count) {
continue;
}
// goal matches what we just progressed in?
if (this.levels[curlevel].goals[i].type == type) { if (this.levels[curlevel].goals[i].type == type) {
// increase progress.
this.levels[curlevel].goals[i].progress += amt; this.levels[curlevel].goals[i].progress += amt;
if (this.levels[curlevel].goals[i].progress >= this.levels[curlevel].goals[i].count) { if (this.levels[curlevel].goals[i].progress >= this.levels[curlevel].goals[i].count) {
@ -1404,8 +1416,6 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
} }
}, },
calcstars : function (lev, points) { calcstars : function (lev, points) {
var i; var i;
for (i = 2; i >= 0; i--) { for (i = 2; i >= 0; i--) {
@ -1881,6 +1891,7 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
var x,y; var x,y;
var margin = 10; var margin = 10;
var indent = 50; var indent = 50;
var progindent = 25;
var boxindent = 20; var boxindent = 20;
//ctx = this.context; //ctx = this.context;
@ -1931,15 +1942,23 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
goalcol = "#aaee00"; goalcol = "#aaee00";
} }
// goal name // goal description
var ess = "s"; var ess = "s";
if (this.levels[curlevel].goals[n].count == 1) { if (this.levels[curlevel].goals[n].count == 1) {
ess = ""; ess = "";
} }
var goalname;
if (GOALNAME[this.levels[curlevel].goals[n].type] == undefined) {
goalname = this.levels[curlevel].goals[n].type;
} else {
goalname = GOALNAME[this.levels[curlevel].goals[n].type];
}
var goaltext = GOALVERB[this.levels[curlevel].goals[n].type] + " " + var goaltext = GOALVERB[this.levels[curlevel].goals[n].type] + " " +
this.levels[curlevel].goals[n].count + " " + this.levels[curlevel].goals[n].count + " " +
this.levels[curlevel].goals[n].type + ess; goalname + ess;
var progtext = "[" + this.levels[curlevel].goals[n].progress + " / " + var progtext = "[" + this.levels[curlevel].goals[n].progress + " / " +
this.levels[curlevel].goals[n].count + "]"; this.levels[curlevel].goals[n].count + "]";
@ -1950,7 +1969,8 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
ctx.textAlign = "right"; ctx.textAlign = "right";
ctx.textBaseline = "top"; ctx.textBaseline = "top";
shadowtext(ctx, progtext, GOALTEXTSIZE,goalcol, SCREENW-indent, y);
shadowtext(ctx, progtext, GOALTEXTSIZE,goalcol, SCREENW-progindent, y);
// completed? // completed?
if (goalmet) { if (goalmet) {
@ -4080,6 +4100,8 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
ctx.stroke(); ctx.stroke();
// right: bags // right: bags
var SMALLBAGAMT = 0.2;
if (game.levels[curlevel].bags != undefined) { if (game.levels[curlevel].bags != undefined) {
for (i = 0; i < game.levels[curlevel].bags.length; i++) { for (i = 0; i < game.levels[curlevel].bags.length; i++) {
var bagh,thisbag; var bagh,thisbag;
@ -4087,8 +4109,8 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
x = BOARDX + (GRIDW * GRIDSIZE); x = BOARDX + (GRIDW * GRIDSIZE);
y = BOARDY + (thisbag.y * GRIDSIZE); y = BOARDY + (thisbag.y * GRIDSIZE);
if (thisbag.cats < thisbag.capacity) { if (thisbag.cats < thisbag.capacity) {
bagh = THINGSIZE*0.1; // base height bagh = THINGSIZE*SMALLBAGAMT; // base height
bagh += (thisbag.cats / thisbag.capacity) * (THINGSIZE*0.9); // increase based on fullness bagh += (thisbag.cats / thisbag.capacity) * (THINGSIZE*(1-SMALLBAGAMT)); // increase based on fullness
ctx.drawImage(image['bag'], x, y + GRIDSIZE/2 - bagh/2, THINGSIZE, bagh); ctx.drawImage(image['bag'], x, y + GRIDSIZE/2 - bagh/2, THINGSIZE, bagh);
} else if (thisbag.prize != "") { // not collected yet } else if (thisbag.prize != "") { // not collected yet
var size = SCREENW - (GRIDW*GRIDSIZE + BOARDX) ; var size = SCREENW - (GRIDW*GRIDSIZE + BOARDX) ;
@ -4173,6 +4195,15 @@ console.log("lev " + lev + " newwid " + newwid + " ratio " + ratio);
console.log("chear() - ending game"); console.log("chear() - ending game");
game.setstate("gameover"); game.setstate("gameover");
game.cheat = 1; game.cheat = 1;
} else if (ch == 'i') {
var what;
what = getthingxy(lastmx, lastmy);
if (what != undefined) {
console.log("info for " + what.name);
console.log(what);
}
} else if (ch == 'c') { } else if (ch == 'c') {
playerdata.clearall(); playerdata.clearall();
} else if (ch == 'f') { } else if (ch == 'f') {
@ -4821,7 +4852,7 @@ function getrandomtype() {
} }
// construct a list of permitted special things // construct a list of permitted special things
var poss = [ "sunlight", "toad", "whitecat" ] ; var poss = [ "door", "sunlight", "toad", "whitecat" ] ;
for (i in poss ) { for (i in poss ) {
if (!game.isbanned(curlevel, poss[i])) { if (!game.isbanned(curlevel, poss[i])) {
if (speciallist == undefined) { if (speciallist == undefined) {
@ -4839,7 +4870,7 @@ function getrandomtype() {
// default thinglist // default thinglist
// must be sorted from low to high! // must be sorted from low to high!
if (!game.isbanned(curlevel, 'door')) thinglist.push({ type: 'door', pct: 10 } ); //if (!game.isbanned(curlevel, 'door')) thinglist.push({ type: 'door', pct: 10 } );
if (speciallist != undefined) { if (speciallist != undefined) {
if (dodb) console.log("specials are possible"); if (dodb) console.log("specials are possible");
thinglist.push({ type: 'special', pct: 5 } ); thinglist.push({ type: 'special', pct: 5 } );
@ -4850,6 +4881,7 @@ function getrandomtype() {
if (!game.isbanned(curlevel, 'cat')) thinglist.push({ type: 'cat', pct: 45 } ); if (!game.isbanned(curlevel, 'cat')) thinglist.push({ type: 'cat', pct: 45 } );
} }
// increase the chance of something appearing if // increase the chance of something appearing if
// a. it's a goal // a. it's a goal
// b. we don't have any // b. we don't have any
@ -4857,16 +4889,41 @@ function getrandomtype() {
var n; var n;
for (i = 0; i < thinglist.length; i++) { for (i = 0; i < thinglist.length; i++) {
for (n = 0 ; n < game.levels[curlevel].goals.length; n++ ) { for (n = 0 ; n < game.levels[curlevel].goals.length; n++ ) {
if (game.levels[curlevel].goals[n].type == thinglist[i].type) { var matchesgoal = false;
var thingtype = thinglist[i].type
var goaltype = game.levels[curlevel].goals[n].type;
var lookforthing;
if (game.levels[curlevel].goals[n].progress < game.levels[curlevel].goals[n].count) {
if (goaltype == thingtype) {
matchesgoal = true;
lookforthing = thingtype;
} else if ((thingtype == "special") &&
speciallist.indexOf(goaltype) != -1) {
// change it.
lookforthing = goaltype;
matchesgoal = true;
}
}
if (matchesgoal) {
var count; var count;
console.log("****** " + thinglist[i].type + " matches goal."); console.log("****** " + thingtype + " matches goal.");
// check if any exist // check if any exist
count = countalivethingsoftype(thinglist[i].type); count = countalivethingsoftype(lookforthing);
if (count <= 1) { if (count <= 1) {
console.log("****** no things of type " + thinglist[i].type); console.log("****** no things of type " + lookforthing);
// extra chance! // extra chance!
thinglist[i].pct *= 3; thinglist[i].pct *= 4;
console.log("double chance of " + thinglist[i].type); console.log("extra chance of " + thingtype + "(" + lookforthing + ")");
// if the thing in question is 'special',
// cheat on the random check later to make sure we
// only get the right kind of special thing.
if (thingtype == "special") {
speciallist.splice(0, speciallist.length);
speciallist.push(goaltype);
}
} }
} }
} }
@ -5054,7 +5111,7 @@ function thing(gridx, gridy, type, text, col) {
this.canfall = function() { this.canfall = function() {
// doors can't fall after their initial drop // doors can't fall after their initial drop
if (this.type == "door") { if (this.type == "door") {
if ((this.gridy >= 0) && (this.new == false)) { if ((this.gridy >= 0) && (this.isnew == false)) {
return false; return false;
} }
} }

22
todo
View File

@ -9,24 +9,24 @@ https://www.smashingmagazine.com/2012/10/design-your-own-mobile-game/
https://www.smashingmagazine.com/2012/10/design-your-own-mobile-game/ https://www.smashingmagazine.com/2012/10/design-your-own-mobile-game/
--- check here for ios --- check here for ios
-------------------
*special: toad - slap to make it drop down and clear objects below. *only increase chance of goal items if you haven't already met the goal.
*special: white cat : destroys stuff around it *make increase chance work for "special" things!!! (eg. white cat)
*increase changes of a goal things appearing if none exist. *stop increasing goal progress once we hit the required amount
*seperate goal names and goal associated things
make increasechance work for "special" things!!! OBSTACLES on later levels
fixed position.
other colour cats
separate goal names and goal associated things
other colour cat
more goals:
form x parades of length y
-------------- --------------
more goals:
form x parades of length y
more prizes: ??? more prizes: ???
mouse - place to clear all cats in grid/column mouse - place to clear all cats in grid/column
whitecat - place to clear 3 x 3 grid around it whitecat - place to clear 3 x 3 grid around it