|
@@ -28,20 +28,23 @@ public final class Level
|
|
|
|
|
|
private final String name;
|
|
|
|
|
|
- private final HashMap<Integer, Entity> entities;
|
|
|
+ private final HashMap<Integer, Entity> entities = new HashMap<>();;
|
|
|
private final LinkedList<Entity> spawnQueue = new LinkedList<>();
|
|
|
private Entity hero;
|
|
|
- private int entityCounter;
|
|
|
+ private int entityCounter = 0;
|
|
|
|
|
|
- private boolean shouldReset;
|
|
|
- private boolean done;
|
|
|
+ private boolean shouldReset = false;
|
|
|
+ private boolean done = true; // this will be reseted in resetLevel()
|
|
|
|
|
|
private int souls;
|
|
|
private int maxSouls;
|
|
|
|
|
|
- private double time;
|
|
|
+ private double time = 0.0;
|
|
|
+ private double clockTick = 0.0;
|
|
|
|
|
|
- private TreeSet<Point> spawns;
|
|
|
+ private int tries = 7;
|
|
|
+
|
|
|
+ private TreeSet<Point> spawns = new TreeSet<>();
|
|
|
|
|
|
public Level(StateRenderer state, File f)
|
|
|
{
|
|
@@ -49,13 +52,6 @@ public final class Level
|
|
|
this.renderer = state.getRenderer();
|
|
|
this.data = new LevelData(f);
|
|
|
this.worldLoaded = data.load();
|
|
|
- this.entities = new HashMap<>();
|
|
|
- this.entityCounter = 0;
|
|
|
- this.shouldReset = false;
|
|
|
- this.done = false;
|
|
|
- this.time = 0.0;
|
|
|
-
|
|
|
- this.spawns = new TreeSet<>();
|
|
|
|
|
|
if(worldLoaded)
|
|
|
{
|
|
@@ -136,6 +132,7 @@ public final class Level
|
|
|
{
|
|
|
spawns.add(new Point(5, 5));
|
|
|
}
|
|
|
+ spawns.add(new Point(15, 10));
|
|
|
|
|
|
resetLevel();
|
|
|
|
|
@@ -173,18 +170,29 @@ public final class Level
|
|
|
shouldReset = true;
|
|
|
}
|
|
|
|
|
|
- public void resetLevel()
|
|
|
+ public boolean resetLevel()
|
|
|
{
|
|
|
+ boolean dead = false;
|
|
|
+ if(!done) // hero just died
|
|
|
+ {
|
|
|
+ tries--;
|
|
|
+ if(tries <= 0)
|
|
|
+ {
|
|
|
+ tries = 7;
|
|
|
+ dead = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
state.resetTiles();
|
|
|
data.activateEntities();
|
|
|
souls = 0;
|
|
|
time = 0.0;
|
|
|
shouldReset = false;
|
|
|
done = false;
|
|
|
- Entity h = spawnHero();
|
|
|
+ Entity h = spawnHero(dead);
|
|
|
hero = h;
|
|
|
entities.clear();
|
|
|
entities.put(entityCounter++, h);
|
|
|
+ return dead;
|
|
|
}
|
|
|
|
|
|
public void spawnEntity(Entity ent)
|
|
@@ -192,11 +200,11 @@ public final class Level
|
|
|
spawnQueue.add(ent);
|
|
|
}
|
|
|
|
|
|
- public Entity spawnHero()
|
|
|
+ public Entity spawnHero(boolean first)
|
|
|
{
|
|
|
Entity h = hero;
|
|
|
Point p;
|
|
|
- if(h == null || hero.getX() < 0)
|
|
|
+ if(h == null || hero.getX() < 0 || first)
|
|
|
{
|
|
|
// first spawn or out of map, use first spawn
|
|
|
p = spawns.first();
|
|
@@ -353,6 +361,34 @@ public final class Level
|
|
|
Utils.getImage("gui/health_bar/health_bar_7", true)
|
|
|
};
|
|
|
|
|
|
+ private final static Image[] LIFE_OVERLAY = new Image[]
|
|
|
+ {
|
|
|
+ Utils.getImage("gui/health_num/health_num_0", true),
|
|
|
+ Utils.getImage("gui/health_num/health_num_1", true),
|
|
|
+ Utils.getImage("gui/health_num/health_num_2", true),
|
|
|
+ Utils.getImage("gui/health_num/health_num_3", true),
|
|
|
+ Utils.getImage("gui/health_num/health_num_4", true),
|
|
|
+ Utils.getImage("gui/health_num/health_num_5", true),
|
|
|
+ Utils.getImage("gui/health_num/health_num_6", true),
|
|
|
+ Utils.getImage("gui/health_num/health_num_7", true)
|
|
|
+ };
|
|
|
+
|
|
|
+ private final static Image[] TIME_CLOCK = new Image[]
|
|
|
+ {
|
|
|
+ Utils.getImage("gui/time_icon/time_f1", true),
|
|
|
+ Utils.getImage("gui/time_icon/time_f2", true),
|
|
|
+ Utils.getImage("gui/time_icon/time_f3", true),
|
|
|
+ Utils.getImage("gui/time_icon/time_f4", true),
|
|
|
+ Utils.getImage("gui/time_icon/time_f5", true),
|
|
|
+ Utils.getImage("gui/time_icon/time_f6", true),
|
|
|
+ Utils.getImage("gui/time_icon/time_f7", true),
|
|
|
+ Utils.getImage("gui/time_icon/time_f8", true),
|
|
|
+ Utils.getImage("gui/time_icon/time_f9", true),
|
|
|
+ Utils.getImage("gui/time_icon/time_f10", true),
|
|
|
+ Utils.getImage("gui/time_icon/time_f11", true),
|
|
|
+ Utils.getImage("gui/time_icon/time_f12", true)
|
|
|
+ };
|
|
|
+
|
|
|
public void render()
|
|
|
{
|
|
|
if(worldLoaded)
|
|
@@ -412,7 +448,7 @@ public final class Level
|
|
|
// gui background
|
|
|
renderer.drawFixedImage(AROUND_BACKGROUND, x, y, w, h);
|
|
|
|
|
|
- // health mirror
|
|
|
+ // health mirror
|
|
|
int hFrame = (int) (hero.getHealth().getHealthPercent() * (HEALTH_BAR.length - 1));
|
|
|
renderer.drawFixedImage(HEALTH_BAR[hFrame], x + 78 * scale, y + 8 * scale,
|
|
|
HEALTH_BAR[hFrame].getWidth() * scale, HEALTH_BAR[hFrame].getHeight() * scale);
|
|
@@ -429,7 +465,12 @@ public final class Level
|
|
|
wEnergy * scale, ENERGY_FULL.getHeight() * scale);
|
|
|
|
|
|
// gui foreground
|
|
|
- renderer.drawFixedImage(AROUND_FOREGROUND, x, y, w, h);
|
|
|
+ renderer.drawFixedImage(AROUND_FOREGROUND, x, y, w, h);
|
|
|
+
|
|
|
+ // tries go over foreground
|
|
|
+ renderer.drawFixedImage(LIFE_OVERLAY[tries], x + 89 * scale, y + 52 * scale,
|
|
|
+ LIFE_OVERLAY[tries].getWidth() * scale, LIFE_OVERLAY[tries].getHeight() * scale);
|
|
|
+
|
|
|
|
|
|
// grey background
|
|
|
double boxHeight = renderer.getTextHeight(2) + 10;
|
|
@@ -442,12 +483,26 @@ public final class Level
|
|
|
}
|
|
|
renderer.restore();
|
|
|
|
|
|
+ // soul / time rendering
|
|
|
+ x = 5;
|
|
|
+ y = 5;
|
|
|
+ w = renderer.getTextWidth(1);
|
|
|
+ h = renderer.getTextHeight(1);
|
|
|
+
|
|
|
// soul rendering
|
|
|
- renderer.drawFixedImagePart(BottledSoulTile.IMAGE[0], 14, 8, 34, 52, 5, 5, renderer.getTextWidth(1), renderer.getTextHeight(1));
|
|
|
- renderer.drawText(5 + renderer.getTextWidth(1), 5, formatBottles(souls));
|
|
|
+ renderer.drawFixedImagePart(BottledSoulTile.IMAGE[0], 14, 8, 34, 52, x, y, w, h);
|
|
|
+ renderer.drawText(x + renderer.getTextWidth(1), y, formatBottles(souls));
|
|
|
|
|
|
+ y += renderer.getTextHeight(1);
|
|
|
+
|
|
|
// time rendering
|
|
|
- renderer.drawText(5 + renderer.getTextWidth(1), 5 + renderer.getTextHeight(1), formatTime(time));
|
|
|
+ clockTick += 0.05;
|
|
|
+ if(clockTick >= TIME_CLOCK.length)
|
|
|
+ {
|
|
|
+ clockTick = 0.0;
|
|
|
+ }
|
|
|
+ renderer.drawFixedImagePart(TIME_CLOCK[(int) clockTick], 0, 0, 32, 32, x, y, w, h);
|
|
|
+ renderer.drawText(x + renderer.getTextWidth(1), y, formatTime(time));
|
|
|
}
|
|
|
renderer.stopTextDrawing();
|
|
|
}
|