*custom thing chance ratios for each level

*make llamas only start appearing a few levels in
This commit is contained in:
Rob Pearce 2016-08-21 11:31:19 +10:00
parent 19b2533010
commit 2e1198c7dc
2 changed files with 77 additions and 16 deletions

View File

@ -301,14 +301,19 @@ function isvalidpath(mypath) {
// would adding 'overthing' to our existing path result in a valid path? // would adding 'overthing' to our existing path result in a valid path?
function canextendpath(overthing) { function canextendpath(overthing) {
var pathtype;
if (!overthing) return false; if (!overthing) return false;
pathtype = getpathtype();
if ( isadjacent(overthing, curpath[curpath.length-1]) && // adjacent to last thing in path? if ( isadjacent(overthing, curpath[curpath.length-1]) && // adjacent to last thing in path?
!pathcontains(overthing) && // path doesn't already contain this? !pathcontains(overthing) && // path doesn't already contain this?
(getpathtype() == "parade" || isinpathdir(overthing)) // path in a straight line (pathtype == "parade" || isinpathdir(overthing)) // path in a straight line
) { ) {
// create a fake new path containing this. // create a fake new path containing this.
var fakepath = curpath.slice(); var fakepath = curpath.slice();
fakepath.push(overthing); fakepath.push(overthing);
if (isvalidpath(fakepath)) { if (isvalidpath(fakepath)) {
return true; return true;
@ -697,9 +702,20 @@ var game = {
mylevel = new Object(); mylevel = new Object();
mylevel.hashelp = hashelp; mylevel.hashelp = hashelp;
mylevel.goals = new Array(); mylevel.goals = new Array();
mylevel.thinglist = new Array();
this.levels[lev] = mylevel; this.levels[lev] = mylevel;
}, },
// thingtype pct
addlevelthings: function (lev) {
var i,idx;
for (i = 1 ; i < arguments.length; i += 2) {
idx = this.levels[lev].thinglist.push(new Object()) - 1;
this.levels[lev].thinglist[idx].type = arguments[i];
this.levels[lev].thinglist[idx].pct = arguments[i+1];
}
},
// goal1type goal1count goal2type goal2count etc... // goal1type goal1count goal2type goal2count etc...
addlevelgoals : function (lev) { addlevelgoals : function (lev) {
var i,idx; var i,idx;
@ -737,9 +753,14 @@ var game = {
this.levels = []; this.levels = [];
this.addlevel(1, true); this.addlevel(1, true);
this.addlevelgoals(1, "food", 10); this.addlevelgoals(1, "food", 10);
this.addlevelthings(1, "cat", 45, "food", 100);
this.addlevel(2, false); this.addlevel(2, false);
this.addlevelgoals(2, "points", 200); this.addlevelgoals(2, "points", 200);
this.addlevelthings(1, "cat", 45, "food", 100);
this.addlevel(3, false);
this.addlevelgoals(3, "points", 500);
/* /*
for (i = 1; i < this.levels.length; i++) { for (i = 1; i < this.levels.length; i++) {
@ -764,6 +785,8 @@ var game = {
var i; var i;
while (!anyvalidmoves()) { while (!anyvalidmoves()) {
var m; var m;
console.log("populating grid...");
clearthings(); clearthings();
// populate initial things // populate initial things
@ -1584,14 +1607,50 @@ function shadowtext(ctx, text, size, col, x, y) {
} }
function getrandomtype() { function getrandomtype() {
var pct,type; var pct,type = null,i;
pct = Math.random() * 100; var thinglist;
if ( pct < 45) {
type = "cat"; if (curlevel >= game.levels.length) {
} else if ( pct < 90) { thinglist = null;
type = "food";
} else { } else {
type = "llama"; thinglist = game.levels[curlevel].thinglist;
}
if (thinglist == undefined || thinglist.length == 0) {
// default thinglist
thinglist = [
{
type: 'cat',
pct: 45
},
{
type: 'food',
pct: 90
},
{
type: 'llama',
pct: 100
}
];
}
/*
console.log("thinglist length is " + thinglist.length);
for (i = 0; i < thinglist.length; i++) {
console.log(" thing " + i + " is " + thinglist[i].type + " pct " + thinglist[i].pct);
}
*/
pct = Math.random() * 100;
for (i = 0; i < thinglist.length; i++) {
if (pct <= thinglist[i].pct) {
type = thinglist[i].type;
break;
}
}
if (type == null) {
console.log("couldn't find type! pct is " + pct);
type = 'cat';
} }
return type; return type;
} }

18
todo
View File

@ -29,18 +29,20 @@ phone fixes as per http://www.html5rocks.com/en/mobile/touch/
https://www.smashingmagazine.com/2012/10/design-your-own-mobile-game/ https://www.smashingmagazine.com/2012/10/design-your-own-mobile-game/
custom thing chance ratios for each level *custom thing chance ratios for each level
1: no llamas *make llamas only start appearing a few levels in
2: no llamas
3: llamas
make llamas only start appearing a few levels in restrict catparades on level 1 -
cat can only go to cheese!
make help text for llamas come later make help text for llamas come later
llamas scaring cats (keep orig help around for reference)
parades can have one llama lv1 help: just how to eat cheese
lv2 help: just how to make cat parades
lv3 help:
llamas scaring cats
parades can have one llama
make initial help text jsut talk about paraes, no llamas
Level selection screen Level selection screen