summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/HeadedPawn.java56
-rw-r--r--core/src/ch/asynk/rustanddust/engine/gfx/Moveable.java3
-rw-r--r--core/src/ch/asynk/rustanddust/game/Factory.java30
-rw-r--r--core/src/ch/asynk/rustanddust/game/Unit.java9
4 files changed, 74 insertions, 24 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/HeadedPawn.java b/core/src/ch/asynk/rustanddust/engine/HeadedPawn.java
index 90b4371..9b4ed83 100644
--- a/core/src/ch/asynk/rustanddust/engine/HeadedPawn.java
+++ b/core/src/ch/asynk/rustanddust/engine/HeadedPawn.java
@@ -8,7 +8,9 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
public abstract class HeadedPawn extends Pawn
{
- private Sprite head;
+ private Sprite turret;
+ private Sprite body;
+ private float turretR;
protected Orientation orientation;
protected HeadedPawn()
@@ -17,10 +19,12 @@ public abstract class HeadedPawn extends Pawn
this.orientation = Orientation.KEEP;
}
- public HeadedPawn(Faction faction, AtlasRegion body, AtlasRegion head, TextureAtlas overlays)
+ public HeadedPawn(Faction faction, AtlasRegion chit, AtlasRegion body, AtlasRegion turret, TextureAtlas overlays)
{
- super(faction, body, overlays);
- this.head = new Sprite(head);
+ super(faction, chit, overlays);
+ this.body = new Sprite(body);
+ this.turret = ((turret == null) ? null : new Sprite(turret));
+ this.turretR = 0f;
this.orientation = Orientation.KEEP;
this.descr += " " + orientation;
}
@@ -32,10 +36,17 @@ public abstract class HeadedPawn extends Pawn
}
@Override
+ public boolean canAim()
+ {
+ return (turret != null);
+ }
+
+ @Override
public void setAlpha(float alpha)
{
super.setAlpha(alpha);
- head.setAlpha(alpha);
+ body.setAlpha(alpha);
+ if (canAim()) turret.setAlpha(alpha);
}
@Override
@@ -51,23 +62,40 @@ public abstract class HeadedPawn extends Pawn
}
@Override
+ public float getTurretRotation()
+ {
+ return turretR;
+ }
+
+ @Override
public void setPosition(float x, float y)
{
super.setPosition(x, y);
float cx = x + (getWidth() / 2f);
float cy = y + (getHeight() / 2f);
- head.setPosition((cx - (head.getWidth() / 2f)), (cy - (head.getHeight() / 2f)));
+ body.setPosition((cx - (body.getWidth() / 2f)), (cy - (body.getHeight() / 2f)));
+ if (canAim()) turret.setPosition((cx - (turret.getWidth() / 2f)), (cy - (turret.getHeight() / 2f)));
}
@Override
public void setRotation(float z)
{
getPosition().z = z;
- head.setRotation(z);
+ body.setRotation(z);
+ if (canAim()) turret.setRotation(z + turretR);
this.orientation = Orientation.fromRotation(z);
}
@Override
+ public void setTurretRotation(float r)
+ {
+ if (canAim()) {
+ turretR = r;
+ turret.setRotation(body.getRotation() + turretR);
+ }
+ }
+
+ @Override
public void setPosition(float x, float y, float z)
{
setPosition(x, y);
@@ -78,7 +106,8 @@ public abstract class HeadedPawn extends Pawn
public void draw(Batch batch)
{
sprite.draw(batch);
- head.draw(batch);
+ body.draw(batch);
+ if (canAim()) turret.draw(batch);
overlays.draw(batch);
}
@@ -88,9 +117,14 @@ public abstract class HeadedPawn extends Pawn
float w = sprite.getWidth();
float h = sprite.getHeight();
debugShapes.rect(sprite.getX(), sprite.getY(), (w / 2f), (h / 2f), w, h, sprite.getScaleX(), sprite.getScaleY(), sprite.getRotation());
- w = head.getWidth();
- h = head.getHeight();
- debugShapes.rect(head.getX(), head.getY(), (w / 2f), (h / 2f), w, h, head.getScaleX(), head.getScaleY(), head.getRotation());
+ w = body.getWidth();
+ h = body.getHeight();
+ debugShapes.rect(body.getX(), body.getY(), (w / 2f), (h / 2f), w, h, body.getScaleX(), body.getScaleY(), body.getRotation());
+ if (canAim()) {
+ w = turret.getWidth();
+ h = turret.getHeight();
+ debugShapes.rect(turret.getX(), turret.getY(), (w / 2f), (h / 2f), w, h, turret.getScaleX(), turret.getScaleY(), turret.getRotation());
+ }
overlays.drawDebug(debugShapes);
}
}
diff --git a/core/src/ch/asynk/rustanddust/engine/gfx/Moveable.java b/core/src/ch/asynk/rustanddust/engine/gfx/Moveable.java
index e8790ab..b3f3541 100644
--- a/core/src/ch/asynk/rustanddust/engine/gfx/Moveable.java
+++ b/core/src/ch/asynk/rustanddust/engine/gfx/Moveable.java
@@ -5,12 +5,15 @@ import ch.asynk.rustanddust.engine.Faction;
public interface Moveable extends Drawable
{
public void setAlpha(float alpha);
+ public boolean canAim();
public float getX();
public float getY();
public float getWidth();
public float getHeight();
public float getRotation();
+ public float getTurretRotation();
public void setPosition(float x, float y);
public void setPosition(float x, float y, float r);
+ public void setTurretRotation(float r);
public Faction getFaction();
}
diff --git a/core/src/ch/asynk/rustanddust/game/Factory.java b/core/src/ch/asynk/rustanddust/game/Factory.java
index d65edd9..fbcd658 100644
--- a/core/src/ch/asynk/rustanddust/game/Factory.java
+++ b/core/src/ch/asynk/rustanddust/game/Factory.java
@@ -161,17 +161,12 @@ public class Factory implements Board.TileBuilder, Disposable
return u;
}
- private Unit buildUnit(Army army, UnitId id, UnitType ut, boolean hq, boolean ace, int a, int d, int cd, int m, String body)
+ private Unit buildUnit(Army army, UnitId id, UnitType ut, boolean hq, boolean ace, int a, int d, int cd, int m, String chit)
{
- return new Unit(army, id, ut, hq, ace, a, d, cd, m, getUnitRegion(body), getHead(army, body), unitOverlaysAtlas);
+ return new Unit(army, id, ut, hq, ace, a, d, cd, m, getUnitRegion(chit), getBody(army, chit), getTurret(army, chit), unitOverlaysAtlas);
}
- private AtlasRegion getUnitRegion(String s)
- {
- return unitsAtlas.findRegion(s);
- }
-
- private AtlasRegion getHead(Army army, String body)
+ private AtlasRegion getBody(Army army, String chit)
{
String head = null;
switch(game.config.graphics) {
@@ -179,12 +174,29 @@ public class Factory implements Board.TileBuilder, Disposable
head = ((army == Army.US) ? "us-head" : "ge-head");
break;
case TANKS:
- head = body + "-head";
+ head = chit + "-head";
break;
}
return getUnitRegion(head);
}
+ private AtlasRegion getTurret(Army army, String chit)
+ {
+ String turret = null;
+ switch(game.config.graphics) {
+ case CHITS:
+ break;
+ case TANKS:
+ break;
+ }
+ return getUnitRegion(turret);
+ }
+
+ private AtlasRegion getUnitRegion(String s)
+ {
+ return ((s == null) ? null : unitsAtlas.findRegion(s));
+ }
+
public Hex getNewTile(float x, float y, int col, int row, boolean offmap)
{
Hex hex = new Hex(x, y, col, row, hexOverlaysAtlas, Army.NONE);
diff --git a/core/src/ch/asynk/rustanddust/game/Unit.java b/core/src/ch/asynk/rustanddust/game/Unit.java
index 0027a18..a006fb9 100644
--- a/core/src/ch/asynk/rustanddust/game/Unit.java
+++ b/core/src/ch/asynk/rustanddust/game/Unit.java
@@ -64,9 +64,9 @@ public class Unit extends HeadedPawn
private boolean hasMoved;
private boolean hasFired;
- protected Unit(Army army, AtlasRegion body, AtlasRegion head, TextureAtlas overlays)
+ protected Unit(Army army, AtlasRegion chit, AtlasRegion body, AtlasRegion turret, TextureAtlas overlays)
{
- super(army, body, head, overlays);
+ super(army, chit, body, turret, overlays);
hq = false;
ace = false;
@@ -90,9 +90,10 @@ public class Unit extends HeadedPawn
this.descr = id.toString() + (hq ? " HQ " : "") + (ace ? " Ace " : "") + " (" + rng + "-" + def + "/" + cdef + "-" + mp + ")";
}
- public Unit(Army army, UnitId id, UnitType type, boolean hq, boolean ace, int range, int defense, int concealedDefense, int movementPoints, AtlasRegion body, AtlasRegion head, TextureAtlas overlays)
+ public Unit(Army army, UnitId id, UnitType type, boolean hq, boolean ace, int range, int defense, int concealedDefense, int movementPoints,
+ AtlasRegion chit, AtlasRegion body, AtlasRegion turret, TextureAtlas overlays)
{
- this(army, body, head, overlays);
+ this(army, chit, body, turret, overlays);
this.hq = hq;
this.ace = ace;
this.rng = range;