diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2019-12-17 16:22:28 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2019-12-17 16:22:28 +0100 |
commit | bc6b9374d9eb228bbc3d66ed6f77ea4e6ff084fe (patch) | |
tree | 829e1f7b008c5262e4dd777015732582e26009c4 /core/src/ch/asynk/gdx | |
parent | 36d827659b54b04c90722eb2e431f622b33c047c (diff) | |
download | gdx-boardgame-bc6b9374d9eb228bbc3d66ed6f77ea4e6ff084fe.zip gdx-boardgame-bc6b9374d9eb228bbc3d66ed6f77ea4e6ff084fe.tar.gz |
core : implement drawDebug(ShapeRenderer)
Diffstat (limited to 'core/src/ch/asynk/gdx')
8 files changed, 88 insertions, 0 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); + } + } } |