From 1574ca33bc2ee1576409b9a0a50bfd3fd95eaaae Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 30 Apr 2017 13:18:20 -0400 Subject: [PATCH] Added difficulty, fixed some bugs --- core/src/io/anuke/moment/Control.java | 3 ++- core/src/io/anuke/moment/Moment.java | 28 +++++++++++++++++++---- core/src/io/anuke/moment/UI.java | 12 ++++++---- core/src/io/anuke/moment/ai/Pathfind.java | 4 ++++ 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/core/src/io/anuke/moment/Control.java b/core/src/io/anuke/moment/Control.java index 23094b4878..e42d02d6af 100644 --- a/core/src/io/anuke/moment/Control.java +++ b/core/src/io/anuke/moment/Control.java @@ -404,6 +404,7 @@ public class Control extends RendererModule{ void drawHealth(DestructibleEntity dest){ float len = 3; float offset = 7; + Draw.thickness(3f); Draw.color(Color.GRAY); Draw.line(dest.x - len + 1, dest.y - offset, dest.x + len + 1, dest.y - offset); @@ -411,7 +412,7 @@ public class Control extends RendererModule{ Draw.color(Color.BLACK); Draw.line(dest.x - len + 1, dest.y - offset, dest.x + len, dest.y - offset); Draw.color(Color.RED); - Draw.line(dest.x - len + 1, dest.y - offset, dest.x - len + len * 2 * ((float) dest.health / dest.maxhealth), dest.y - offset); + Draw.line(dest.x - len + 1, dest.y - offset, dest.x - len + (int)(len * 2 * ((float) dest.health / dest.maxhealth)), dest.y - offset); Draw.clear(); } diff --git a/core/src/io/anuke/moment/Moment.java b/core/src/io/anuke/moment/Moment.java index 68dd422dea..5876b88137 100644 --- a/core/src/io/anuke/moment/Moment.java +++ b/core/src/io/anuke/moment/Moment.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; +import io.anuke.moment.ai.Pathfind; import io.anuke.moment.entities.Enemy; import io.anuke.moment.entities.Player; import io.anuke.moment.resource.Item; @@ -35,7 +36,7 @@ public class Moment extends ModuleController{ public int wave = 1; public float wavespace = 60*60; - public float wavetime = wavespace; + public float wavetime; public float spawnspace = 65; public Tile core; public Array spawnpoints = new Array(); @@ -52,7 +53,7 @@ public class Moment extends ModuleController{ } @Override - public void setup(){ + public void preInit(){ KeyBinds.defaults( "up", Keys.W, "left", Keys.A, @@ -76,6 +77,10 @@ public class Moment extends ModuleController{ player = new Player(); + } + + @Override + public void postInit(){ restart(); } @@ -95,12 +100,13 @@ public class Moment extends ModuleController{ } public void play(){ + wavetime = waveSpacing(); playing = true; } public void restart(){ wave = 1; - wavetime = wavespace; + wavetime = waveSpacing(); Entities.clear(); Enemy.amount = 0; player.add(); @@ -112,10 +118,12 @@ public class Moment extends ModuleController{ player.y = core.worldy()+10; items.put(Item.stone, 20); + + if(get(UI.class).about != null) + get(UI.class).updateItems(); } public void coreDestroyed(){ - //TODO "you lose" message or something Effects.shake(5, 6); for(int i = 0; i < 16; i ++){ Timers.run(i*2, ()->{ @@ -131,7 +139,10 @@ public class Moment extends ModuleController{ } void generate(){ + spawnpoints.clear(); + Pathfind.reset(); Generator.generate(tiles, "map"); + Pathfind.updatePath(); core.setBlock(TileType.core); int x = core.x, y = core.y; @@ -174,7 +185,14 @@ public class Moment extends ModuleController{ } wave ++; - wavetime = wavespace; + + wavetime = waveSpacing(); + } + + public float waveSpacing(){ + int scale = Settings.getInt("difficulty"); + float out = (scale == 0 ? 2f : scale == 1f ? 1f : 0.5f); + return wavespace*out; } public Tile tile(int x, int y){ diff --git a/core/src/io/anuke/moment/UI.java b/core/src/io/anuke/moment/UI.java index 57599c6833..3f05180e4b 100644 --- a/core/src/io/anuke/moment/UI.java +++ b/core/src/io/anuke/moment/UI.java @@ -12,9 +12,7 @@ import io.anuke.moment.entities.Enemy; import io.anuke.moment.resource.*; import io.anuke.moment.world.Tile; import io.anuke.moment.world.TileType; -import io.anuke.ucore.core.Draw; -import io.anuke.ucore.core.UGraphics; -import io.anuke.ucore.core.UInput; +import io.anuke.ucore.core.*; import io.anuke.ucore.modules.SceneModule; import io.anuke.ucore.scene.builders.*; import io.anuke.ucore.scene.style.Styles; @@ -107,6 +105,10 @@ public class UI extends SceneModule{ return (i / 4f) + "x"; }); + prefs.sliderPref("difficulty", "Difficulty", 1, 0, 2, i -> { + return i == 0 ? "Easy" : i == 1 ? "Normal" : "Hard"; + }); + prefs.checkPref("fps", "Show FPS", false); @@ -116,7 +118,7 @@ public class UI extends SceneModule{ about.getContentTable().add("Made by Anuken for the" + "\nGDL Metal Monstrosity jam." + "\nTools used:"); about.addCloseButton(); - restart = new Dialog("Your core was destroyed.", "dialog"); + restart = new Dialog("The core was destroyed.", "dialog"); restart.content().add("You lasted until wave [GREEN]" + main.wave + "[].").pad(6); restart.getButtonTable().addButton("Back to menu", ()->{ restart.hide(); @@ -348,7 +350,7 @@ public class UI extends SceneModule{ Label fps = new Label(""); fps.update(()->{ - fps.setText(Gdx.graphics.getFramesPerSecond() + " FPS"); + fps.setText(Settings.getBool("fps") ? (Gdx.graphics.getFramesPerSecond() + " FPS") : ""); }); row(); add(fps); diff --git a/core/src/io/anuke/moment/ai/Pathfind.java b/core/src/io/anuke/moment/ai/Pathfind.java index d9953cafa9..b036fe35cd 100644 --- a/core/src/io/anuke/moment/ai/Pathfind.java +++ b/core/src/io/anuke/moment/ai/Pathfind.java @@ -46,6 +46,10 @@ public class Pathfind{ } + static public void reset(){ + paths.clear(); + } + static public void updatePath(){ if(paths.size == 0){ for(int i = 0; i < Moment.i.spawnpoints.size; i ++){