From 3be9db7d4d603791727b2cb3bcec7ae38d3cda50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 18 Oct 2018 16:48:50 +0200 Subject: kill pieces subdirectory for now --- core/src/ch/asynk/gdx/boardgame/Overlays.java | 118 +++++++++++++++++++++ core/src/ch/asynk/gdx/boardgame/Path.java | 1 - core/src/ch/asynk/gdx/boardgame/Piece.java | 56 ++++++++++ .../gdx/boardgame/animations/BounceAnimation.java | 2 +- .../gdx/boardgame/animations/MoveAnimation.java | 2 +- .../ch/asynk/gdx/boardgame/pieces/Overlays.java | 118 --------------------- core/src/ch/asynk/gdx/boardgame/pieces/Piece.java | 56 ---------- .../asynk/gdx/boardgame/test/AnimationsScreen.java | 2 +- .../ch/asynk/gdx/boardgame/test/BoardScreen.java | 2 +- 9 files changed, 178 insertions(+), 179 deletions(-) create mode 100644 core/src/ch/asynk/gdx/boardgame/Overlays.java create mode 100644 core/src/ch/asynk/gdx/boardgame/Piece.java delete mode 100644 core/src/ch/asynk/gdx/boardgame/pieces/Overlays.java delete mode 100644 core/src/ch/asynk/gdx/boardgame/pieces/Piece.java diff --git a/core/src/ch/asynk/gdx/boardgame/Overlays.java b/core/src/ch/asynk/gdx/boardgame/Overlays.java new file mode 100644 index 0000000..fb77d55 --- /dev/null +++ b/core/src/ch/asynk/gdx/boardgame/Overlays.java @@ -0,0 +1,118 @@ +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; +import ch.asynk.gdx.boardgame.Positionable; +import ch.asynk.gdx.boardgame.Rotable; +import ch.asynk.gdx.boardgame.Scalable; + +public class Overlays implements Drawable, Positionable, Rotable, Scalable +{ + private boolean enabled[]; + private Array sprites; + + public Overlays(TextureAtlas atlas) + { + this.sprites = atlas.createSprites(); + this.enabled = new boolean[sprites.size]; + } + + public void disableAll() + { + for (int i = 0; i < sprites.size; i++) + enabled[i] = false; + } + + public void enable(int i, boolean enable) + { + enabled[i] = enable; + } + + public boolean isEnabled(int i) + { + return enabled[i]; + } + + public boolean isEnabled() + { + for (int i = 0; i < sprites.size; i++) { + if (enabled[i]) { + return true; + } + } + return false; + } + + @Override public float getX() { return sprites.get(0).getX(); } + @Override public float getY() { return sprites.get(0).getY(); } + @Override public float getWidth() { return sprites.get(0).getWidth(); } + @Override public float getHeight() { return sprites.get(0).getHeight(); } + + @Override public void translate(float dx, float dy) + { + for (Sprite sprite : sprites) { + sprite.translate(dx, dy); + } + } + + @Override public void centerOn(float cx, float cy) + { + for (Sprite sprite : sprites) { + sprite.setPosition( + (cx - (sprite.getWidth() / 2f)), + (cy - (sprite.getHeight() / 2f))); + } + } + + @Override public void setPosition(float x, float y) + { + for (Sprite sprite : sprites) { + sprite.setPosition(x, y); + } + } + + @Override public float getRotation() + { + return sprites.get(0).getRotation(); + } + + @Override public void setRotation(float rotation) + { + for (Sprite sprite : sprites) { + sprite.setRotation(rotation); + } + } + + @Override public float getScale() + { + return sprites.get(0).getScaleX(); + } + + @Override public void setScale(float scale) + { + for (Sprite sprite : sprites) { + sprite.setScale(scale); + } + } + + @Override public void setAlpha(float alpha) + { + for (Sprite sprite : sprites) { + sprite.setAlpha(alpha); + } + } + + @Override public void draw(Batch batch) + { + for (int i = 0, n = sprites.size; i < n; i++) { + if (enabled[i]) { + sprites.get(i).draw(batch); + } + } + } +} diff --git a/core/src/ch/asynk/gdx/boardgame/Path.java b/core/src/ch/asynk/gdx/boardgame/Path.java index de148ae..97aaabe 100644 --- a/core/src/ch/asynk/gdx/boardgame/Path.java +++ b/core/src/ch/asynk/gdx/boardgame/Path.java @@ -6,7 +6,6 @@ import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.Disposable; -import ch.asynk.gdx.boardgame.pieces.Piece; import ch.asynk.gdx.boardgame.utils.IterableArray; public class Path extends IterableArray implements Disposable, Pool.Poolable diff --git a/core/src/ch/asynk/gdx/boardgame/Piece.java b/core/src/ch/asynk/gdx/boardgame/Piece.java new file mode 100644 index 0000000..9e253e4 --- /dev/null +++ b/core/src/ch/asynk/gdx/boardgame/Piece.java @@ -0,0 +1,56 @@ +package ch.asynk.gdx.boardgame; + +import java.lang.Math; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.math.Vector3; + +import ch.asynk.gdx.boardgame.Drawable; +import ch.asynk.gdx.boardgame.Orientation; +import ch.asynk.gdx.boardgame.Positionable; +import ch.asynk.gdx.boardgame.Rotable; +import ch.asynk.gdx.boardgame.Scalable; +import ch.asynk.gdx.boardgame.Tile; + +public class Piece extends Sprite implements Drawable, Positionable, Rotable, Scalable +{ + public Piece(Texture texture) + { + super(texture); + } + + @Override public float getScale() + { + return getScaleX(); + } + + @Override public void centerOn(float cx, float cy) + { + setPosition((cx - (getWidth() / 2f)), (cy - (getHeight() / 2f))); + } + + public void getPosOn(Tile tile, Orientation orientation, Vector3 v) + { + v.set((tile.x - (getWidth() / 2f)), (tile.y- (getHeight() / 2f)), orientation.r()); + } + + public void setPosition(float x, float y, float r) + { + setPosition(x, y); + setRotation(r); + } + + public boolean isOn(Tile tile) + { + return ( + (Math.abs(getX() - (tile.x - (getWidth() / 2f))) < 3) && + (Math.abs(getY() - (tile.y- (getHeight() / 2f))) < 3) + ); + } + + public boolean isFacing(Orientation orientation) + { + return (Orientation.fromR(getRotation()) == orientation); + } +} diff --git a/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java index 17f0a53..cd4f3aa 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/BounceAnimation.java @@ -5,7 +5,7 @@ import java.lang.Math; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.graphics.g2d.Batch; -import ch.asynk.gdx.boardgame.pieces.Piece; +import ch.asynk.gdx.boardgame.Piece; public class BounceAnimation extends TimedAnimation implements Pool.Poolable { diff --git a/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java index e47eb3a..823f7c6 100644 --- a/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java +++ b/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java @@ -6,7 +6,7 @@ import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.math.Vector3; -import ch.asynk.gdx.boardgame.pieces.Piece; +import ch.asynk.gdx.boardgame.Piece; import ch.asynk.gdx.boardgame.Path; public class MoveAnimation implements Animation, Pool.Poolable diff --git a/core/src/ch/asynk/gdx/boardgame/pieces/Overlays.java b/core/src/ch/asynk/gdx/boardgame/pieces/Overlays.java deleted file mode 100644 index 387090a..0000000 --- a/core/src/ch/asynk/gdx/boardgame/pieces/Overlays.java +++ /dev/null @@ -1,118 +0,0 @@ -package ch.asynk.gdx.boardgame.pieces; - -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; -import ch.asynk.gdx.boardgame.Positionable; -import ch.asynk.gdx.boardgame.Rotable; -import ch.asynk.gdx.boardgame.Scalable; - -public class Overlays implements Drawable, Positionable, Rotable, Scalable -{ - private boolean enabled[]; - private Array sprites; - - public Overlays(TextureAtlas atlas) - { - this.sprites = atlas.createSprites(); - this.enabled = new boolean[sprites.size]; - } - - public void disableAll() - { - for (int i = 0; i < sprites.size; i++) - enabled[i] = false; - } - - public void enable(int i, boolean enable) - { - enabled[i] = enable; - } - - public boolean isEnabled(int i) - { - return enabled[i]; - } - - public boolean isEnabled() - { - for (int i = 0; i < sprites.size; i++) { - if (enabled[i]) { - return true; - } - } - return false; - } - - @Override public float getX() { return sprites.get(0).getX(); } - @Override public float getY() { return sprites.get(0).getY(); } - @Override public float getWidth() { return sprites.get(0).getWidth(); } - @Override public float getHeight() { return sprites.get(0).getHeight(); } - - @Override public void translate(float dx, float dy) - { - for (Sprite sprite : sprites) { - sprite.translate(dx, dy); - } - } - - @Override public void centerOn(float cx, float cy) - { - for (Sprite sprite : sprites) { - sprite.setPosition( - (cx - (sprite.getWidth() / 2f)), - (cy - (sprite.getHeight() / 2f))); - } - } - - @Override public void setPosition(float x, float y) - { - for (Sprite sprite : sprites) { - sprite.setPosition(x, y); - } - } - - @Override public float getRotation() - { - return sprites.get(0).getRotation(); - } - - @Override public void setRotation(float rotation) - { - for (Sprite sprite : sprites) { - sprite.setRotation(rotation); - } - } - - @Override public float getScale() - { - return sprites.get(0).getScaleX(); - } - - @Override public void setScale(float scale) - { - for (Sprite sprite : sprites) { - sprite.setScale(scale); - } - } - - @Override public void setAlpha(float alpha) - { - for (Sprite sprite : sprites) { - sprite.setAlpha(alpha); - } - } - - @Override public void draw(Batch batch) - { - for (int i = 0, n = sprites.size; i < n; i++) { - if (enabled[i]) { - sprites.get(i).draw(batch); - } - } - } -} diff --git a/core/src/ch/asynk/gdx/boardgame/pieces/Piece.java b/core/src/ch/asynk/gdx/boardgame/pieces/Piece.java deleted file mode 100644 index 31ecca3..0000000 --- a/core/src/ch/asynk/gdx/boardgame/pieces/Piece.java +++ /dev/null @@ -1,56 +0,0 @@ -package ch.asynk.gdx.boardgame.pieces; - -import java.lang.Math; - -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.Sprite; -import com.badlogic.gdx.math.Vector3; - -import ch.asynk.gdx.boardgame.Drawable; -import ch.asynk.gdx.boardgame.Orientation; -import ch.asynk.gdx.boardgame.Positionable; -import ch.asynk.gdx.boardgame.Rotable; -import ch.asynk.gdx.boardgame.Scalable; -import ch.asynk.gdx.boardgame.Tile; - -public class Piece extends Sprite implements Drawable, Positionable, Rotable, Scalable -{ - public Piece(Texture texture) - { - super(texture); - } - - @Override public float getScale() - { - return getScaleX(); - } - - @Override public void centerOn(float cx, float cy) - { - setPosition((cx - (getWidth() / 2f)), (cy - (getHeight() / 2f))); - } - - public void getPosOn(Tile tile, Orientation orientation, Vector3 v) - { - v.set((tile.x - (getWidth() / 2f)), (tile.y- (getHeight() / 2f)), orientation.r()); - } - - public void setPosition(float x, float y, float r) - { - setPosition(x, y); - setRotation(r); - } - - public boolean isOn(Tile tile) - { - return ( - (Math.abs(getX() - (tile.x - (getWidth() / 2f))) < 3) && - (Math.abs(getY() - (tile.y- (getHeight() / 2f))) < 3) - ); - } - - public boolean isFacing(Orientation orientation) - { - return (Orientation.fromR(getRotation()) == orientation); - } -} diff --git a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java index a675a82..9fd6d68 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java @@ -10,7 +10,7 @@ import ch.asynk.gdx.boardgame.Camera; import ch.asynk.gdx.boardgame.Orientation; import ch.asynk.gdx.boardgame.Path; import ch.asynk.gdx.boardgame.Tile; -import ch.asynk.gdx.boardgame.pieces.Piece; +import ch.asynk.gdx.boardgame.Piece; import ch.asynk.gdx.boardgame.boards.Board; import ch.asynk.gdx.boardgame.boards.BoardFactory; import ch.asynk.gdx.boardgame.ui.Alignment; diff --git a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java index ee38fbd..613fe57 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java @@ -8,7 +8,7 @@ import com.badlogic.gdx.math.Vector2; import ch.asynk.gdx.boardgame.Camera; import ch.asynk.gdx.boardgame.Orientation; -import ch.asynk.gdx.boardgame.pieces.Piece; +import ch.asynk.gdx.boardgame.Piece; import ch.asynk.gdx.boardgame.boards.Board; import ch.asynk.gdx.boardgame.boards.BoardFactory; import ch.asynk.gdx.boardgame.ui.Alignment; -- cgit v1.1-2-g2b99