Merge branch 'master' of woodyfolsom.net:/opt/git/cs8803p3

This commit is contained in:
Woody Folsom
2012-03-17 22:23:45 -04:00

View File

@@ -121,15 +121,26 @@ public class PCGLevel extends Level {
int length = 0; int length = 0;
if (TESTING) { if (TESTING) {
difficulty = 6;
length = buildStraight(0, width - 64, true); length = buildStraight(0, width - 64, true);
length += buildFreebie(length, width - 64 - length);
length += buildBowlingAlley(length, width - 64 - length, length += buildBowlingAlley(length, width - 64 - length,
SpriteTemplate.ARMORED_TURTLE); SpriteTemplate.ARMORED_TURTLE);
length += buildLemmingTrap(length, width - 64 - length, length += buildFreebie(length, width - 64 - length);
random.nextInt(3) + 1);
length += buildLemmingTrap(length, width - 64 - length);
length += buildFreebie(length, width - 64 - length);
length += buildPlatformJump(length, width - 64 - length); length += buildPlatformJump(length, width - 64 - length);
length += buildFreebie(length, width - 64 - length);
length += buildMaze(length, width - 64 - length); length += buildMaze(length, width - 64 - length);
length += buildFreebie(length, width - 64 - length);
length += buildPipeJump(length, width - 64 - length); length += buildPipeJump(length, width - 64 - length);
length += buildFreebie(length, width - 64 - length);
// create all of the medium sections // create all of the medium sections
while (length < width - 64) { while (length < width - 64) {
@@ -186,10 +197,44 @@ public class PCGLevel extends Level {
fillEndPiece(length, floor); fillEndPiece(length, floor);
} }
private int buildFreebie(int xo, int maxLength) {
if (maxLength >= 5) {
int floor = height - 1 - random.nextInt(4);
for (int x = 0; x < 5; x++) {
for (int y = 0; y < height; y++) {
if (y >= floor) {
setBlock(xo + x, y, GROUND);
}
}
}
if (random.nextBoolean()) {
setBlock(xo, floor - 1, Level.BLOCK_EMPTY);
setBlock(xo + 4, floor - 1, Level.BLOCK_POWERUP);
setSpriteTemplate(xo + 3, floor - 1, new SpriteTemplate(
SpriteTemplate.GREEN_TURTLE, false));
}
else {
setBlock(xo + 2, floor - 3, Level.BLOCK_POWERUP);
}
return 5;
}
return 0;
}
private int buildBowlingAlley(int xo, int maxLength, int enemyType) { private int buildBowlingAlley(int xo, int maxLength, int enemyType) {
if (maxLength >= 26 if (maxLength >= 26
&& (enemyType == SpriteTemplate.ARMORED_TURTLE || enemyType == SpriteTemplate.GREEN_TURTLE)) { && (enemyType == SpriteTemplate.ARMORED_TURTLE || enemyType == SpriteTemplate.GREEN_TURTLE)) {
int numEnemies = 0;
for (int i = 0; i < 10; i++) {
numEnemies += shouldAddChallenge() ? 1 : 0;
}
// Create the pit. // Create the pit.
setBlock(xo, this.height - 2, Level.GROUND); setBlock(xo, this.height - 2, Level.GROUND);
setBlock(xo, this.height - 1, Level.GROUND); setBlock(xo, this.height - 1, Level.GROUND);
@@ -209,22 +254,26 @@ public class PCGLevel extends Level {
setBlock(xo + x, this.height - 2, Level.GROUND); setBlock(xo + x, this.height - 2, Level.GROUND);
setBlock(xo + x, this.height - 3, Level.GROUND); setBlock(xo + x, this.height - 3, Level.GROUND);
if (x > 16) { if (x >= 26 - numEnemies) {
setSpriteTemplate(xo + x, this.height - 4, setSpriteTemplate(xo + x, this.height - 4,
new SpriteTemplate(enemyType, false)); new SpriteTemplate(enemyType, false));
} }
} }
return 25; return 26;
} }
return 0; return 0;
} }
private int buildLemmingTrap(int xo, int maxLength, int enemyType) { private int buildLemmingTrap(int xo, int maxLength) {
if (maxLength >= 14 if (maxLength >= 14) {
&& (enemyType == SpriteTemplate.GOOMPA int enemyType = shouldAddChallenge() ? (shouldAddChallenge() ? SpriteTemplate.ARMORED_TURTLE
|| enemyType == SpriteTemplate.GREEN_TURTLE || enemyType == SpriteTemplate.ARMORED_TURTLE)) { : SpriteTemplate.GREEN_TURTLE)
: SpriteTemplate.GOOMPA;
boolean flying = shouldAddChallenge() && shouldAddChallenge()
&& shouldAddChallenge();
for (int x = 0; x < 18; x++) { for (int x = 0; x < 18; x++) {
if (x > 5) { if (x > 5) {
for (int y = 0; y < 5; y++) { for (int y = 0; y < 5; y++) {
@@ -237,7 +286,7 @@ public class PCGLevel extends Level {
if (x > 6 && x % 2 == 0) { if (x > 6 && x % 2 == 0) {
setSpriteTemplate(xo + x, this.height - 6, setSpriteTemplate(xo + x, this.height - 6,
new SpriteTemplate(enemyType, false)); new SpriteTemplate(enemyType, flying));
} }
} }
return 18; return 18;
@@ -388,7 +437,15 @@ public class PCGLevel extends Level {
} }
} }
// This is basically just a randomizer function to call whenever I need to
// randomly add difficulty based on the user's skill level.
private boolean shouldAddChallenge() {
return random.nextInt(11) + 1 <= difficulty;
}
private int buildMaze(int xo, int maxLength) { private int buildMaze(int xo, int maxLength) {
if (maxLength >= 19) {
int length = random.nextInt(maxLength - 19) + 20; int length = random.nextInt(maxLength - 19) + 20;
int soFar = 6; int soFar = 6;
int next; int next;
@@ -443,31 +500,13 @@ public class PCGLevel extends Level {
// Stretch nxt; // Stretch nxt;
boolean stretchEnd; boolean stretchEnd;
boolean midLine; boolean midLine;
boolean addEnemy;
int heightMod;
int enemyType;
for (int i = 0; i < maze.size(); i++) { for (int i = 0; i < maze.size(); i++) {
str = maze.get(i); str = maze.get(i);
// if (i < maze.size() - 1) {
// nxt = maze.get(i + 1);
// } else {
// nxt = null;
// }
// if (nxt != null) {
// skipUp = ((nxt.lvl != MazeLevel.TOP) && (str.lvl ==
// MazeLevel.TOP))
// || ((nxt.lvl == MazeLevel.TOP) && (str.lvl != MazeLevel.TOP));
//
// skipDown = ((nxt.lvl != MazeLevel.BOT) && (str.lvl ==
// MazeLevel.BOT))
// || ((str.lvl != MazeLevel.BOT) && (nxt.lvl == MazeLevel.BOT));
// }
//
// else {
// skipUp = false;
// skipDown = false;
// }
for (int x = 0; x < str.len; x++) { for (int x = 0; x < str.len; x++) {
setBlock(xo + soFar + x, this.height - 1, Level.GROUND); setBlock(xo + soFar + x, this.height - 1, Level.GROUND);
@@ -477,48 +516,69 @@ public class PCGLevel extends Level {
// skipDown = (skipDown && (x == str.len - 2)) // skipDown = (skipDown && (x == str.len - 2))
// || (str.len >= 5 && x == (str.len / 2)); // || (str.len >= 5 && x == (str.len / 2));
midLine = (str.len >= 5 && x == (str.len / 2) - 1); midLine = (str.len >= 5 && x == (str.len / 2) - 1);
addEnemy = (str.len >= 5 && x == (str.len / 2));
stretchEnd = (x == str.len - 1); stretchEnd = (x == str.len - 1);
if // ((stretchEnd && nxt != null && nxt.lvl != MazeLevel.BOT) if // ((stretchEnd && nxt != null && nxt.lvl !=
// MazeLevel.BOT)
// || // ||
(midLine && str.lvl != LevelComponent.MazeLevel.BOT) // ) (midLine && str.lvl != LevelComponent.MazeLevel.BOT) // )
{ {
setBlock(xo + soFar + x, this.height - 2, Level.BLOCK_EMPTY); setBlock(xo + soFar + x, this.height - 2, Level.ROCK);
setBlock(xo + soFar + x, this.height - 3, Level.BLOCK_EMPTY); setBlock(xo + soFar + x, this.height - 3, Level.ROCK);
} }
if // ((stretchEnd && nxt != null && nxt.lvl != MazeLevel.MID) if // ((stretchEnd && nxt != null && nxt.lvl !=
// MazeLevel.MID)
// || // ||
(midLine && str.lvl != LevelComponent.MazeLevel.MID)// ) (midLine && str.lvl != LevelComponent.MazeLevel.MID)// )
{ {
setBlock(xo + soFar + x, this.height - 5, Level.BLOCK_EMPTY); setBlock(xo + soFar + x, this.height - 5, Level.ROCK);
setBlock(xo + soFar + x, this.height - 6, Level.BLOCK_EMPTY); setBlock(xo + soFar + x, this.height - 6, Level.ROCK);
} }
if // ((stretchEnd && nxt != null && nxt.lvl != MazeLevel.TOP) if // ((stretchEnd && nxt != null && nxt.lvl !=
// MazeLevel.TOP)
// || // ||
(midLine && str.lvl != LevelComponent.MazeLevel.TOP)// ) (midLine && str.lvl != LevelComponent.MazeLevel.TOP)// )
{ {
setBlock(xo + soFar + x, this.height - 8, Level.BLOCK_EMPTY); setBlock(xo + soFar + x, this.height - 8, Level.ROCK);
setBlock(xo + soFar + x, this.height - 9, Level.BLOCK_EMPTY); setBlock(xo + soFar + x, this.height - 9, Level.ROCK);
setBlock(xo + soFar + x, this.height - 10, setBlock(xo + soFar + x, this.height - 10, Level.ROCK);
Level.BLOCK_EMPTY); setBlock(xo + soFar + x, this.height - 11, Level.ROCK);
setBlock(xo + soFar + x, this.height - 11, setBlock(xo + soFar + x, this.height - 12, Level.ROCK);
Level.BLOCK_EMPTY); setBlock(xo + soFar + x, this.height - 13, Level.ROCK);
setBlock(xo + soFar + x, this.height - 12, setBlock(xo + soFar + x, this.height - 14, Level.ROCK);
Level.BLOCK_EMPTY); setBlock(xo + soFar + x, this.height - 15, Level.ROCK);
setBlock(xo + soFar + x, this.height - 13,
Level.BLOCK_EMPTY);
setBlock(xo + soFar + x, this.height - 14,
Level.BLOCK_EMPTY);
setBlock(xo + soFar + x, this.height - 15,
Level.BLOCK_EMPTY);
} }
if (!stretchEnd) { if (!stretchEnd) {
setBlock(xo + soFar + x, this.height - 7, Level.BLOCK_EMPTY); setBlock(xo + soFar + x, this.height - 7, Level.ROCK);
} }
if (!stretchEnd) { if (!stretchEnd) {
setBlock(xo + soFar + x, this.height - 4, Level.BLOCK_EMPTY); setBlock(xo + soFar + x, this.height - 4, Level.ROCK);
}
if (addEnemy && shouldAddChallenge()) {
enemyType = shouldAddChallenge() ? (shouldAddChallenge() ? (shouldAddChallenge() ? SpriteTemplate.ARMORED_TURTLE
: SpriteTemplate.RED_TURTLE)
: SpriteTemplate.GREEN_TURTLE)
: SpriteTemplate.GOOMPA;
switch (str.lvl) {
case TOP:
heightMod = 8;
break;
case MID:
heightMod = 5;
break;
default:
heightMod = 2;
}
setSpriteTemplate(xo + soFar + x, this.height
- heightMod, new SpriteTemplate(enemyType,
shouldAddChallenge()));
} }
} }
@@ -531,6 +591,8 @@ public class PCGLevel extends Level {
return length; return length;
} }
return 0;
}
private int buildPipeJump(int xo, int maxLength) { private int buildPipeJump(int xo, int maxLength) {
int numPipes = 4; int numPipes = 4;
@@ -599,7 +661,12 @@ public class PCGLevel extends Level {
private int buildPlatformJump(int xo, int maxLength) { private int buildPlatformJump(int xo, int maxLength) {
int length = 0; int length = 0;
int numPlatforms = random.nextInt((maxLength - 3) / 8); int gapLength;
for (gapLength = 1; shouldAddChallenge() && gapLength < 4; gapLength++) {
}
int numPlatforms = random.nextInt((maxLength - 3) / (4 + gapLength));
if (numPlatforms > 1) { if (numPlatforms > 1) {
boolean found = false; boolean found = false;
@@ -607,10 +674,11 @@ public class PCGLevel extends Level {
LevelComponent.PlatformLevel last; LevelComponent.PlatformLevel last;
LevelComponent.PlatformLevel next; LevelComponent.PlatformLevel next;
ArrayList<LevelComponent.PlatformLevel> jumps = new ArrayList<LevelComponent.PlatformLevel>(); ArrayList<LevelComponent.PlatformLevel> jumps = new ArrayList<LevelComponent.PlatformLevel>();
int heightMod; int heightMod = 0;
int lastHeightMod = 0;
int enemyType;
jumps.add(random.nextBoolean() ? LevelComponent.PlatformLevel.BOT jumps.add(LevelComponent.PlatformLevel.BOT);
: LevelComponent.PlatformLevel.MID_D);
for (int i = 1; i < numPlatforms; i++) { for (int i = 1; i < numPlatforms; i++) {
last = jumps.get(i - 1); last = jumps.get(i - 1);
@@ -667,6 +735,10 @@ public class PCGLevel extends Level {
length = 3; length = 3;
for (int x = 0; x < jumps.size(); x++) { for (int x = 0; x < jumps.size(); x++) {
if (x > 0) {
lastHeightMod = heightMod;
}
switch (jumps.get(x)) { switch (jumps.get(x)) {
case TOP: case TOP:
heightMod = 12; heightMod = 12;
@@ -681,19 +753,35 @@ public class PCGLevel extends Level {
heightMod = 3; heightMod = 3;
} }
heightMod += (random.nextBoolean() ? random.nextInt(2) : -1 heightMod += (x > 0 && random.nextBoolean() ? random.nextInt(2)
* random.nextInt(2)); : -1 * random.nextInt(2));
setBlock(xo + length, this.height - heightMod, while (x > 0 && heightMod - lastHeightMod >= 5) {
Level.BLOCK_EMPTY); heightMod--;
setBlock(xo + length + 1, this.height - heightMod, }
Level.BLOCK_EMPTY);
setBlock(xo + length + 2, this.height - heightMod,
Level.BLOCK_EMPTY);
setBlock(xo + length + 3, this.height - heightMod,
Level.BLOCK_EMPTY);
length += 8; setBlock(xo + length, this.height - heightMod, Level.ROCK);
setBlock(xo + length + 1, this.height - heightMod, Level.ROCK);
setBlock(xo + length + 2, this.height - heightMod, Level.ROCK);
setBlock(xo + length + 3, this.height - heightMod, Level.ROCK);
if (shouldAddChallenge()) {
enemyType = shouldAddChallenge() ? (shouldAddChallenge() ? (shouldAddChallenge() ? SpriteTemplate.ARMORED_TURTLE
: SpriteTemplate.RED_TURTLE)
: SpriteTemplate.GREEN_TURTLE)
: SpriteTemplate.GOOMPA;
setSpriteTemplate(
xo + length + 3,
this.height - heightMod - 1,
new SpriteTemplate(
enemyType,
(enemyType == SpriteTemplate.RED_TURTLE && shouldAddChallenge())
|| enemyType != SpriteTemplate.RED_TURTLE));
}
length += 4 + gapLength;
} }
} }