Refactoring to allow MyNewLevelGenerator to determine the level type, difficulty and music based on the player metrics.

Work in progress.
This commit is contained in:
Woody Folsom
2012-03-17 10:26:33 -04:00
parent 47520126ff
commit a827ca7430
9 changed files with 141 additions and 63 deletions

View File

@@ -51,8 +51,8 @@ public class LevelScene extends Scene implements SpriteContext {
protected long levelSeed;
protected MarioComponent marioComponent;
protected int levelType;
protected int levelDifficulty;
//protected int levelType;
//protected int levelDifficulty;
public static DataRecorder recorder;
@@ -66,12 +66,12 @@ public class LevelScene extends Scene implements SpriteContext {
private int xArrow, yArrow;
public LevelScene(GraphicsConfiguration graphicsConfiguration,
MarioComponent renderer, long seed, int levelDifficulty, int type) {
MarioComponent renderer, long seed/*, int levelDifficulty, int type*/) {
this.graphicsConfiguration = graphicsConfiguration;
this.levelSeed = seed;
this.marioComponent = renderer;
this.levelDifficulty = levelDifficulty;
this.levelType = type;
//this.levelDifficulty = levelDifficulty;
//this.levelType = type;
widthArrow = 25;
tipWidthArrow = 10;
@@ -282,7 +282,7 @@ public class LevelScene extends Scene implements SpriteContext {
private DecimalFormat df = new DecimalFormat("00");
private DecimalFormat df2 = new DecimalFormat("000");
public void render(Graphics g, float alpha) {
int xCam = (int) (mario.xOld + (mario.x - mario.xOld) * alpha) - 160;
int yCam = (int) (mario.yOld + (mario.y - mario.yOld) * alpha) - 120;

View File

@@ -31,7 +31,7 @@ public class LevelSceneCustom extends LevelScene {
public LevelSceneCustom(GraphicsConfiguration graphicsConfiguration,
MarioComponent renderer, long seed, int levelDifficulty, int type,
boolean isCustom, LevelGenerator levelGenerator) {
super(graphicsConfiguration, renderer, seed, levelDifficulty, type);
super(graphicsConfiguration, renderer, seed/*, levelDifficulty, type*/);
this.isCustom = isCustom;
this.clg = levelGenerator;
}
@@ -46,21 +46,26 @@ public class LevelSceneCustom extends LevelScene {
}
GamePlay gp = GamePlay.read("player.txt");
currentLevel = (Level) clg.generateLevel(gp);
String detailedInfo = FileHandler.readFile("DetailedInfo.txt");
File xmlInfoFile = new File("DetailedInfo.xml");
DataRecorder dataRecorder;
if (xmlInfoFile.exists()) {
try {
DataRecorder dataRecorder = DataRecorder.fromXML(xmlInfoFile);
System.out.println("DetailedInfo (from xml file): " + detailedInfo);
dataRecorder = DataRecorder.fromXML(xmlInfoFile);
} catch (IOException ioe) {
ioe.printStackTrace();
System.out.println("Reading from DataRecorder failed due to: ");
ioe.printStackTrace(System.out);
System.out.println("Initializing blank record");
dataRecorder = DataRecorder.BLANK_RECORD;
}
} else {
System.out.println("DetailedInfo (from txt file): " + detailedInfo);
dataRecorder = DataRecorder.BLANK_RECORD;;
String detailedInfo = FileHandler.readFile("DetailedInfo.txt");
System.out.println("Read detailedInfo from DetailedInfo.txt (not parsed): ");
System.out.println(detailedInfo);
}
int levelType = clg.generateLevelType(gp,dataRecorder);
currentLevel = (Level) clg.generateLevel(gp,dataRecorder);
try {
level = currentLevel.clone();
@@ -68,9 +73,7 @@ public class LevelSceneCustom extends LevelScene {
e.printStackTrace();
}
// TODO change this
// level is always overground
Art.startMusic(2);
Art.startMusic(levelType);
paused = false;
Sprite.spriteContext = this;