diff options
13 files changed, 141 insertions, 27 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/FramedSprite.java b/core/src/ch/asynk/gdx/boardgame/FramedSprite.java index 1f60f9c..8fc2e80 100644 --- a/core/src/ch/asynk/gdx/boardgame/FramedSprite.java +++ b/core/src/ch/asynk/gdx/boardgame/FramedSprite.java @@ -3,6 +3,7 @@ package ch.asynk.gdx.boardgame; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; public class FramedSprite implements Drawable, Positionable { @@ -101,4 +102,18 @@ public class FramedSprite implements Drawable, Positionable { batch.draw(frame, x, y, 0, 0, frame.getRegionWidth(), frame.getRegionHeight(), 1f, 1f, r); } + + @Override public void drawDebug(ShapeRenderer shapeRenderer) + { + shapeRenderer.end(); + shapeRenderer.begin(ShapeRenderer.ShapeType.Line); + shapeRenderer.identity(); + shapeRenderer.translate(x, y, 0); + shapeRenderer.rotate(0, 0, 1, r); + shapeRenderer.translate(-x, -y, 0); + shapeRenderer.rect(x, y, frame.getRegionWidth(), frame.getRegionHeight()); + shapeRenderer.end(); + shapeRenderer.begin(ShapeRenderer.ShapeType.Line); + shapeRenderer.identity(); + } } diff --git a/core/src/ch/asynk/gdx/boardgame/Overlays.java b/core/src/ch/asynk/gdx/boardgame/Overlays.java index 392d1cd..5746630 100644 --- a/core/src/ch/asynk/gdx/boardgame/Overlays.java +++ b/core/src/ch/asynk/gdx/boardgame/Overlays.java @@ -3,6 +3,7 @@ package ch.asynk.gdx.boardgame; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.utils.Array; import ch.asynk.gdx.boardgame.Drawable; @@ -120,4 +121,18 @@ public class Overlays implements Drawable, Positionable, Rotable, Scalable } } } + + @Override public void drawDebug(ShapeRenderer shapeRenderer) + { + if (!isEnabled) return; + for (int i = 0, n = sprites.size; i < n; i++) { + if (enabled[i]) { + final Sprite sprite = sprites.get(i); + float w = sprite.getWidth(); + float h = sprite.getHeight(); + shapeRenderer.rect(sprite.getX(), sprite.getY(), (w / 2f), (h / 2f), w, h, sprite.getScaleX(), sprite.getScaleY(), sprite.getRotation()); + return; + } + } + } } diff --git a/core/src/ch/asynk/gdx/boardgame/Piece.java b/core/src/ch/asynk/gdx/boardgame/Piece.java index 5008d9a..275ea58 100644 --- a/core/src/ch/asynk/gdx/boardgame/Piece.java +++ b/core/src/ch/asynk/gdx/boardgame/Piece.java @@ -4,6 +4,7 @@ import java.lang.Math; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.MathUtils; @@ -69,4 +70,11 @@ public class Piece extends Sprite implements Drawable, Positionable, Rotable, Sc { v.set(getX()+ (getWidth() / 2f), getY() + (getHeight() / 2f)); } + + @Override public void drawDebug(ShapeRenderer shapeRenderer) + { + float w = getWidth(); + float h = getHeight(); + shapeRenderer.rect(getX(), getY(), (w / 2f), (h / 2f), w, h, getScaleX(), getScaleY(), getRotation()); + } } diff --git a/core/src/ch/asynk/gdx/boardgame/Tile.java b/core/src/ch/asynk/gdx/boardgame/Tile.java index dda0307..d051cef 100644 --- a/core/src/ch/asynk/gdx/boardgame/Tile.java +++ b/core/src/ch/asynk/gdx/boardgame/Tile.java @@ -2,6 +2,7 @@ package ch.asynk.gdx.boardgame; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ch.asynk.gdx.boardgame.Overlays; @@ -41,4 +42,11 @@ public class Tile implements Drawable { return "[" + x + ", " + y + "]"; } + + @Override public void drawDebug(ShapeRenderer shapeRenderer) + { + if (overlays != null) { + overlays.drawDebug(shapeRenderer); + } + } } diff --git a/core/src/ch/asynk/gdx/boardgame/animations/AnimationBatch.java b/core/src/ch/asynk/gdx/boardgame/animations/AnimationBatch.java index 9fdcfb9..1bc047f 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/AnimationBatch.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/AnimationBatch.java @@ -2,6 +2,7 @@ package ch.asynk.gdx.boardgame.animations; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ch.asynk.gdx.boardgame.utils.IterableArray; @@ -78,4 +79,13 @@ public class AnimationBatch implements Animation, Pool.Poolable } } } + + @Override public void drawDebug(ShapeRenderer shapeRenderer) + { + if (!completed()) { + for (Animation animation : animations) { + animation.drawDebug(shapeRenderer); + } + } + } } diff --git a/core/src/ch/asynk/gdx/boardgame/animations/AnimationSequence.java b/core/src/ch/asynk/gdx/boardgame/animations/AnimationSequence.java index 0569a40..08091d2 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/AnimationSequence.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/AnimationSequence.java @@ -2,6 +2,7 @@ package ch.asynk.gdx.boardgame.animations; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ch.asynk.gdx.boardgame.utils.IterableArray; @@ -75,4 +76,11 @@ public class AnimationSequence implements Animation, Pool.Poolable animations.get(0).draw(batch); } } + + @Override public void drawDebug(ShapeRenderer shapeRenderer) + { + if (!completed()) { + animations.get(0).drawDebug(shapeRenderer); + } + } } diff --git a/core/src/ch/asynk/gdx/boardgame/animations/FireAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/FireAnimation.java index a8b4546..6e44d40 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/FireAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/FireAnimation.java @@ -3,6 +3,7 @@ package ch.asynk.gdx.boardgame.animations; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.Pool; @@ -187,4 +188,15 @@ public class FireAnimation implements Animation, Pool.Poolable } } } + + @Override public void drawDebug(ShapeRenderer shapeRenderer) + { + if (single) { + this.shot.drawDebug(shapeRenderer); + } else { + for (ShotAnimation shot : this.shots) { + shot.drawDebug(shapeRenderer); + } + } + } } diff --git a/core/src/ch/asynk/gdx/boardgame/animations/ShotAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/ShotAnimation.java index 890b6a4..ad2d198 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/ShotAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/ShotAnimation.java @@ -4,6 +4,7 @@ import java.util.Random; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.utils.Pool; @@ -183,4 +184,15 @@ public class ShotAnimation extends TimedAnimation implements Drawable, Pool.Pool this.explosionSprites.draw(batch); } } + + @Override public void drawDebug(ShapeRenderer shapeRenderer) + { + if (drawFire) { + this.shellSprites.drawDebug(shapeRenderer); + } + + if (drawExplosion) { + this.explosionSprites.drawDebug(shapeRenderer); + } + } } diff --git a/test/src/ch/asynk/gdx/boardgame/test/AbstractScreen.java b/test/src/ch/asynk/gdx/boardgame/test/AbstractScreen.java index d65c853..deb8dca 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/AbstractScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/AbstractScreen.java @@ -30,7 +30,7 @@ public abstract class AbstractScreen implements Screen protected final Vector3 boardTouch = new Vector3(); protected final Vector3 hudTouch = new Vector3(); - private ShapeRenderer debugShapes = null; + private ShapeRenderer shapeRenderer = null; protected final String dom; protected final GdxBoardTest app; @@ -55,18 +55,21 @@ public abstract class AbstractScreen implements Screen this.inputDelay = 0f; this.paused = false; - if (DEBUG) this.debugShapes = new ShapeRenderer(); + if (DEBUG) this.shapeRenderer = new ShapeRenderer(); HdpiUtils.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); } - protected void drawDebug(ShapeRenderer shapeRenderer) { } + protected abstract boolean animate(float delta); protected abstract void draw(SpriteBatch batch); + protected abstract void drawDebug(ShapeRenderer shapeRenderer); @Override public void render(float delta) { if (paused) return; - Gdx.gl.glClearColor(1, 1, 1, 1); + if (!animate(delta)) return; + + Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); @@ -77,11 +80,11 @@ public abstract class AbstractScreen implements Screen if (DEBUG) { Gdx.gl.glEnable(GL20.GL_BLEND); - debugShapes.setAutoShapeType(true); - debugShapes.setProjectionMatrix(camera.combined); - debugShapes.begin(); - drawDebug(debugShapes); - debugShapes.end(); + shapeRenderer.setAutoShapeType(true); + shapeRenderer.setProjectionMatrix(camera.combined); + shapeRenderer.begin(); + drawDebug(shapeRenderer); + shapeRenderer.end(); } } diff --git a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java index 19602ee..6fcc30f 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java @@ -3,6 +3,7 @@ package ch.asynk.gdx.boardgame.test; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.math.Vector2; @@ -164,11 +165,8 @@ public class AnimationsScreen extends AbstractScreen super.dispose(); } - @Override public void draw(SpriteBatch batch) { } - @Override public void render(float delta) + @Override protected boolean animate(float delta) { - if (paused) return; - if (inputBlocked) { inputDelay -= delta; if (inputDelay <= 0f) @@ -178,15 +176,13 @@ public class AnimationsScreen extends AbstractScreen dice.animate(delta); if (animations.animate(delta)) { app.switchToMenu(); - return; + return false; } + return true; + } - Gdx.gl.glClearColor(0, 0, 0, 1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - - cam.applyBoardViewport(); - batch.setProjectionMatrix(cam.combined); - batch.begin(); + @Override public void draw(SpriteBatch batch) + { batch.draw(map, 0, 0); for (int i = 0; i < path.size(); i++) { path.get(i).draw(batch); @@ -197,7 +193,19 @@ public class AnimationsScreen extends AbstractScreen other2.draw(batch); dice.draw(batch); animations.draw(batch); - batch.end(); + } + + @Override public void drawDebug(ShapeRenderer shapeRenderer) + { + for (int i = 0; i < path.size(); i++) { + path.get(i).drawDebug(shapeRenderer); + } + panzer.drawDebug(shapeRenderer); + other0.drawDebug(shapeRenderer); + other1.drawDebug(shapeRenderer); + other2.drawDebug(shapeRenderer); + dice.drawDebug(shapeRenderer); + animations.drawDebug(shapeRenderer); } @Override public void resize(int width, int height) diff --git a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java index 85b57c9..5357449 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java @@ -3,6 +3,7 @@ package ch.asynk.gdx.boardgame.test; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.math.Vector2; @@ -170,19 +171,19 @@ public class BoardScreen extends AbstractScreen setState(State.HEX_V); } - @Override public void draw(SpriteBatch batch) { } - @Override public void render(float delta) + @Override protected boolean animate(float delta) { - if (paused) return; - if (inputBlocked) { inputDelay -= delta; if (inputDelay <= 0f) inputBlocked = false; } + return true; + } - Gdx.gl.glClearColor(0, 0, 0, 1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + @Override public void draw(SpriteBatch batch) + { + batch.end(); // for AbstractScreen cam.applyBoardViewport(); batch.setProjectionMatrix(cam.combined); @@ -195,8 +196,12 @@ public class BoardScreen extends AbstractScreen batch.begin(); root.draw(batch); batch.end(); + + batch.begin(); // for AbstractScreen } + @Override public void drawDebug(ShapeRenderer shapeRenderer) { } + @Override public void resize(int width, int height) { GdxBoardTest.debug("BoardScrean", String.format("resize (%d,%d)",width, height)); diff --git a/test/src/ch/asynk/gdx/boardgame/test/MenuScreen.java b/test/src/ch/asynk/gdx/boardgame/test/MenuScreen.java index 95dbd80..3c198e0 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/MenuScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/MenuScreen.java @@ -3,6 +3,7 @@ package ch.asynk.gdx.boardgame.test; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ch.asynk.gdx.boardgame.ui.Alignment; import ch.asynk.gdx.boardgame.ui.Menu; @@ -34,6 +35,8 @@ public class MenuScreen extends AbstractScreen this.camera.position.set(bg.getWidth() / 2f, bg.getHeight() / 2f, 0); } + @Override protected boolean animate(float delta) { return true; } + @Override protected void draw(SpriteBatch batch) { batch.draw(bg, 0, 0); @@ -41,6 +44,11 @@ public class MenuScreen extends AbstractScreen root.draw(batch); } + @Override protected void drawDebug(ShapeRenderer shapeRenderer) + { + root.drawDebug(shapeRenderer); + } + private void drawCorners(SpriteBatch batch) { float right = root.getInnerX() + root.getInnerWidth() - corner.getWidth(); diff --git a/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java b/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java index 8793510..14d282c 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java @@ -94,6 +94,8 @@ public class UiScreen extends AbstractScreen this.state = state; } + @Override protected boolean animate(float delta) { return true; } + @Override protected void draw(SpriteBatch batch) { batch.draw(bg, 0, 0); |