Skip to content

Commit

Permalink
Updated ChunkFactory to use the length value of the PType (previously…
Browse files Browse the repository at this point in the history
… PlatformLength) enum in Platform

Renamed PlatformLength as PType (it was very long and is used a lot in
ChunkFactory. Also it is more of a type than a length – the type then
has a length).
Fixed the starting chunks (there were overlapping platforms).
Removed some System.out from the menus.
  • Loading branch information
JonatanKilhamn committed May 3, 2013
1 parent 9ffb560 commit 0643088
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 62 deletions.
97 changes: 42 additions & 55 deletions Kandidat33MobileGame/src/leveldata/ChunkFactory.java
Expand Up @@ -15,7 +15,7 @@
import spatial.MileStone;
import spatial.Plant;
import spatial.Platform;
import spatial.Platform.PlatformLength;
import spatial.Platform.PType;
import spatial.PlayerInteractor;
import spatial.Torch;
import spatial.Wall;
Expand Down Expand Up @@ -93,9 +93,6 @@ public List<Object> generateChunk(int level) {
enemyType = -1;
powerupType = -1;
decorationType = 4;
if (level == 4) {
d += dist; // distance after the "starting strip" is over
}
} else {
/*results 0-7 are actual enemies; a 'roll' of 8 or higher
* will give nothing */
Expand All @@ -116,90 +113,101 @@ public List<Object> generateChunk(int level) {
}


int pType;
PType pType;
float nDist;

switch (platformLayoutType) {
case (-1): // starting platform
d = 0;
while (d < totalLength) {
spatials.add(createPlatform(d, height, 1));
d += getPlatformLength(1);
spatials.add(createPlatform(d, height, PType.LONG));
d += PType.LONG.length;
}
if (level == P.noOfStartingChunks-1) {
d += dist;
}
break;
case (0): // standard platforms
while (d < totalLength) {
spatials.add(createPlatform(d, height + random.nextFloat() * 3, 2));
d += getPlatformLength(2) + dist;
spatials.add(createPlatform(d, height + random.nextFloat() * 3, PType.MEDIUM));
d += PType.MEDIUM.length + dist;
}
break;
case (1): // differentlength platforms
while (d < totalLength) {
pType = random.nextInt(2) + 1;
if (random.nextBoolean()) {
pType = PType.SHORT;
} else {
pType = PType.MEDIUM;
}
nDist = dist * (1f + random.nextFloat());

spatials.add(createPlatform(d, height + random.nextFloat() * 3, pType));
d += getPlatformLength(pType) + nDist;
d += pType.length + nDist;
}
break;
case (2): // climbing platforms
while (d < totalLength) {
pType = random.nextInt(2) + 1;
if (random.nextBoolean()) {
pType = PType.SHORT;
} else {
pType = PType.MEDIUM;
}
nDist = dist * (0.6f + 0.5f * random.nextFloat());
height += 1 + 4 * random.nextFloat();
spatials.add(createPlatform(d, height + random.nextFloat() * 2, pType));
d += getPlatformLength(pType) + nDist;
d += pType.length + nDist;
}
break;
case (3): // descending platforms
float descent;
while (d < totalLength) {
pType = random.nextInt(2) + 1;
if (random.nextBoolean()) {
pType = PType.SHORT;
} else {
pType = PType.MEDIUM;
}
nDist = dist * (1f + random.nextFloat());
descent = 2 + 8 * random.nextFloat();
if (height - descent > P.deathTreshold + 2) {
height -= descent;
}
spatials.add(createPlatform(d, height + random.nextFloat() * 4, pType));
d += getPlatformLength(pType) + nDist;
d += pType.length + nDist;
}
break;
case (4): // invulnerability only reachable with double-jump
height = -1;
spatials.add(createPlatform(d, height, 3));
d += getPlatformLength(3) + dist;
spatials.add(createPlatform(d, height, PType.LONG));
d += PType.LONG.length + dist;
float nHeight = 5 + 3 * random.nextFloat();
spatials.add(createPlatform(d, height + nHeight, 1));
spatials.add(createPlatform(d, height + nHeight - 13, 1));
spatials.add(createPlatform(d, height + nHeight, PType.SHORT));
spatials.add(createPlatform(d, height + nHeight - 13, PType.SHORT));
height += nHeight;
d += getPlatformLength(1) + dist;
d += PType.SHORT.length + dist;
spatials.add(createInvulnerabilityPowerup(d + 5, height - 6));
height += 2 + 5 * random.nextFloat();
spatials.add(createPlatform(d, height, 1));
d += getPlatformLength(1) + 5;
spatials.add(createPlatform(d, height, PType.SHORT));
d += PType.SHORT.length + 5;
height = -1;
if (d < totalLength) {
spatials.add(createPlatform(d, height, 2));
d += getPlatformLength(2) + dist;
spatials.add(createPlatform(d, height, PType.MEDIUM));
d += PType.MEDIUM.length + dist;
}
powerupType = -1;
break;
case (5): // long platform with short platforms above
float d2 = d + getPlatformLength(3)/2; // start higher platforms a bit in
float d2 = d + PType.LONG.length/2; // start higher platforms a bit in
while (d < totalLength) {
spatials.add(createPlatform(d, height, 3));
d += getPlatformLength(3);
spatials.add(createPlatform(d, height, PType.LONG));
d += PType.LONG.length;
}
d += dist;
height += 15;
windowHeight = height;
while (d2 < totalLength) {
spatials.add(createPlatform(d2, height,1));
spatials.add(createPlatform(d2, height,PType.SHORT));
spatials.add(createLinearBat(d2 + 40,height - 6));
d2 += getPlatformLength(1) + 2*dist;
d2 += PType.SHORT.length + 2*dist;
height += 1 + random.nextFloat();
}
height -= 20;
Expand All @@ -210,9 +218,9 @@ public List<Object> generateChunk(int level) {

// fill up with platforms if whatever was in the switch statement didn't already
while (d < totalLength) {
spatials.add(createPlatform(d, height, 1));
spatials.add(createPlatform(d, height, PType.SHORT));
height += random.nextInt(9) - 4;
d += getPlatformLength(1) + dist;
d += PType.SHORT.length + dist;
}
// record this number so that the next chunk doesn't overlap
distanceOverFlow = d - totalLength;
Expand Down Expand Up @@ -362,20 +370,10 @@ public void reset() {

/**
* Creates a platform at a given 2d position.
*
* @param i: must be 1,2 or 3
*/
private Platform createPlatform(float positionX, float positionY, int i) {
private Platform createPlatform(float positionX, float positionY, PType type) {
Vector3f platformPos = new Vector3f(positionX, positionY, 0f);
switch (i) {
case (1):
return new Platform(this.assetManager, platformPos, PlatformLength.SHORT);
case (2):
return new Platform(this.assetManager, platformPos, PlatformLength.MEDIUM);
case (3):
return new Platform(this.assetManager, platformPos, PlatformLength.LONG);
}
return null;
return new Platform(this.assetManager, platformPos, type);
}

/* Creates a windowframe on the wall at a given position */
Expand Down Expand Up @@ -494,15 +492,4 @@ private Spatial createMileStone(int progress, float positionX, float positionY)
return mileStone;
}

private float getPlatformLength(int i) {
switch (i) {
case (1):
return P.shortPlatformLength;
case (2):
return P.mediumPlatformLength;
case (3):
return P.longPlatformLength;
}
return 0;
}
}
Expand Up @@ -22,7 +22,7 @@ public class MainMenuScreenController implements ScreenController {
@Override
public void bind(final Nifty newNifty, final Screen newScreen) {
this.nifty = newNifty;
System.out.println("Startar screenen");
//System.out.println("Startar screenen");
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions Kandidat33MobileGame/src/spatial/Platform.java
Expand Up @@ -20,14 +20,14 @@
*/
public class Platform extends Geometry {

public enum PlatformLength {
public enum PType {
SHORT (P.shortPlatformLength),
MEDIUM (P.mediumPlatformLength),
LONG (P.longPlatformLength);

public final float length;

PlatformLength(float length) {
PType(float length) {
this.length = length;
}
}
Expand All @@ -45,7 +45,7 @@ public enum PlatformLength {
* @param assetManager is used to load the geometry and texture of
* the <code>Platform</code>.
*/
public Platform(AssetManager assetManager, Vector3f position, PlatformLength type) {
public Platform(AssetManager assetManager, Vector3f position, PType type) {
super("platform");
float length = type.length;
Box model =
Expand Down
2 changes: 1 addition & 1 deletion Kandidat33MobileGame/src/spatial/WindowFrame.java
Expand Up @@ -33,7 +33,7 @@ public WindowFrame(AssetManager assetManager, Vector3f position) {

this.attachChild(window);

this.setLocalTranslation(position.x, position.y, -P.platformWidth/2-P.playerZOffset-5.8f);
this.setLocalTranslation(position.x, position.y, -P.platformWidth/2-P.playerZOffset-5.7f);
this.setShadowMode(ShadowMode.Off);

}
Expand Down
2 changes: 0 additions & 2 deletions Kandidat33MobileGame/src/state/InMainMenuState.java
Expand Up @@ -61,12 +61,10 @@ public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (enabled) {
//Initiate the things that are needed when the state is active
System.out.println("InMainMenuState is now active");
nifty.setIgnoreMouseEvents(false);
nifty.gotoScreen("gameOverScreen");
} else {
//Remove the things not needed when the state is inactive
System.out.println("InMainMenuState is now inactive");
nifty.setIgnoreMouseEvents(true); // needed to prevent nullpointer from releasing the click too quickly when closing nifty
nifty.exit();
}
Expand Down

0 comments on commit 0643088

Please sign in to comment.