Added debug rendering. Toggle with F2.
This commit is contained in:
parent
6e1387662d
commit
ae5300f3fd
26
core/src/com/saltosion/gladiator/input/IRDebugToggle.java
Normal file
26
core/src/com/saltosion/gladiator/input/IRDebugToggle.java
Normal file
@ -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 <jeasonfire@gmail.com>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -18,6 +18,7 @@ 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
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,8 @@ import com.saltosion.gladiator.util.Direction;
|
||||
import com.saltosion.gladiator.util.Name;
|
||||
|
||||
public class InputReceivers {
|
||||
public static HashMap<String, InputReceiver> inputreceivers = new HashMap<String, InputReceiver>();
|
||||
|
||||
public static final HashMap<String, InputReceiver> inputreceivers = new HashMap<String, InputReceiver>();
|
||||
|
||||
static {
|
||||
inputreceivers.put(Name.MOVE_LEFT, new IRMoveLeft());
|
||||
@ -16,6 +17,7 @@ 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) {
|
||||
|
@ -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,19 +21,24 @@ import com.saltosion.gladiator.util.SpriteSequence;
|
||||
|
||||
public class RenderingSystem extends EntitySystem {
|
||||
|
||||
private ComponentMapper<CRenderedObject> rom = ComponentMapper.getFor(CRenderedObject.class);
|
||||
private ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class);
|
||||
private final ComponentMapper<CRenderedObject> rom = ComponentMapper.getFor(CRenderedObject.class);
|
||||
private final ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class);
|
||||
private ImmutableArray<Entity> 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);
|
||||
}
|
||||
@ -68,10 +76,37 @@ public class RenderingSystem extends EntitySystem {
|
||||
renderedObject.setCurrentFrame(nextFrame % currSequence.frameCount());
|
||||
}
|
||||
batch.end();
|
||||
|
||||
if (debug) {
|
||||
debugRenderer.setProjectionMatrix(camera.combined);
|
||||
debugRenderer.begin(ShapeType.Line);
|
||||
debugRenderer.setColor(debugColor);
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
CPhysics physics = pm.get(entities.get(i));
|
||||
float x0 = physics.getPosition().x - physics.getSize().x / 2;
|
||||
float x1 = physics.getPosition().x + physics.getSize().x / 2;
|
||||
float y0 = physics.getPosition().y - physics.getSize().y / 2;
|
||||
float y1 = physics.getPosition().y + physics.getSize().y / 2;
|
||||
|
||||
debugRenderer.line(x0, y0, x1, y0);
|
||||
debugRenderer.line(x1, y0, x1, y1);
|
||||
debugRenderer.line(x1, y1, x0, y1);
|
||||
debugRenderer.line(x0, y1, x0, y0);
|
||||
}
|
||||
debugRenderer.end();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateEntities(Engine engine) {
|
||||
entities = engine.getEntitiesFor(Family.getFor(CRenderedObject.class, CPhysics.class));
|
||||
}
|
||||
|
||||
public boolean getDebug() {
|
||||
return this.debug;
|
||||
}
|
||||
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ public class Name {
|
||||
|
||||
public static final String GAME_NAME = "Gladiator Brawl";
|
||||
|
||||
public static final String DEBUG = "DEBUG";
|
||||
|
||||
public static final String STATICPLAYER = "STATICPLAYER";
|
||||
public static final String PLAYERIMG = "PLAYERIMG";
|
||||
public static final String GROUNDIMG = "GROUNDIMG";
|
||||
|
Loading…
Reference in New Issue
Block a user