Randomise brick layout on random levels.
This commit is contained in:
parent
3088b74816
commit
2e83f351aa
185
cat.html
185
cat.html
|
@ -1632,7 +1632,9 @@ var game = {
|
|||
},
|
||||
|
||||
genrandomlevel : function (lev) {
|
||||
var ngoals,i,pctleft;
|
||||
var ngoals,i,n,pctleft;
|
||||
var nbricks = 0,bricktype, xmin,ymin,xmax,ymax,totbricks = 0, wantbricks;
|
||||
var gw,gh;
|
||||
|
||||
// set random seed based on level
|
||||
game.setrndseed(lev+50);
|
||||
|
@ -1644,6 +1646,9 @@ var game = {
|
|||
game.addlevel(lev, false);
|
||||
}
|
||||
|
||||
gw = game.levels[lev].gridw;
|
||||
gh = game.levels[lev].gridh;
|
||||
|
||||
// generate goals
|
||||
pctleft = 100;
|
||||
for (i = 0; i < ngoals; i++) {
|
||||
|
@ -1684,11 +1689,185 @@ console.log("genrandomlev() - lev " + lev + " goal " + i + " type=" + game.leve
|
|||
if (count < 1) count = 1;
|
||||
|
||||
game.levels[lev].goals[i].count = count;
|
||||
}
|
||||
|
||||
// add forced things based on goals
|
||||
|
||||
// add random bricks - 66% chance
|
||||
nbricks = 0;
|
||||
brickpos = new Array();
|
||||
bricktype = game.seedrnd(1,4);
|
||||
//bricktype = 4;
|
||||
if (game.seedrnd(1,3) > 1) {
|
||||
wantbricks = true;
|
||||
} else {
|
||||
wantbricks = false;
|
||||
}
|
||||
//wantbricks = true;
|
||||
|
||||
if (wantbricks) {
|
||||
switch (bricktype) {
|
||||
case 1: // random
|
||||
nbricks = game.seedrnd(1,8); // ie. max 8
|
||||
xmin = 0;
|
||||
ymin = 0;
|
||||
xmax = gw-1;
|
||||
ymax = gh-1;
|
||||
break;
|
||||
case 2: // vert flip
|
||||
nbricks = game.seedrnd(1,4); // ie. max 8
|
||||
xmin = 0;
|
||||
ymin = 0;
|
||||
xmax = gw-1;
|
||||
if (gh % 2 == 0) {
|
||||
ymax = Math.floor(gh/2)-1;
|
||||
} else {
|
||||
ymax = Math.floor(gh/2);
|
||||
}
|
||||
break;
|
||||
case 3: // horz flip
|
||||
nbricks = game.seedrnd(1,4); // ie. max 8
|
||||
xmin = 0;
|
||||
ymin = 0;
|
||||
if (gw % 2 == 0) {
|
||||
xmax = Math.floor(gw/2)-1;
|
||||
} else {
|
||||
xmax = Math.floor(gw/2);
|
||||
}
|
||||
ymax = gw-1;
|
||||
break;
|
||||
case 4: // quads
|
||||
nbricks = game.seedrnd(1,3); // ie. max 12
|
||||
xmin = 0;
|
||||
ymin = 0;
|
||||
if (gw % 2 == 0) {
|
||||
xmax = Math.floor(gw/2)-1;
|
||||
} else {
|
||||
xmax = Math.floor(gw/2);
|
||||
}
|
||||
if (gh % 2 == 0) {
|
||||
ymax = Math.floor(gh/2)-1;
|
||||
} else {
|
||||
ymax = Math.floor(gh/2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// console.log("bricktype = " + bricktype + " nbricks = " + nbricks);
|
||||
|
||||
// generate coords
|
||||
bricksleft = nbricks;
|
||||
for (n = 0; n < nbricks; n++) {
|
||||
var x,y,coord,found = true;
|
||||
while (found) {
|
||||
found = false;
|
||||
// pick random x/y
|
||||
x = game.seedrnd(0,xmax);
|
||||
y = game.seedrnd(0,ymax);
|
||||
// make sure its not used
|
||||
for (i = 0; i < brickpos.length; i++) {
|
||||
if ((brickpos[i].x == x) && (brickpos[i].y == y)){
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
coord = new Object();
|
||||
coord.x = x;
|
||||
coord.y = y;
|
||||
brickpos.push(coord);
|
||||
//console.log("--- brick at " + x + "," + y);
|
||||
}
|
||||
//console.log("--- gw is " + gw + " gh is " + gh);
|
||||
|
||||
// place bricks
|
||||
totbricks = 0;
|
||||
for (i = 0; i < nbricks; i++) {
|
||||
var newx, newy;
|
||||
|
||||
// add initial one
|
||||
game.addlevelbricks(brickpos[i].x, brickpos[i].y);
|
||||
totbricks++;
|
||||
|
||||
switch (bricktype) {
|
||||
case 1: // normal
|
||||
break;
|
||||
case 2: // vert flip
|
||||
newy = -1;
|
||||
if (gh % 2 == 0) {
|
||||
newy = (ymax+1) + (ymax - brickpos[i].y);
|
||||
} else {
|
||||
if (brickpos[i].y != ymax) { // don't flip on middle line
|
||||
newy = ymax + (ymax - brickpos[i].y);
|
||||
}
|
||||
}
|
||||
if (newy != -1) {
|
||||
console.log(" " + brickpos[i].x + "," + brickpos[i].y + " flipped to " + brickpos[i].x + "," + newy);
|
||||
game.addlevelbricks(brickpos[i].x, newy);
|
||||
totbricks++;
|
||||
}
|
||||
break;
|
||||
case 3: // horz flip
|
||||
newx = -1;
|
||||
if (gw % 2 == 0) {
|
||||
newx = (xmax+1) + (xmax - brickpos[i].x);
|
||||
} else {
|
||||
if (brickpos[i].x != xmax) { // don't flip on middle line
|
||||
newx = xmax + (xmax - brickpos[i].x);
|
||||
}
|
||||
}
|
||||
if (newx != -1) {
|
||||
game.addlevelbricks(newx, brickpos[i].y);
|
||||
totbricks++;
|
||||
}
|
||||
break;
|
||||
case 4: // quads (ie. flip x, y, and both)
|
||||
|
||||
// flip y
|
||||
newy = -1;
|
||||
if (gh % 2 == 0) {
|
||||
newy = (ymax+1) + (ymax - brickpos[i].y);
|
||||
} else {
|
||||
if (brickpos[i].y != ymax) { // don't flip on middle line
|
||||
newy = (ymax) + (ymax - brickpos[i].y);
|
||||
}
|
||||
}
|
||||
if (newy != -1) {
|
||||
game.addlevelbricks(brickpos[i].x, newy);
|
||||
totbricks++;
|
||||
}
|
||||
|
||||
// flip x
|
||||
newx = -1;
|
||||
if (gw % 2 == 0) {
|
||||
newx = ((xmax)+1) + (xmax - brickpos[i].x);
|
||||
} else {
|
||||
if (brickpos[i].x != xmax) { // don't flip on middle line
|
||||
newx = (xmax) + (xmax - brickpos[i].x);
|
||||
}
|
||||
}
|
||||
if (newx != -1) {
|
||||
game.addlevelbricks(newx, brickpos[i].y);
|
||||
totbricks++;
|
||||
}
|
||||
|
||||
// flip x + y
|
||||
if (newx == -1) newx = brickpos[i].x;
|
||||
if (newy == -1) newy = brickpos[i].y;
|
||||
if ((newx != brickpos[i].x) || (newy != brickpos[i].y)) {
|
||||
game.addlevelbricks(newx, newy);
|
||||
totbricks++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// add forced things based on goals
|
||||
for (i = 0; i < ngoals; i++) {
|
||||
switch (game.levels[lev].goals[i].type) {
|
||||
case "brick":
|
||||
game.addlevelforcethings(game.levels[lev].goals[i].type, count);
|
||||
if (totbricks < game.levels[lev].goals[i].count ) {
|
||||
var extras = game.levels[lev].goals[i].count - totbricks;
|
||||
game.addlevelforcethings(game.levels[lev].goals[i].type, extras);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
17
todo
17
todo
|
@ -9,22 +9,10 @@ https://www.smashingmagazine.com/2012/10/design-your-own-mobile-game/
|
|||
--- check here for ios
|
||||
-------------------
|
||||
|
||||
*add starpoint cutoffs for bag, curtain, toad and sunlight goals
|
||||
*save level scores in json format to cope with randomised levels
|
||||
*lev 6 help references both llamas and alpacas
|
||||
*make goalbooster effect actualy work
|
||||
*tweak random goal numbers - too low - add a minimum cutoff
|
||||
*try to make height correct on android tablets
|
||||
*add happy birthday message
|
||||
|
||||
|
||||
sometimes add random bricks
|
||||
randoms:
|
||||
add 1-4 bricks
|
||||
quads:
|
||||
pick quad
|
||||
add 1-2 bricks
|
||||
flip to others
|
||||
vert flip
|
||||
pick side
|
||||
add 1-3 bricks
|
||||
|
@ -33,7 +21,10 @@ sometimes add random bricks
|
|||
pick top/bottom
|
||||
add 1-3 bricks
|
||||
flip
|
||||
|
||||
quads:
|
||||
pick quad
|
||||
add 1-2 bricks
|
||||
flip to others
|
||||
|
||||
|
||||
new door fell down on top of new goat!!
|
||||
|
|
Loading…
Reference in New Issue