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 /HexBoard.gd | |
parent | f33e0d721d881792720a9c4a8943d962e1cd2a5f (diff) | |
download | godot-hexgrid-857e8831cf4e25b487a1c390e1f32cef2ca2554d.zip godot-hexgrid-857e8831cf4e25b487a1c390e1f32cef2ca2554d.tar.gz |
implement adjacents()
Diffstat (limited to 'HexBoard.gd')
-rw-r--r-- | HexBoard.gd | 17 |
1 files changed, 17 insertions, 0 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)) |