summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/tankontank/engine/HeadedPawn.java11
-rw-r--r--core/src/ch/asynk/tankontank/engine/Pawn.java64
2 files changed, 47 insertions, 28 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/HeadedPawn.java b/core/src/ch/asynk/tankontank/engine/HeadedPawn.java
index 3f01c72..b52c56c 100644
--- a/core/src/ch/asynk/tankontank/engine/HeadedPawn.java
+++ b/core/src/ch/asynk/tankontank/engine/HeadedPawn.java
@@ -14,9 +14,9 @@ public abstract class HeadedPawn extends Pawn
private Image head;
protected Orientation orientation;
- public HeadedPawn(TextureRegion region, TextureRegion head, TextureAtlas atlas)
+ public HeadedPawn(TextureRegion pawn, TextureRegion head, TextureAtlas overlays)
{
- super(region, atlas);
+ super(pawn, overlays);
this.head = new Image(head);
this.orientation = Orientation.KEEP;
}
@@ -35,13 +35,6 @@ public abstract class HeadedPawn extends Pawn
}
@Override
- public void translate(float dx, float dy)
- {
- super.translate(dx, dy);
- head.translate(dx, dy);
- }
-
- @Override
public void setPosition(float x, float y, float z)
{
super.setPosition(x, y);
diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java
index b85668b..b22c0ef 100644
--- a/core/src/ch/asynk/tankontank/engine/Pawn.java
+++ b/core/src/ch/asynk/tankontank/engine/Pawn.java
@@ -10,18 +10,21 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import ch.asynk.tankontank.engine.gfx.Image;
+import ch.asynk.tankontank.engine.gfx.Drawable;
import ch.asynk.tankontank.engine.gfx.StackedImages;
import ch.asynk.tankontank.engine.gfx.animations.MoveToAnimation;
import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation;
import ch.asynk.tankontank.engine.gfx.animations.AnimationSequence;
-public abstract class Pawn extends Image implements Disposable
+public abstract class Pawn implements Drawable, Disposable
{
private static final float MOVE_TIME = 0.4f;
+ private Image image;
private StackedImages overlays;
private ArrayDeque<Vector3> moves = new ArrayDeque<Vector3>();
@@ -34,12 +37,11 @@ public abstract class Pawn extends Image implements Disposable
protected Pawn()
{
- super();
}
public Pawn(TextureRegion pawn, TextureAtlas overlays)
{
- super(pawn);
+ image = new Image(pawn);
this.overlays = new StackedImages(overlays);
}
@@ -49,6 +51,17 @@ public abstract class Pawn extends Image implements Disposable
return moves.getFirst();
}
+ public Vector2 getPosAt(Vector2 center, Vector2 pos)
+ {
+ float x = (center.x - (image.getWidth() / 2f));
+ float y = (center.y - (image.getHeight() / 2f));
+ if (pos == null)
+ return new Vector2(x, y);
+ else
+ pos.set(x, y);
+ return pos;
+ }
+
public Orientation getOrientation()
{
return Orientation.fromRotation(getRotation());
@@ -123,49 +136,62 @@ public abstract class Pawn extends Image implements Disposable
return hasOverlayEnabled();
}
- @Override
- public void translate(float dx, float dy)
+ public float getX()
{
- super.translate(dx, dy);
- overlays.translate(dx, dy);
+ return image.getX();
}
- @Override
- public void centerOn(float cx, float cy)
+ public float getY()
{
- setPosition((cx - (getWidth() / 2f)), (cy - (getHeight() / 2f)));
+ return image.getY();
+ }
+
+ public float getWidth()
+ {
+ return image.getWidth();
+ }
+
+ public float getHeight()
+ {
+ return image.getHeight();
+ }
+
+ public float getRotation()
+ {
+ return image.getRotation();
}
- @Override
public void setPosition(float x, float y)
{
- super.setPosition(x, y);
+ image.setPosition(x, y);
float cx = x + (getWidth() / 2f);
float cy = y + (getHeight() / 2f);
overlays.centerOn(cx, cy);
}
- @Override
public void setPosition(float x, float y, float z)
{
- super.setPosition(x, y, z);
- float cx = x + (getWidth() / 2f);
- float cy = y + (getHeight() / 2f);
- overlays.centerOn(cx, cy);
+ setPosition(x, y);
overlays.setRotation(z);
}
@Override
+ public void dispose()
+ {
+ image.dispose();
+ }
+
+ @Override
public void draw(Batch batch)
{
- super.draw(batch);
+ image.draw(batch);
overlays.draw(batch);
}
@Override
public void drawDebug(ShapeRenderer debugShapes)
{
- super.drawDebug(debugShapes);
+ image.drawDebug(debugShapes);
overlays.drawDebug(debugShapes);
}
}