Config option for "difficulty" :D

This commit is contained in:
oitsjustjose 2017-12-10 17:59:26 -05:00
commit f9ddea550d
2 changed files with 37 additions and 16 deletions

View file

@ -74,12 +74,31 @@ public class Dungeon extends SceneLevel
this.player = player;
this.entityManager.addEntity(this.player);
this.level = level;
this.maxLevels = 24;
this.maxLevels = parseLevelCount();
initFont();
initScene();
}
public int parseLevelCount()
{
String str = Game.getInstance().config.difficulty;
if (str.equalsIgnoreCase("easy"))
{
return 8;
}
if (str.equalsIgnoreCase("normal"))
{
return 16;
}
if (str.equalsIgnoreCase("hard"))
{
return 48;
}
return 16;
}
public void initFont()
{
try
@ -112,12 +131,13 @@ public class Dungeon extends SceneLevel
{
tileManager.addTile(new TileDecoration("wall_decor_", 4).changeColor(c));
}
if (this.level % 3 == 0)
if (this.level != (maxLevels / 8) && this.level % (maxLevels / 8) == 0)
{
if (getItemAtStage(level / 3) != null)
if (getItemAtStage(level / (maxLevels / 8)) != null)
{
AudioManager.getInstance().play("level_up");
entityManager.addEntity(new EntityItem(getItemAtStage(level / 3), Display.getWidth() / 2, Display.getHeight() - 32, -1));
entityManager.addEntity(new EntityItem(getItemAtStage(level / (maxLevels / 8)), Display.getWidth() / 2, Display.getHeight() - 32, -1));
}
}

View file

@ -19,6 +19,7 @@ public class Config
public int resolutionWidth;
public int resolutionHeight;
public int targetFPS;
public String difficulty;
public float volume;
public Config()
@ -38,8 +39,9 @@ public class Config
String[] resolutions = props.getProperty("windowed_resolution", "800x600").split("x");
this.resolutionWidth = Integer.parseInt(resolutions[0]);
this.resolutionHeight = Integer.parseInt(resolutions[1]);
this.targetFPS = Integer.parseInt(props.getProperty("target_FPS", "100"));
this.volume = Integer.parseInt(props.getProperty("volume", "100")) / 100F; // divide by one hundred because users understand 0 -> 100 better than 0.0 -> 1.0
this.targetFPS = Integer.parseInt(props.getProperty("target_FPS", "60"));
this.difficulty = props.getProperty("difficulty", "normal");
this.volume = Integer.parseInt(props.getProperty("volume", "50")) / 100F; // divide by one hundred because users understand 0 -> 100 better than 0.0 -> 1.0
reader.close();
}
@ -51,15 +53,12 @@ public class Config
}
catch (IOException e)
{
System.out.println("Everything went wrong with the config. Do you have read/write perms for this folder?");
e.printStackTrace();
}
}
// TODO: Properly handle these exceptions..
catch (IOException ioEx)
{
}
catch (NullPointerException npe)
catch (IOException | NullPointerException e)
{
e.printStackTrace();
}
}
@ -69,14 +68,16 @@ public class Config
Properties props = new Properties();
props.setProperty("windowed_resolution", "800x600");
props.setProperty("target_FPS", "100");
props.setProperty("volume", "100");
props.setProperty("target_FPS", "60");
props.setProperty("difficulty", "normal");
props.setProperty("volume", "50");
String[] resolutions = props.getProperty("windowed_resolution", "800x600").split("x");
this.resolutionWidth = Integer.parseInt(resolutions[0]);
this.resolutionHeight = Integer.parseInt(resolutions[1]);
this.targetFPS = Integer.parseInt(props.getProperty("target_FPS", "100"));
this.volume = Integer.parseInt(props.getProperty("volume", "100")) / 100F; // divide by one hundred because users understand 0->100 better than 0.0 to 1.0
this.targetFPS = Integer.parseInt(props.getProperty("target_FPS", "60"));
this.difficulty = props.getProperty("difficulty", "normal");
this.volume = Integer.parseInt(props.getProperty("volume", "50")) / 100F; // divide by one hundred because users understand 0->100 better than 0.0 to 1.0
FileWriter writer = new FileWriter(configFile);
props.store(writer, "game settings");