summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-15 21:49:09 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-15 21:49:09 +0200
commitc09dc7241937b13904207e5ed7a60fcbfd2a82c1 (patch)
treef6693287cd295f785425dc7d865baf09c3a48905 /core
parent2eb47f999c19b9274c511ca6898d8db56b253286 (diff)
downloadRustAndDust-c09dc7241937b13904207e5ed7a60fcbfd2a82c1.zip
RustAndDust-c09dc7241937b13904207e5ed7a60fcbfd2a82c1.tar.gz
actors/Tile -> actors/Pawn
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/actors/HexMap.java57
-rw-r--r--core/src/ch/asynk/tankontank/actors/Pawn.java (renamed from core/src/ch/asynk/tankontank/actors/Tile.java)43
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java17
3 files changed, 60 insertions, 57 deletions
diff --git a/core/src/ch/asynk/tankontank/actors/HexMap.java b/core/src/ch/asynk/tankontank/actors/HexMap.java
index f5ac9ba..722f5c7 100644
--- a/core/src/ch/asynk/tankontank/actors/HexMap.java
+++ b/core/src/ch/asynk/tankontank/actors/HexMap.java
@@ -24,7 +24,7 @@ public class HexMap extends Image
private int cols;
private int rows;
- private ArrayDeque<Tile>[][] cells;
+ private ArrayDeque<Pawn>[][] cells;
@SuppressWarnings("unchecked")
public HexMap(int cols, int rows, Texture texture)
@@ -39,15 +39,15 @@ public class HexMap extends Image
this.rows = rows - 1;
}
- public Tile getTopTileAt(GridPoint2 cell)
+ public Pawn getTopPawnAt(GridPoint2 cell)
{
- return getTopTileAt(cell.x, cell.y);
+ return getTopPawnAt(cell.x, cell.y);
}
- private Tile getTopTileAt(int col, int row)
+ private Pawn getTopPawnAt(int col, int row)
{
if ((col < 0) || (row < 0)) return null;
- ArrayDeque<Tile> st = cells[row][col];
+ ArrayDeque<Pawn> st = cells[row][col];
if ((st == null) || (st.size() == 0)) return null;
return st.getFirst();
}
@@ -60,48 +60,53 @@ public class HexMap extends Image
image.setCenterPosition(x, y);
}
- public Vector2 getTilePosAt(Tile tile, GridPoint3 cell)
+ // public Vector2 getPawnPosAt(Pawn pawn, GridPoint2 cell)
+ // {
+ // return getPawnPosAt(pawn, cell.x, cell.y);
+ // }
+
+ public Vector2 getPawnPosAt(Pawn pawn, GridPoint3 cell)
{
- return getTilePosAt(tile, cell.x, cell.y);
+ return getPawnPosAt(pawn, cell.x, cell.y);
}
- private Vector2 getTilePosAt(Tile tile, int col, int row)
+ private Vector2 getPawnPosAt(Pawn pawn, int col, int row)
{
- float x = x0 + ((col * w) + ((w - tile.getHeight()) / 2));
- float y = y0 + ((row * H) + ((h - tile.getWidth()) / 2));
+ float x = x0 + ((col * w) + ((w - pawn.getHeight()) / 2));
+ float y = y0 + ((row * H) + ((h - pawn.getWidth()) / 2));
if ((row % 2) == 1) x += dw;
return new Vector2(x, y);
}
- private void removeTileFrom(Tile tile, int col, int row)
+ private void removePawnFrom(Pawn pawn, int col, int row)
{
if ((col> 0) && (row > 0)) {
- ArrayDeque<Tile> st = cells[row][col];
+ ArrayDeque<Pawn> st = cells[row][col];
if ((st == null) || (st.size() == 0))
- Gdx.app.error("GameScreen", "remove tile from " + col + ";" + row + " but tile stack is empty");
+ Gdx.app.error("GameScreen", "remove pawn from " + col + ";" + row + " but pawn stack is empty");
else
- st.remove(tile);
+ st.remove(pawn);
}
}
- public void setTileOn(Tile tile, GridPoint3 cell)
+ public void setPawnOn(Pawn pawn, GridPoint3 cell)
{
- setTileOn(tile, cell.x, cell.y, cell.z);
+ setPawnOn(pawn, cell.x, cell.y, cell.z);
}
- private void setTileOn(Tile tile, int col, int row, int angle)
+ private void setPawnOn(Pawn pawn, int col, int row, int angle)
{
- GridPoint3 prev = tile.cell;
- if (prev != null) removeTileFrom(tile, prev.x, prev.y);
+ GridPoint3 prev = pawn.getHex();
+ if (prev != null) removePawnFrom(pawn, prev.x, prev.y);
- Vector2 pos = getTilePosAt(tile, col, row);
- tile.setPosition(pos.x, pos.y);
- tile.setRotation(angle);
+ Vector2 pos = getPawnPosAt(pawn, col, row);
+ pawn.setPosition(pos.x, pos.y);
+ pawn.setRotation(angle);
- ArrayDeque<Tile> st = cells[row][col];
- if (st == null) st = cells[row][col] = new ArrayDeque<Tile>();
- st.push(tile);
- tile.setZIndex(st.size());
+ ArrayDeque<Pawn> st = cells[row][col];
+ if (st == null) st = cells[row][col] = new ArrayDeque<Pawn>();
+ st.push(pawn);
+ pawn.setZIndex(st.size());
}
public GridPoint2 getCellAt(GridPoint2 cell, float cx, float cy)
diff --git a/core/src/ch/asynk/tankontank/actors/Tile.java b/core/src/ch/asynk/tankontank/actors/Pawn.java
index dbc2da0..b33e049 100644
--- a/core/src/ch/asynk/tankontank/actors/Tile.java
+++ b/core/src/ch/asynk/tankontank/actors/Pawn.java
@@ -8,34 +8,33 @@ import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.GridPoint3;
-public class Tile extends Image
+public class Pawn extends Image
{
public static final int DRAGGED_Z_INDEX = 10;
private static final float MOVE_TIME = 0.3f;
- public GridPoint3 cell = new GridPoint3(-1, -1, 0);
-
private HexMap map;
private ArrayDeque<GridPoint3> path = new ArrayDeque<GridPoint3>();
- public Tile(TextureRegion region, HexMap map)
+ public Pawn(TextureRegion region, HexMap map)
{
super(region);
this.map = map;
setOrigin((getWidth() / 2.f), (getHeight() / 2.f));
}
- public void setRotation(int angle)
+ public GridPoint3 getHex()
{
- super.setRotation(angle);
- cell.z = angle;
+ if (path.size() == 0) return null;
+ return path.getFirst();
}
- public void moveTo(int col, int row)
+ public void moveTo(GridPoint2 hex)
{
- moveTo(new GridPoint3(col, row, cell.z));
+ moveTo(new GridPoint3(hex.x, hex.y, (int) getRotation()));
}
public void moveTo(int col, int row, int angle)
@@ -43,44 +42,42 @@ public class Tile extends Image
moveTo(new GridPoint3(col, row, angle));
}
- private void moveTo(GridPoint3 nextCell)
+ private void moveTo(GridPoint3 hex)
{
- if ((nextCell.x == -1) || (nextCell.y == -1)) {
+ if ((hex.x == -1) || (hex.y == -1)) {
resetMoves();
} else {
- map.setTileOn(this, nextCell);
- path.push(nextCell);
- cell = nextCell;
+ map.setPawnOn(this, hex);
+ path.push(hex);
}
}
public void resetMoves()
{
- final Tile self = this;
- final GridPoint3 finalPos = path.getLast();
+ final Pawn self = this;
+ final GridPoint3 finalHex = path.getLast();
SequenceAction seq = new SequenceAction();
while(path.size() != 0) {
- Vector2 v = map.getTilePosAt(this, path.pop());
+ Vector2 v = map.getPawnPosAt(this, path.pop());
seq.addAction(Actions.moveTo(v.x, v.y, MOVE_TIME));
}
seq.addAction( Actions.run(new Runnable() {
@Override
public void run() {
- map.setTileOn(self, finalPos);
- path.push(finalPos);
- cell = finalPos;
+ map.setPawnOn(self, finalHex);
+ path.push(finalHex);
}
}));
addAction(seq);
}
- public void done()
+ public void moveDone()
{
- GridPoint3 p = path.pop();
+ GridPoint3 hex = path.pop();
path.clear();
- path.push(p);
+ path.push(hex);
}
}
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index c4d06be..8f05039 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -25,7 +25,7 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import ch.asynk.tankontank.TankOnTank;
-import ch.asynk.tankontank.actors.Tile;
+import ch.asynk.tankontank.actors.Pawn;
import ch.asynk.tankontank.actors.HexMap;
public class GameScreen extends AbstractScreen
@@ -49,7 +49,7 @@ public class GameScreen extends AbstractScreen
private Vector3 touchPos = new Vector3(); // world coordinates
private Vector2 dragPos = new Vector2(); // screen coordinates
- private Tile draggedTile = null;
+ private Pawn draggedPawn = null;
private GridPoint2 cell = new GridPoint2(-1, -1); // current map cell
public GameScreen(final TankOnTank game)
@@ -103,14 +103,15 @@ public class GameScreen extends AbstractScreen
float deltaX = ((x - dragPos.x) * cam.zoom * screenToViewport.x);
float deltaY = ((dragPos.y - y) * cam.zoom * screenToViewport.y);
dragPos.set(x, y);
- if (draggedTile == null) {
+ if (draggedPawn == null) {
cam.translate(-deltaX, -deltaY, 0);
clampCameraPos();
} else {
- draggedTile.moveBy(deltaX, deltaY);
+ draggedPawn.moveBy(deltaX, deltaY);
cam.unproject(touchPos.set(x, y, 0));
map.getCellAt(cell, touchPos.x, touchPos.y);
map.setImageCenterAt(selectedHex, cell);
+
}
return true;
}
@@ -121,8 +122,8 @@ public class GameScreen extends AbstractScreen
dragPos.set(x, y);
cam.unproject(touchPos.set(x, y, 0));
map.getCellAt(cell, touchPos.x, touchPos.y);
- draggedTile = map.getTopTileAt(cell);
- if (draggedTile != null) draggedTile.setZIndex(Tile.DRAGGED_Z_INDEX);
+ draggedPawn = map.getTopPawnAt(cell);
+ if (draggedPawn != null) draggedPawn.setZIndex(Pawn.DRAGGED_Z_INDEX);
map.setImageCenterAt(selectedHex, cell);
selectedHex.setVisible(true);
}
@@ -133,9 +134,9 @@ public class GameScreen extends AbstractScreen
{
if (button == Input.Buttons.LEFT) {
cam.unproject(touchPos.set(x, y, 0));
- if (draggedTile != null) {
+ if (draggedPawn != null) {
map.getCellAt(cell, touchPos.x, touchPos.y);
- draggedTile.moveTo(cell.x, cell.y);
+ draggedPawn.moveTo(cell);
}
selectedHex.setVisible(false);
}