summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java24
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java25
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java3
3 files changed, 52 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index 440f38b..871f9e8 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -348,6 +348,25 @@ public abstract class Board implements Disposable
return areaPoints;
}
+ public List<GridPoint2> lineOfSight(int col0, int row0, int col1, int row1)
+ {
+ for (GridPoint2 p : areaPoints)
+ gridPoint2Pool.free(p);
+ areaPoints.clear();
+
+ for (SearchBoard.Node node : searchBoard.lineOfSight(col0, row0, col1, row1)) {
+ GridPoint2 point = gridPoint2Pool.obtain();
+ if (point != null) {
+ point.set(node.col, node.row);
+ areaPoints.add(point);
+ } else {
+ System.err.println("null point");
+ }
+ }
+
+ return areaPoints;
+ }
+
public void disableOverlaysOn(int col, int row)
{
disableOverlaysOn(getTile(col, row));
@@ -413,6 +432,11 @@ public abstract class Board implements Disposable
return n;
}
+ public Vector2 getTileCenter(int col, int row)
+ {
+ return getTile(col, row).getCenter();
+ }
+
public Vector2 getPawnPosAt(Pawn pawn, GridPoint2 tile)
{
return getPawnPosAt(pawn, tile.x, tile.y);
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index 0406b6d..5a5f5b0 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -2,7 +2,9 @@ package ch.asynk.tankontank.game;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.GridPoint2;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import ch.asynk.tankontank.engine.Board;
import ch.asynk.tankontank.engine.Pawn;
@@ -15,6 +17,9 @@ public abstract class Map extends Board
private Pawn currentPawn;
private GridPoint2 currentHex = new GridPoint2(-1, -1);
+ private GridPoint2 lineHex = new GridPoint2(-1, -1);
+ private Vector2 line0 = new Vector2(0, 0);
+ private Vector2 line1 = new Vector2(0, 0);
protected abstract void setup();
@@ -42,6 +47,7 @@ public abstract class Map extends Board
if (currentHex.x != -1) {
currentPawn = removeTopPawnFrom(currentHex);
if (currentPawn != null) pawnsToDraw.add(currentPawn);
+ line0 = getTileCenter(currentHex.x, currentHex.y);
}
}
@@ -71,6 +77,25 @@ public abstract class Map extends Board
enableOverlayOn(hex.x, hex.y, Hex.RED, true);
}
+ public void lineOfSight(float x, float y)
+ {
+ getHexAt(lineHex, x, y);
+ line1 = getTileCenter(lineHex.x, lineHex.y);
+
+ for(GridPoint2 hex : areaPoints)
+ enableOverlayOn(hex.x, hex.y, Hex.RED, false);
+
+ for(GridPoint2 hex : lineOfSight(currentHex.x, currentHex.y, lineHex.x, lineHex.y))
+ enableOverlayOn(hex.x, hex.y, Hex.RED, true);
+ }
+
+ @Override
+ public void drawDebug(ShapeRenderer debugShapes)
+ {
+ super.drawDebug(debugShapes);
+ debugShapes.line(line0.x, line0.y, line1.x, line1.y);
+ }
+
private void debugMap()
{
int o = Hex.FOG;
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index 1f4e986..6a0c715 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -156,6 +156,9 @@ public class GameScreen implements Screen
} else if (button == Input.Buttons.RIGHT) {
cam.unproject(touchPos.set(x, y, 0));
map.showMoves(touchPos.x, touchPos.y);
+ } else {
+ cam.unproject(touchPos.set(x, y, 0));
+ map.lineOfSight(touchPos.x, touchPos.y);
}
return true;
}