Refactored to use Vector4i. Added Spider/Grasshopper. TODO: Ant
This commit is contained in:
parent
ff4aa93845
commit
11f8a71f52
19 changed files with 482 additions and 326 deletions
|
|
@ -1,2 +1,38 @@
|
|||
extends MovementBehaviour
|
||||
class_name MovementBehaviourGrasshopper
|
||||
|
||||
const DIRS = [
|
||||
Vector4i(0, -1, +1, 0), #UP
|
||||
Vector4i(-1, 0, +1, 0), #UP_LEFT
|
||||
Vector4i(-1, +1, 0, 0), #DOWN_LEFT
|
||||
Vector4i(0, +1, -1, 0), #DOWN
|
||||
Vector4i(+1, 0, -1, 0), #DOWN_RIGHT
|
||||
Vector4i(+1, -1, 0, 0), #UP_RIGHT
|
||||
]
|
||||
|
||||
func simulate_move_dirs(start: Vector4i, map: HexGrid) -> Array[Vector4i]:
|
||||
var possible: Array[Vector4i] = []
|
||||
for dir in DIRS:
|
||||
possible.push_back(simulate_move_recursive(start, dir, map))
|
||||
|
||||
return possible
|
||||
|
||||
func simulate_move_recursive(start: Vector4i, dir: Vector4i, map: HexGrid) -> Vector4i:
|
||||
var possible: Array[Vector4i] = []
|
||||
|
||||
var target: Vector4i = start + dir
|
||||
|
||||
if map.is_cell_empty(target):
|
||||
return target
|
||||
|
||||
return simulate_move_recursive(target, dir, map)
|
||||
|
||||
func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]:
|
||||
var possible_places: Array[Vector4i] = []
|
||||
|
||||
possible_places = simulate_move_dirs(pos, map)
|
||||
|
||||
for neighbour in map.get_empty_neighbours(pos):
|
||||
possible_places.erase(neighbour)
|
||||
|
||||
return possible_places
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue