summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-07-09 14:52:50 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-07-09 14:52:50 +0200
commit857e8831cf4e25b487a1c390e1f32cef2ca2554d (patch)
tree4f0e21f4108fa0b63adf701f46989c43ea0b4da0
parentf33e0d721d881792720a9c4a8943d962e1cd2a5f (diff)
downloadgodot-hexgrid-857e8831cf4e25b487a1c390e1f32cef2ca2554d.zip
godot-hexgrid-857e8831cf4e25b487a1c390e1f32cef2ca2554d.tar.gz
implement adjacents()
-rw-r--r--HexBoard.gd17
-rw-r--r--README.md2
2 files changed, 18 insertions, 1 deletions
diff --git a/HexBoard.gd b/HexBoard.gd
index ce240f8..b890cc0 100644
--- a/HexBoard.gd
+++ b/HexBoard.gd
@@ -21,6 +21,7 @@ var tl : int # num of hexes in 2 consecutives rows
var tile_factory_fct : FuncRef
var angles : Dictionary
+var adjacents : Array
func configure(cols : int, rows : int, side : float, v0 : Vector2, vertical : bool) -> void:
v = vertical
@@ -90,6 +91,22 @@ func _key(x : int, y : int) -> int:
i += (int(cr.x) - 1)
return i
+func adjacents(coords : Vector2) -> Array:
+ adjacents.clear()
+ coords.x += 1
+ adjacents.append(get_tile(coords))
+ coords.y += 1
+ adjacents.append(get_tile(coords))
+ coords.x -= 1
+ adjacents.append(get_tile(coords))
+ coords.x -= 1
+ adjacents.append(get_tile(coords))
+ coords.y -= 2
+ adjacents.append(get_tile(coords))
+ coords.x += 1
+ adjacents.append(get_tile(coords))
+ return adjacents
+
func is_on_map(coords : Vector2) -> bool:
if v: return _is_on_map(int(coords.x), int(coords.y))
else: return _is_on_map(int(coords.y), int(coords.x))
diff --git a/README.md b/README.md
index cd7300d..92cfcb4 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ base map made with [gimp](https://www.gimp.org) and my plugin [hexmap](https://g
## features
- [x] Distance
- - [ ] Adjacents
+ - [x] Adjacents
- [x] Line Of Sight
- [ ] Reachable Tiles ::: BFS
- [ ] Shortest Path ::: A*