diff --git a/core/src/com/saltosion/gladiator/input/IRDebugToggle.java b/core/src/com/saltosion/gladiator/input/IRDebugToggle.java new file mode 100644 index 0000000..46ffccd --- /dev/null +++ b/core/src/com/saltosion/gladiator/input/IRDebugToggle.java @@ -0,0 +1,26 @@ +package com.saltosion.gladiator.input; + +import com.saltosion.gladiator.systems.RenderingSystem; +import com.saltosion.gladiator.util.AppUtil; + +/** + * + * @author Jens "Jeasonfire" Pitkänen + */ +public class IRDebugToggle implements InputReceiver { + + @Override + public boolean pressed() { + RenderingSystem renderingSystem = AppUtil.engine.getSystem(RenderingSystem.class); + if (renderingSystem != null) { + renderingSystem.setDebug(!renderingSystem.getDebug()); + } + return true; + } + + @Override + public boolean released() { + return false; + } + +} diff --git a/core/src/com/saltosion/gladiator/input/InputHandler.java b/core/src/com/saltosion/gladiator/input/InputHandler.java index ef208ae..30f82fc 100644 --- a/core/src/com/saltosion/gladiator/input/InputHandler.java +++ b/core/src/com/saltosion/gladiator/input/InputHandler.java @@ -7,7 +7,7 @@ import com.badlogic.gdx.InputProcessor; import com.saltosion.gladiator.util.Name; public class InputHandler implements InputProcessor { - + public HashMap keys = new HashMap(); public InputHandler() { @@ -18,8 +18,9 @@ public class InputHandler implements InputProcessor { keys.put(Keys.RIGHT, Name.SWING_RIGHT); keys.put(Keys.UP, Name.SWING_UP); keys.put(Keys.DOWN, Name.SWING_DOWN); + keys.put(Keys.F2, Name.DEBUG); } - + @Override public boolean keyDown(int keycode) { if (!keys.containsKey(keycode)) { diff --git a/core/src/com/saltosion/gladiator/input/InputReceiver.java b/core/src/com/saltosion/gladiator/input/InputReceiver.java index 13ce98c..a56c5e3 100644 --- a/core/src/com/saltosion/gladiator/input/InputReceiver.java +++ b/core/src/com/saltosion/gladiator/input/InputReceiver.java @@ -1,6 +1,15 @@ package com.saltosion.gladiator.input; public interface InputReceiver { + + /** + * @return Returns if the keypress was handled. + */ public boolean pressed(); + + /** + * @return Returns if the key's release was handled. + */ public boolean released(); + } diff --git a/core/src/com/saltosion/gladiator/input/InputReceivers.java b/core/src/com/saltosion/gladiator/input/InputReceivers.java index d220069..1541f31 100644 --- a/core/src/com/saltosion/gladiator/input/InputReceivers.java +++ b/core/src/com/saltosion/gladiator/input/InputReceivers.java @@ -6,8 +6,9 @@ import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Name; public class InputReceivers { - public static HashMap inputreceivers = new HashMap(); - + + public static final HashMap inputreceivers = new HashMap(); + static { inputreceivers.put(Name.MOVE_LEFT, new IRMoveLeft()); inputreceivers.put(Name.MOVE_RIGHT, new IRMoveRight()); @@ -16,8 +17,9 @@ public class InputReceivers { inputreceivers.put(Name.SWING_RIGHT, new IRSwing(Direction.RIGHT)); inputreceivers.put(Name.SWING_UP, new IRSwing(Direction.UP)); inputreceivers.put(Name.SWING_DOWN, new IRSwing(Direction.DOWN)); + inputreceivers.put(Name.DEBUG, new IRDebugToggle()); } - + public static InputReceiver getReceiver(String key) { return inputreceivers.get(key); } diff --git a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java index d025ab6..27d9beb 100644 --- a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java +++ b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java @@ -7,10 +7,13 @@ import com.badlogic.ashley.core.EntitySystem; import com.badlogic.ashley.core.Family; import com.badlogic.ashley.utils.ImmutableArray; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CRenderedObject; import com.saltosion.gladiator.util.AppUtil; @@ -18,27 +21,32 @@ import com.saltosion.gladiator.util.SpriteSequence; public class RenderingSystem extends EntitySystem { - private ComponentMapper rom = ComponentMapper.getFor(CRenderedObject.class); - private ComponentMapper pm = ComponentMapper.getFor(CPhysics.class); + private final ComponentMapper rom = ComponentMapper.getFor(CRenderedObject.class); + private final ComponentMapper pm = ComponentMapper.getFor(CPhysics.class); private ImmutableArray entities; - + private SpriteBatch batch; + private ShapeRenderer debugRenderer; private OrthographicCamera camera; - + + private boolean debug = true; + private final Color debugColor = new Color(0, 1, 0, 1); + @Override public void addedToEngine(Engine engine) { - + updateEntities(engine); - + batch = new SpriteBatch(); + debugRenderer = new ShapeRenderer(); camera = new OrthographicCamera(); camera.setToOrtho(false, 1, 1); } - + public void setViewport(int width, int height) { camera.setToOrtho(false, width, height); } - + @Override public void update(float deltaTime) { CPhysics phys = pm.get(AppUtil.player); @@ -49,29 +57,56 @@ public class RenderingSystem extends EntitySystem { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(camera.combined); batch.begin(); - for (int i=0; i