diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-09-27 22:33:27 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-09-27 22:33:27 +0200 |
commit | 296f56aab97d8cf38aa04ec4d7af18b8330369a1 (patch) | |
tree | e40d5178355f770f82c31680f329a4b4df6ec19c /core/src/ch/asynk/tankontank | |
parent | 2b2e8271f44ae6e548f9e8b9844199fa179368f4 (diff) | |
download | RustAndDust-296f56aab97d8cf38aa04ec4d7af18b8330369a1.zip RustAndDust-296f56aab97d8cf38aa04ec4d7af18b8330369a1.tar.gz |
rework (Basic)Drawable into Drawable->Moveable
Diffstat (limited to 'core/src/ch/asynk/tankontank')
7 files changed, 108 insertions, 44 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java index 24a6cb8..b049b92 100644 --- a/core/src/ch/asynk/tankontank/engine/Pawn.java +++ b/core/src/ch/asynk/tankontank/engine/Pawn.java @@ -103,6 +103,19 @@ public abstract class Pawn extends Image implements Disposable } @Override + public void centerOn(float cx, float cy) + { + setPosition((cx - (getWidth() / 2f)), (cy - (getHeight() / 2f))); + } + + @Override + public void setPosition(float x, float y) + { + super.setPosition(x, y); + overlays.setPosition(x, y); + } + + @Override public void setPosition(float x, float y, float z) { super.setPosition(x, y, z); diff --git a/core/src/ch/asynk/tankontank/engine/Tile.java b/core/src/ch/asynk/tankontank/engine/Tile.java index 8e3ec93..24176f3 100644 --- a/core/src/ch/asynk/tankontank/engine/Tile.java +++ b/core/src/ch/asynk/tankontank/engine/Tile.java @@ -7,10 +7,10 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import ch.asynk.tankontank.engine.gfx.BasicDrawable; +import ch.asynk.tankontank.engine.gfx.Drawable; import ch.asynk.tankontank.engine.gfx.StackedImages; -public abstract class Tile implements BasicDrawable +public abstract class Tile implements Drawable { private StackedImages overlays; protected ArrayDeque<Pawn> stack; @@ -76,13 +76,6 @@ public abstract class Tile implements BasicDrawable return mustBeDrawn(); } - @Override - public void translate(float dx, float dy) - { - overlays.translate(dx, dy); - } - - @Override public void setPosition(float x, float y, float z) { overlays.setPosition(x, y, z); diff --git a/core/src/ch/asynk/tankontank/engine/gfx/BasicDrawable.java b/core/src/ch/asynk/tankontank/engine/gfx/BasicDrawable.java deleted file mode 100644 index 2e9b3a4..0000000 --- a/core/src/ch/asynk/tankontank/engine/gfx/BasicDrawable.java +++ /dev/null @@ -1,15 +0,0 @@ -package ch.asynk.tankontank.engine.gfx; - -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; - -public interface BasicDrawable -{ - public void translate(float dx, float dy); - - public void setPosition(float x, float y, float r); - - public void draw(Batch batch); - - public void drawDebug(ShapeRenderer debugShapes); -} diff --git a/core/src/ch/asynk/tankontank/engine/gfx/Drawable.java b/core/src/ch/asynk/tankontank/engine/gfx/Drawable.java index ca749be..0338727 100644 --- a/core/src/ch/asynk/tankontank/engine/gfx/Drawable.java +++ b/core/src/ch/asynk/tankontank/engine/gfx/Drawable.java @@ -1,20 +1,11 @@ package ch.asynk.tankontank.engine.gfx; -public interface Drawable extends BasicDrawable -{ - public float getX(); - - public float getY(); - - public float getWidth(); - - public float getHeight(); +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; - public float getRotation(); - - public void setScale(float s); - - public void setRotation(float r); +public interface Drawable +{ + public void draw(Batch batch); - public void setPosition(float x, float y); + public void drawDebug(ShapeRenderer debugShapes); } diff --git a/core/src/ch/asynk/tankontank/engine/gfx/Image.java b/core/src/ch/asynk/tankontank/engine/gfx/Image.java index e408493..fcfc4c8 100644 --- a/core/src/ch/asynk/tankontank/engine/gfx/Image.java +++ b/core/src/ch/asynk/tankontank/engine/gfx/Image.java @@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -public class Image extends Sprite implements Drawable, Disposable +public class Image extends Sprite implements Moveable, Disposable { private Texture texture; @@ -36,6 +36,12 @@ public class Image extends Sprite implements Drawable, Disposable } @Override + public void centerOn(float cx, float cy) + { + setPosition((cx - (getWidth() / 2f)), (cy - (getHeight() / 2f))); + } + + @Override public void drawDebug(ShapeRenderer shapes) { shapes.rect(getX(), getY(), (getWidth() / 2f), (getHeight() / 2f), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation()); diff --git a/core/src/ch/asynk/tankontank/engine/gfx/Moveable.java b/core/src/ch/asynk/tankontank/engine/gfx/Moveable.java new file mode 100644 index 0000000..55d5364 --- /dev/null +++ b/core/src/ch/asynk/tankontank/engine/gfx/Moveable.java @@ -0,0 +1,24 @@ +package ch.asynk.tankontank.engine.gfx; + +public interface Moveable extends Drawable +{ + public float getX(); + + public float getY(); + + public float getWidth(); + + public float getHeight(); + + public float getRotation(); + + public void setRotation(float r); + + public void translate(float dx, float dy); + + public void centerOn(float cx, float cy); + + public void setPosition(float x, float y); + + public void setPosition(float x, float y, float r); +} diff --git a/core/src/ch/asynk/tankontank/engine/gfx/StackedImages.java b/core/src/ch/asynk/tankontank/engine/gfx/StackedImages.java index 077dcef..d1d2dbf 100644 --- a/core/src/ch/asynk/tankontank/engine/gfx/StackedImages.java +++ b/core/src/ch/asynk/tankontank/engine/gfx/StackedImages.java @@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.utils.Array; -public class StackedImages implements BasicDrawable +public class StackedImages implements Moveable { private boolean enabled[]; private Array<Sprite> sprites; @@ -36,11 +36,63 @@ public class StackedImages implements BasicDrawable } @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 float getRotation() + { + return sprites.get(0).getRotation(); + } + + @Override + public void setRotation(float r) + { + for (int i = 0, n = sprites.size; i < n; i++) + sprites.get(i).setRotation(r); + } + + @Override public void translate(float dx, float dy) { - for (int i = 0; i < sprites.size; i++) { + for (int i = 0, n = sprites.size; i < n; i++) sprites.get(i).translate(dx, dy); - } + } + + @Override + public void centerOn(float cx, float cy) + { + float x = (cx - (getWidth() / 2f)); + float y = (cy - (getHeight() / 2f)); + for (int i = 0, n = sprites.size; i < n; i++) + setPosition(x, y); + } + + @Override + public void setPosition(float x, float y) + { + for (int i = 0, n = sprites.size; i < n; i++) + sprites.get(i).setPosition(x, y); } @Override @@ -55,7 +107,7 @@ public class StackedImages implements BasicDrawable @Override public void draw(Batch batch) { - for (int i = 0; i < sprites.size; i++) { + for (int i = 0, n = sprites.size; i < n; i++) { if (enabled[i]) sprites.get(i).draw(batch); } |