diff --git a/bin/me/ElectronicsBoy/GameEngine/gui/HUD.class b/bin/me/ElectronicsBoy/GameEngine/gui/HUD.class index 7539a95..2231d11 100644 Binary files a/bin/me/ElectronicsBoy/GameEngine/gui/HUD.class and b/bin/me/ElectronicsBoy/GameEngine/gui/HUD.class differ diff --git a/bin/me/ElectronicsBoy/wavegame/Game.class b/bin/me/ElectronicsBoy/wavegame/Game.class index 024e95d..8e1e937 100644 Binary files a/bin/me/ElectronicsBoy/wavegame/Game.class and b/bin/me/ElectronicsBoy/wavegame/Game.class differ diff --git a/crashReports/CrashReport_10-0-2023 17-34-28.txt b/crashReports/CrashReport_10-0-2023 17-34-28.txt new file mode 100644 index 0000000..aaf91c9 --- /dev/null +++ b/crashReports/CrashReport_10-0-2023 17-34-28.txt @@ -0,0 +1,34 @@ +Game Crash Report +----------------- + +All known info is shown below +----------------------------- +StackTrace: +java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 + at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) + at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) + at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266) + at java.base/java.util.Objects.checkIndex(Objects.java:359) + at java.base/java.util.ArrayList.get(ArrayList.java:427) + at me.ElectronicsBoy.GameEngine.gui.HUD.render(HUD.java:57) + at me.ElectronicsBoy.wavegame.Game.renderUI(Game.java:129) + at me.ElectronicsBoy.GameEngine.gui.GUIWindow.render(GUIWindow.java:31) + at me.ElectronicsBoy.GameEngine.Engine.render(Engine.java:139) + at me.ElectronicsBoy.GameEngine.Engine.run(Engine.java:81) + at java.base/java.lang.Thread.run(Thread.java:833) + +Caused by: +null + +Message: +Index 0 out of bounds for length 0 +Current Thread: +Engine Thread + +System Details: +OS : Linux +OS Version : 5.15.0-56-generic +OS Architecture : amd64 +Current Dir : /home/electronicsboy/ElectroGamingStudios/WaveGame + +#@!Game has crashed! Crash Report saved to /home/electronicsboy/ElectroGamingStudios/WaveGame/crashReports/CrashReport_10-0-2023 17-34-28.txt!@# diff --git a/crashReports/CrashReport_5-0-2023 22-16-3.txt b/crashReports/CrashReport_5-0-2023 22-16-3.txt new file mode 100644 index 0000000..0e062de --- /dev/null +++ b/crashReports/CrashReport_5-0-2023 22-16-3.txt @@ -0,0 +1,30 @@ +Game Crash Report +----------------- + +All known info is shown below +----------------------------- +StackTrace: +java.lang.NullPointerException: Cannot invoke "me.ElectronicsBoy.GameEngine.SpriteSheet.SpriteSheet.grabImage(int, int, int, int)" because "this.spriteSheet" is null + at me.ElectronicsBoy.wavegame.Game.getImg(Game.java:137) + at me.ElectronicsBoy.wavegame.entities.BasicEnemy.(BasicEnemy.java:16) + at me.ElectronicsBoy.wavegame.Game.tickUI(Game.java:67) + at me.ElectronicsBoy.GameEngine.gui.GUIWindow.tick(GUIWindow.java:27) + at me.ElectronicsBoy.GameEngine.Engine.tick(Engine.java:56) + at me.ElectronicsBoy.GameEngine.Engine.run(Engine.java:76) + at java.base/java.lang.Thread.run(Thread.java:833) + +Caused by: +null + +Message: +Cannot invoke "me.ElectronicsBoy.GameEngine.SpriteSheet.SpriteSheet.grabImage(int, int, int, int)" because "this.spriteSheet" is null +Current Thread: +Engine Thread + +System Details: +OS : Linux +OS Version : 5.15.0-56-generic +OS Architecture : amd64 +Current Dir : /home/electronicsboy/ElectroGamingStudios/WaveGame + +#@!Game has crashed! Crash Report saved to /home/electronicsboy/ElectroGamingStudios/WaveGame/crashReports/CrashReport_5-0-2023 22-16-3.txt!@# diff --git a/engine/me/ElectronicsBoy/GameEngine/gui/HUD.java b/engine/me/ElectronicsBoy/GameEngine/gui/HUD.java index 0345cdf..fc70a8d 100644 --- a/engine/me/ElectronicsBoy/GameEngine/gui/HUD.java +++ b/engine/me/ElectronicsBoy/GameEngine/gui/HUD.java @@ -3,21 +3,21 @@ import java.awt.Color; import java.awt.Font; import java.awt.Graphics; -import java.util.HashMap; +import java.util.ArrayList; +import java.util.List; import me.ElectronicsBoy.GameEngine.Util.Util; public class HUD { - private HashMaprenderNames = new HashMap(); - private HashMaprenderNamesValue = new HashMap(); + private List renderName = new ArrayList(); + private List renderValue = new ArrayList(); private Font font = new Font("arial", 1, 15); private int indent = 16; private int lastItemX = 5; private int nextX = lastItemX + indent; - private int lastValue = 0; public float health = 100; @@ -54,23 +54,29 @@ public void render(Graphics g) { g.setColor(Color.WHITE); g.setFont(font); - g.drawString(renderNames.get(0) + ": " + renderNamesValue.get(0), 15, nextX); - indent = 8; - nextX += lastItemX + indent; - for(int i = 1; i < renderNames.size(); i++) { - g.drawString(renderNames.get(i) + ": " + renderNamesValue.get(i), 15, nextX); + if(!renderName.isEmpty()) { + g.drawString(renderName.get(0) + ": " + renderValue.get(0), 15, nextX); + indent = 8; nextX += lastItemX + indent; + for(int i = 1; i < renderName.size(); i++) { + g.drawString(renderName.get(i) + ": " + renderValue.get(i), 15, nextX); + nextX += lastItemX + indent; + } } } public void addRenderValue(String var, String value) { - renderNames.put(lastValue, var); - renderNamesValue.put(lastValue, value); - lastValue++; + renderName.add(var); + renderValue.add(value); } public void updateValue(int valuePoint, String value) { int actuallPoint = valuePoint-1; - renderNamesValue.put(actuallPoint, value); + renderValue.set(actuallPoint, value); + } + + public void removeAll() { + renderName.removeIf((e) -> true); + renderValue.removeIf((e) -> true); } } diff --git a/res/save.bin b/res/save.bin index 2433742..b6c3efb 100644 Binary files a/res/save.bin and b/res/save.bin differ diff --git a/src/me/ElectronicsBoy/wavegame/Game.java b/src/me/ElectronicsBoy/wavegame/Game.java index a52c96e..3b977c4 100644 --- a/src/me/ElectronicsBoy/wavegame/Game.java +++ b/src/me/ElectronicsBoy/wavegame/Game.java @@ -37,6 +37,7 @@ public class Game extends GUIWindow implements HUDPostTick { public Main main; public boolean useSave = true; + public boolean inited = false; public Game(Engine engine) { super("PLAY", engine); @@ -53,11 +54,13 @@ public void init() { @Override public void tickUI() { if(gameStart) { + inited = true; ((Main)engine).handler.clearAll(); try { - if(useSave) + if(useSave) { save.read().forEach((e) -> { ((Main)engine).handler.addObject(e); }); - else { + hudReady = true; + }else { ((Main)engine).handler.addObject(new BasicEnemy()); player = new PlayerEntity(((Main)engine)); ((Main)engine).handler.addObject(player); @@ -139,4 +142,23 @@ public BufferedImage getImg(int i, int j, int k, int l) { @Override public void postHUDTick() {} + public void reset() { + levelsTillBoss = 0; + levelsReset = 0; + scoreKeep = 0; + reset = 0; + level = 1; + fullScore = 0; + player = null; + hudReady = false; + + afterScoreLevel = 100; + bossFight = false; + + boss = null; + hud.health = 100; + hud.removeAll(); + +// inited = false; + } } diff --git a/src/me/ElectronicsBoy/wavegame/gui/PauseMenu.java b/src/me/ElectronicsBoy/wavegame/gui/PauseMenu.java index d45129f..6255a7a 100644 --- a/src/me/ElectronicsBoy/wavegame/gui/PauseMenu.java +++ b/src/me/ElectronicsBoy/wavegame/gui/PauseMenu.java @@ -24,15 +24,7 @@ public void init() { } catch (Exception e) { e.printStackTrace(); } - Game.inst.level = 0; - Game.inst.levelsReset = 0; - Game.inst.scoreKeep = 0; - Game.inst.reset = 0; - Game.inst.level = 1; - Game.inst.afterScoreLevel = 100; - hud.health = 100; - hud.updateValue(1, "0"); - hud.updateValue(2, "0"); + Game.inst.reset(); engine.sys.setState("MENU"); })); addButton(new Button(190, 260, 230, 64, Color.WHITE, Color.WHITE, ButtonStyle.createStyle(new Font("arial", 1, 30), ButtonStyle.Rect), 260, 300, "Save", Color.WHITE, () -> { @@ -43,15 +35,7 @@ public void init() { } })); addButton(new Button(190, 170, 230, 64, Color.WHITE, Color.WHITE, ButtonStyle.createStyle(new Font("arial", 1, 30), ButtonStyle.Rect), 260, 210, "Quit", Color.WHITE, () -> { - Game.inst.level = 0; - Game.inst.levelsReset = 0; - Game.inst.scoreKeep = 0; - Game.inst.reset = 0; - Game.inst.level = 1; - Game.inst.afterScoreLevel = 100; - hud.health = 100; - hud.updateValue(1, "0"); - hud.updateValue(2, "0"); + Game.inst.reset(); engine.sys.setState("MENU"); })); addButton(new Button(190, 80, 230, 64, Color.WHITE, Color.WHITE, ButtonStyle.createStyle(new Font("arial", 1, 30), ButtonStyle.Rect), 230, 120, "Continue", Color.WHITE, () -> { diff --git a/src/me/ElectronicsBoy/wavegame/save/Save.java b/src/me/ElectronicsBoy/wavegame/save/Save.java index e8595f5..33ab95c 100644 --- a/src/me/ElectronicsBoy/wavegame/save/Save.java +++ b/src/me/ElectronicsBoy/wavegame/save/Save.java @@ -45,7 +45,6 @@ public void save() throws Exception { writer.writeFloat(main.hud.health); for(Entity e : main.entitis) { if(!(e instanceof BossEntity)) { - System.out.println(e.getClass().getName()); writer.writeString(e.getClass().getName()); writer.writeFloat(e.getX()); writer.writeFloat(e.getY()); @@ -60,6 +59,7 @@ public void save() throws Exception { } } public List read() throws Exception { + Game.inst.reset(); List entities = new ArrayList(); if(binfile.exists()) { BinaryReader reader = new BinaryReader(binfile); @@ -83,12 +83,17 @@ public List read() throws Exception { Game.inst.fullScore = reader.readInt(); Game.inst.afterScoreLevel = reader.readInt(); main.hud.health = reader.readFloat(); - main.hud.updateValue(1, Integer.toString(Game.inst.level)); + if(!Game.inst.hudReady){ + main.hud.addRenderValue("Level", Integer.toString(Game.inst.level)); + main.hud.addRenderValue("Score", Integer.toString(Game.inst.scoreKeep)); + }else { + main.hud.updateValue(1, Integer.toString(Game.inst.level)); + main.hud.updateValue(2, Integer.toString(Game.inst.scoreKeep)); + } while(reader.available()) { Entity e; String s = reader.readString(); - System.out.println(s); switch(s) { case "me.ElectronicsBoy.wavegame.entities.PlayerEntity": e = new PlayerEntity(main);