i am making a game with the same concept as the game doodle jump except with a monkey and platforms. i am trying to create the best algorithm to create random platforms, however i keep running into "impossible" situations such as one platform directly on top of another making it impossible to move forth in the game. i am looking for ideas that will help me finesse my algorithm i currently have, which is:
int prevcount =0;
int platformcounter=0;
int numberofplatforms = 5;
int theplatformputter;
boolean must =false;
if(numberofplatforms<=numPlats) {
for (int first = 97; first >= 1; first--)
{
grid[98][1] = new monkeySquare(1,98,monkeySquare.PLAT);
platformcounter =0;
if (must) {
theplatformputter = (int) (Math.random() * (4 - prevcount)) + 1;
must = false;
} else {
theplatformputter = (int) (Math.random() * (5 - prevcount));
}
for (int xx = 1; xx <= theplatformputter; xx++) {
int column = (int) (Math.random() * 5);
while (grid[first + 1][column] != null && grid[first+2][column]!=null) {
column = (int) (Math.random() * 5);
break;
}
grid[first][column] = new monkeySquare(column, first, monkeySquare.PLAT);
platformcounter++;
numberofplatforms++;
}
prevcount = platformcounter;
System.out.println("prevcount is" + prevcount);
System.out.println("platcount is"+platformcounter);
if(prevcount==0 && platformcounter==0)
{
System.out.println("must is true :p");
must=true;
}
}
i appreciate anyone's help. i am in high school and have been working on this game for 2 months and this is one of the few problems i have left. thank you!
Aucun commentaire:
Enregistrer un commentaire