summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/gdx
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-06-04 14:43:47 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-06-04 14:43:47 +0200
commit40d2fd89e130ffdee44ec1b3896a5e70484f6e6e (patch)
tree419654861bec362ce9cde07c04187d19995f320d /core/src/ch/asynk/gdx
parent98438b94388e19e68a8bb2a9673b29966d260814 (diff)
downloadgdx-boardgame-40d2fd89e130ffdee44ec1b3896a5e70484f6e6e.zip
gdx-boardgame-40d2fd89e130ffdee44ec1b3896a5e70484f6e6e.tar.gz
HexBoard : block LOS if left&right of hex sides blocked
Diffstat (limited to 'core/src/ch/asynk/gdx')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java20
1 files changed, 12 insertions, 8 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
index a0f1149..22a669d 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
@@ -363,16 +363,17 @@ public class HexBoard implements Board
Tile to = getTile(x1, y1);
float d = distance(x0, y0, x1, y1);
tiles.add(from);
+ int blocked = 0;
boolean losBlocked = false;
while ((x != x1) || (y != y1)) {
- boolean blocked = losBlocked;
y += dt; // up left
Tile t = getTile(x, y);
if (t.isOnMap()) {
tiles.add(t);
t.blocked = losBlocked;
- blocked = (blocked || t.blockLos(from, to, d, distance(x0, y0, x, y)));
+ if (t.blockLos(from, to, d, distance(x0, y0, x, y)))
+ blocked |= 0x01;
}
x += dt; // up right
@@ -380,14 +381,15 @@ public class HexBoard implements Board
if (t.isOnMap()) {
tiles.add(t);
t.blocked = losBlocked;
- blocked = (blocked && t.blockLos(from, to, d, distance(x0, y0, x, y)));
+ if (t.blockLos(from, to, d, distance(x0, y0, x, y)))
+ blocked |= 0x02;
}
y += dt; // vertical
t = getTile(x, y);
if (t.isOnMap()) {
tiles.add(t);
- t.blocked = (losBlocked || blocked);
+ t.blocked = (losBlocked || blocked == 0x03);
losBlocked = (t.blocked || t.blockLos(from, to, d, distance(x0, y0, x, y)));
}
}
@@ -409,16 +411,17 @@ public class HexBoard implements Board
Tile to = getTile(x1, y1);
float d = distance(x0, y0, x1, y1);
tiles.add(from);
+ int blocked = 0;
boolean losBlocked = false;
while ((x != x1) || (y != y1)) {
- boolean blocked = losBlocked;
x += dx; // right
Tile t = getTile(x, y);
if (t.isOnMap()) {
tiles.add(t);
t.blocked = losBlocked;
- blocked = (blocked || t.blockLos(from, to, d, distance(x0, y0, x, y)));
+ if (t.blockLos(from, to, d, distance(x0, y0, x, y)))
+ blocked |= 0x01;
}
y += dy; // up right
@@ -428,14 +431,15 @@ public class HexBoard implements Board
if (t.isOnMap()) {
tiles.add(t);
t.blocked = losBlocked;
- blocked = (blocked && t.blockLos(from, to, d, distance(x0, y0, x, y)));
+ if (t.blockLos(from, to, d, distance(x0, y0, x, y)))
+ blocked |= 0x02;
}
x += dx; // diagonal
t = getTile(x, y);
if (t.isOnMap()) {
tiles.add(t);
- t.blocked = (losBlocked || blocked);
+ t.blocked = (losBlocked || blocked == 0x03);
losBlocked = (t.blocked || t.blockLos(from, to, d, distance(x0, y0, x, y)));
}
}