diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-09 14:52:50 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-09 14:52:50 +0200 |
commit | 857e8831cf4e25b487a1c390e1f32cef2ca2554d (patch) | |
tree | 4f0e21f4108fa0b63adf701f46989c43ea0b4da0 | |
parent | f33e0d721d881792720a9c4a8943d962e1cd2a5f (diff) | |
download | godot-hexgrid-857e8831cf4e25b487a1c390e1f32cef2ca2554d.zip godot-hexgrid-857e8831cf4e25b487a1c390e1f32cef2ca2554d.tar.gz |
implement adjacents()
-rw-r--r-- | HexBoard.gd | 17 | ||||
-rw-r--r-- | README.md | 2 |
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)) @@ -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* |