summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-15 21:25:21 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-15 21:25:21 +0200
commit402c933456df6a256e6846e9338bb940e7e229c8 (patch)
tree6feb754101586a71f535c31db107b140cdec948c /core/src/ch/asynk
parent89eff7909cc161df57a5ac0e0a126a2a2cd08237 (diff)
downloadRustAndDust-402c933456df6a256e6846e9338bb940e7e229c8.zip
RustAndDust-402c933456df6a256e6846e9338bb940e7e229c8.tar.gz
add ugly selectedHex
Diffstat (limited to 'core/src/ch/asynk')
-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
3 files changed, 21 insertions, 0 deletions
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;
}