summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-14 22:38:55 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-14 22:38:55 +0200
commit97f11378f27303addd8605a50d6a014267bd58fc (patch)
tree2444b88396c0e5b26a004258cfea8ad7f620458a /core/src/ch
parent711b0193dbefbaec96859fbafa735b217f401e77 (diff)
downloadRustAndDust-97f11378f27303addd8605a50d6a014267bd58fc.zip
RustAndDust-97f11378f27303addd8605a50d6a014267bd58fc.tar.gz
GameScreen tracks the touched cell, dragNdrop tiles
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/tankontank/actors/Tile.java1
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java33
2 files changed, 30 insertions, 4 deletions
diff --git a/core/src/ch/asynk/tankontank/actors/Tile.java b/core/src/ch/asynk/tankontank/actors/Tile.java
index 42882d5..dbc2da0 100644
--- a/core/src/ch/asynk/tankontank/actors/Tile.java
+++ b/core/src/ch/asynk/tankontank/actors/Tile.java
@@ -12,6 +12,7 @@ import com.badlogic.gdx.math.GridPoint3;
public class Tile 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);
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index 5f185fe..50c46ce 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -16,6 +16,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
+import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.MathUtils;
@@ -23,6 +24,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.HexMap;
public class GameScreen extends AbstractScreen
@@ -46,6 +48,9 @@ public class GameScreen extends AbstractScreen
private Vector3 touchPos = new Vector3(); // world coordinates
private Vector2 dragPos = new Vector2(); // screen coordinates
+ private Tile draggedTile = null;
+ private GridPoint2 cell = new GridPoint2(-1, -1); // current map cell
+
public GameScreen(final TankOnTank game)
{
super(game);
@@ -92,9 +97,15 @@ public class GameScreen extends AbstractScreen
@Override
public boolean touchDragged(int x, int y, int pointer)
{
- cam.translate(((dragPos.x - x) * cam.zoom * screenToViewport.x), ((y - dragPos.y) * cam.zoom * screenToViewport.y), 0);
+ float deltaX = ((x - dragPos.x) * cam.zoom * screenToViewport.x);
+ float deltaY = ((dragPos.y - y) * cam.zoom * screenToViewport.y);
dragPos.set(x, y);
- clampCameraPos();
+ if (draggedTile == null) {
+ cam.translate(-deltaX, -deltaY, 0);
+ clampCameraPos();
+ } else {
+ draggedTile.moveBy(deltaX, deltaY);
+ }
return true;
}
@Override
@@ -103,7 +114,21 @@ public class GameScreen extends AbstractScreen
if (button == Input.Buttons.LEFT) {
dragPos.set(x, y);
cam.unproject(touchPos.set(x, y, 0));
- map.selectCell(touchPos.x, touchPos.y);
+ map.getCellAt(cell, touchPos.x, touchPos.y);
+ draggedTile = map.getTopTileAt(cell);
+ draggedTile.setZIndex(Tile.DRAGGED_Z_INDEX);
+ }
+ return true;
+ }
+ @Override
+ public boolean touchUp(int x, int y, int pointer, int button)
+ {
+ if (button == Input.Buttons.LEFT) {
+ cam.unproject(touchPos.set(x, y, 0));
+ if (draggedTile != null) {
+ map.getCellAt(cell, touchPos.x, touchPos.y);
+ draggedTile.moveTo(cell.x, cell.y);
+ }
}
return true;
}
@@ -138,7 +163,7 @@ public class GameScreen extends AbstractScreen
fps.setText("FPS: " + Gdx.graphics.getFramesPerSecond());
camInfo.setText("Camera: " + (int) cam.position.y + " ; " + (int) cam.position.y + " x " + String.format("%.2f", cam.zoom));
- cellInfo.setText("Cell: " + map.cell.x + " ; " + map.cell.y);
+ cellInfo.setText("Cell: " + cell.x + " ; " + cell.y);
gameStage.act(delta);
gameStage.draw();