summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--android/assets/images/hex.pngbin0 -> 31816 bytes
-rw-r--r--core/src/ch/asynk/tankontank/TankOnTank.java2
-rw-r--r--core/src/ch/asynk/tankontank/actors/HexMap.java8
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java11
4 files changed, 21 insertions, 0 deletions
diff --git a/android/assets/images/hex.png b/android/assets/images/hex.png
new file mode 100644
index 0000000..202f27f
--- /dev/null
+++ b/android/assets/images/hex.png
Binary files differ
diff --git a/core/src/ch/asynk/tankontank/TankOnTank.java b/core/src/ch/asynk/tankontank/TankOnTank.java
index 45e7cf1..8083534 100644
--- a/core/src/ch/asynk/tankontank/TankOnTank.java
+++ b/core/src/ch/asynk/tankontank/TankOnTank.java
@@ -36,6 +36,7 @@ public class TankOnTank extends Game
manager.load("images/counters.pack", TextureAtlas.class);
manager.load("images/ge.pack", TextureAtlas.class);
manager.load("images/us.pack", TextureAtlas.class);
+ manager.load("images/hex.png", Texture.class);
// manager.load("images/cup.jpg", Texture.class);
// manager.load("images/small.png", Texture.class);
}
@@ -49,6 +50,7 @@ public class TankOnTank extends Game
manager.unload("images/counters.pack");
manager.unload("images/ge.pack");
manager.unload("images/us.pack");
+ manager.unload("images/hex.png");
// manager.unload("images/cup.jpg");
// manager.unload("images/small.png");
}
diff --git a/core/src/ch/asynk/tankontank/actors/HexMap.java b/core/src/ch/asynk/tankontank/actors/HexMap.java
index 801ae2c..f5ac9ba 100644
--- a/core/src/ch/asynk/tankontank/actors/HexMap.java
+++ b/core/src/ch/asynk/tankontank/actors/HexMap.java
@@ -52,6 +52,14 @@ public class HexMap extends Image
return st.getFirst();
}
+ public void setImageCenterAt(Image image, GridPoint2 cell)
+ {
+ float x = x0 + ((cell.x * w) + (w / 2));
+ float y = y0 + ((cell.y * H) + (h / 2));
+ if ((cell.y % 2) == 1) x += dw;
+ image.setCenterPosition(x, y);
+ }
+
public Vector2 getTilePosAt(Tile tile, GridPoint3 cell)
{
return getTilePosAt(tile, cell.x, cell.y);
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index e550357..f059c08 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -14,6 +14,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Stage;
+import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.math.GridPoint2;
@@ -37,6 +38,7 @@ public class GameScreen extends AbstractScreen
final OrthographicCamera cam;
private HexMap map;
+ private Image selectedHex;
private Label fps;
private Label camInfo;
private Label cellInfo;
@@ -63,6 +65,8 @@ public class GameScreen extends AbstractScreen
cellInfo.setPosition( 10, Gdx.graphics.getHeight() - 70);
map = new HexMap(11, 9, game.manager.get("images/map_a.png", Texture.class));
+ selectedHex = new Image(game.manager.get("images/hex.png", Texture.class));
+ selectedHex.setVisible(false);
cam = new OrthographicCamera();
cam.setToOrtho(false);
@@ -70,6 +74,7 @@ public class GameScreen extends AbstractScreen
gameStage = new Stage(new FitViewport(map.getWidth(), map.getHeight(), cam));
gameStage.addActor(map);
+ gameStage.addActor(selectedHex);
hud = new Stage(new ScreenViewport());
hud.addActor(fps);
@@ -108,6 +113,9 @@ public class GameScreen extends AbstractScreen
clampCameraPos();
} else {
draggedTile.moveBy(deltaX, deltaY);
+ cam.unproject(touchPos.set(x, y, 0));
+ map.getCellAt(cell, touchPos.x, touchPos.y);
+ map.setImageCenterAt(selectedHex, cell);
}
return true;
}
@@ -120,6 +128,8 @@ public class GameScreen extends AbstractScreen
map.getCellAt(cell, touchPos.x, touchPos.y);
draggedTile = map.getTopTileAt(cell);
if (draggedTile != null) draggedTile.setZIndex(Tile.DRAGGED_Z_INDEX);
+ map.setImageCenterAt(selectedHex, cell);
+ selectedHex.setVisible(true);
}
return true;
}
@@ -132,6 +142,7 @@ public class GameScreen extends AbstractScreen
map.getCellAt(cell, touchPos.x, touchPos.y);
draggedTile.moveTo(cell.x, cell.y);
}
+ selectedHex.setVisible(false);
}
return true;
}