diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-06-03 18:04:28 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-06-03 18:04:28 +0200 |
commit | f6800af5b9013589e305cccf5cdcfe91a3981a06 (patch) | |
tree | bb8445e2514156dbea686cc36d167786251f01df /test/src/ch/asynk | |
parent | 0d121cac76bc84eb5238140f922f3ef1782d0910 (diff) | |
download | gdx-boardgame-f6800af5b9013589e305cccf5cdcfe91a3981a06.zip gdx-boardgame-f6800af5b9013589e305cccf5cdcfe91a3981a06.tar.gz |
Tile : add distances to blockLos(…)
Diffstat (limited to 'test/src/ch/asynk')
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/HexScreen.java | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java b/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java index 1d5947c..b6c7f28 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java @@ -1,5 +1,7 @@ package ch.asynk.gdx.boardgame.test; +import com.badlogic.gdx.math.MathUtils; + import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; @@ -35,7 +37,7 @@ public class HexScreen extends AbstractScreen private enum Terrain { - WOODS, CITY, HILL, PLAIN; + WOODS(0,1), CITY(0,2), HILL(2,0), PLAIN(0,0); static private int[] cv = {23, 74}; static private int[] hv = {68, 78, 79, 15, 45, 46}; @@ -46,6 +48,13 @@ public class HexScreen extends AbstractScreen static public boolean v = true; + public int elevation; + public int height; + private Terrain(int elevation, int height) { + this.elevation = elevation; + this.height = height; + } + static public Terrain get(int k) { if (v) { @@ -89,10 +98,19 @@ public class HexScreen extends AbstractScreen this.terrain = terrain; } - @Override public boolean blockLos(final Tile from, final Tile to) + @Override public boolean blockLos(final Tile from, final Tile to, float d, float dt) { - if (terrain != Terrain.PLAIN) return true; - return false; + int h = terrain.elevation + terrain.height; + if (h == 0) return false; + + int e = ((Hex)from).terrain.elevation; + if (e > h) { + if (((Hex)to).terrain.elevation > h) return false; + return (h * dt / (e - h)) >= (d - dt); + } else { + h -= e; + return (h * d / dt) >= (((Hex)to).terrain.elevation - e); + } } public String toString() |