TODO: Fix UI Button reaching 0 not greying out, fix state behaviour for selected tiles
This commit is contained in:
parent
b9df0b4361
commit
5b79dc9822
9 changed files with 325 additions and 95 deletions
|
|
@ -1,5 +1,5 @@
|
|||
extends Resource
|
||||
class_name MovementBehaviour
|
||||
|
||||
func get_available_spaces(pos: Vector2i, map: HexGrid) -> Array[Vector2i]:
|
||||
func get_available_spaces(pos: HexGrid.CubeCoordinates, map: HexGrid) -> Array[HexGrid.CubeCoordinates]:
|
||||
return []
|
||||
|
|
|
|||
|
|
@ -1,35 +1,35 @@
|
|||
extends MovementBehaviour
|
||||
class_name MovementBehaviourBee
|
||||
|
||||
func can_reach(start: Vector2i, target: Vector2i, map: HexGrid) -> bool:
|
||||
func can_reach(start: HexGrid.CubeCoordinates, target: HexGrid.CubeCoordinates, map: HexGrid) -> bool:
|
||||
# if we have 5 potential spaces it can never be blocked
|
||||
var cubepos: HexGrid.CubeCoordinates = map.axial_to_cube(HexGrid.AxialCoordinates.new(start.x, start.y))
|
||||
var cubecoord = map.axial_to_cube(HexGrid.AxialCoordinates.new(target.x, target.y))
|
||||
var cubepos: HexGrid.CubeCoordinates = start
|
||||
var cubecoord: HexGrid.CubeCoordinates = target
|
||||
|
||||
var cubetest: HexGrid.CubeCoordinates = map.axial_to_cube(HexGrid.AxialCoordinates.new(0, 0))
|
||||
var cubetest: HexGrid.CubeCoordinates = HexGrid.CubeCoordinates.new(0, 0, 0)
|
||||
|
||||
cubetest.q = cubecoord.q - cubepos.q
|
||||
cubetest.r = cubecoord.r - cubepos.r
|
||||
cubetest.s = cubecoord.s - cubepos.s
|
||||
|
||||
var left = get_left_neighbour(Vector3i(cubetest.q, cubetest.r, cubetest.s))
|
||||
var right = get_right_neighbour(Vector3i(cubetest.q, cubetest.r, cubetest.s))
|
||||
var left = get_left_neighbour(cubetest)
|
||||
var right = get_right_neighbour(cubetest)
|
||||
|
||||
var left_coord = map.cube_to_axial(HexGrid.CubeCoordinates.new(left.x + cubepos.q, left.y + cubepos.r, left.z + cubepos.s))
|
||||
var right_coord = map.cube_to_axial(HexGrid.CubeCoordinates.new(right.x + cubepos.q, right.y + cubepos.r, right.z + cubepos.s))
|
||||
var left_coord = HexGrid.CubeCoordinates.new(left.q + cubepos.q, left.r + cubepos.r, left.s + cubepos.s)
|
||||
var right_coord = HexGrid.CubeCoordinates.new(right.q + cubepos.q, right.r + cubepos.r, right.s + cubepos.s)
|
||||
|
||||
return map.is_cell_empty(Vector2i(left_coord.q, left_coord.r)) or map.is_cell_empty(Vector2i(right_coord.q, right_coord.r))
|
||||
return map.is_cell_empty(left_coord) or map.is_cell_empty(right_coord)
|
||||
|
||||
func get_left_neighbour(pos: Vector3i) -> Vector3i:
|
||||
return Vector3(-pos.z, -pos.x, -pos.y)
|
||||
func get_left_neighbour(pos: HexGrid.CubeCoordinates) -> HexGrid.CubeCoordinates:
|
||||
return HexGrid.CubeCoordinates.new(-pos.s, -pos.q, -pos.r)
|
||||
|
||||
func get_right_neighbour(pos: Vector3i) -> Vector3i:
|
||||
return Vector3(-pos.y, -pos.z, -pos.x)
|
||||
func get_right_neighbour(pos: HexGrid.CubeCoordinates) -> HexGrid.CubeCoordinates:
|
||||
return HexGrid.CubeCoordinates.new(-pos.r, -pos.s, -pos.q)
|
||||
|
||||
func get_available_spaces(pos: Vector2i, map: HexGrid) -> Array[Vector2i]:
|
||||
func get_available_spaces(pos: HexGrid.CubeCoordinates, map: HexGrid) -> Array[HexGrid.CubeCoordinates]:
|
||||
var potential_spaces = map.get_empty_neighbours(pos)
|
||||
|
||||
var target_spaces: Array[Vector2i] = []
|
||||
var target_spaces: Array[HexGrid.CubeCoordinates] = []
|
||||
|
||||
for neighbour in potential_spaces:
|
||||
if can_reach(pos, neighbour, map):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue