extends Node const WIDTH=1024 const HEIGHT=1024 const GRID_SIZE=float(64.0) const GRID_COLOR="#000000" const SHOVEL_DURATION=1 var DebugLabel = null var HexGrid = null var HexCell = null var OceanNavGrid = null var IslandNavGrid = null var hex_size = 128 var debug_nav = false # Called when the node enters the scene tree for the first time. func _ready(): HexGrid = preload("../thirdparty/gdhexgrid/HexGrid.gd").new() HexGrid.hex_scale = Vector2(hex_size, hex_size) OceanNavGrid = preload("../thirdparty/gdhexgrid/HexGrid.gd").new() OceanNavGrid.hex_scale = Vector2(hex_size, hex_size) IslandNavGrid = preload("../thirdparty/gdhexgrid/HexGrid.gd").new() IslandNavGrid.hex_scale = Vector2(hex_size, hex_size) HexCell = preload("../thirdparty/gdhexgrid/HexCell.gd").new() HexTileDrawer.hex_scale = Vector2(hex_size, hex_size) func ClearDebugLabel(): if DebugLabel == null: return DebugLabel.text = "" func DebugLabelAdd(text): if DebugLabel == null: return DebugLabel.text = DebugLabel.text + text + "\n" func ScreenToWorld(pos: Vector2, camera: Camera2D): pos = pos - OS.get_window_safe_area().size * 0.5 return camera.offset + pos * camera.zoom func ScreenToHex(pos: Vector2, camera: Camera2D): return Globals.HexGrid.get_hex_at(ScreenToWorld(pos, camera)).axial_coords func HexToWorld(coord: Vector2): return Globals.HexGrid.get_hex_center(coord) func WorldToHex(pos: Vector2): return Globals.HexGrid.get_hex_at(pos).axial_coords func WorldToHexCenter(pos: Vector2): return Globals.HexGrid.get_hex_center(Globals.HexGrid.get_hex_at(pos).axial_coords) func WorldToScreen(pos: Vector2, camera: Camera2D): return pos * camera.zoom + camera.offset func WorldLineToHexTiles (start: Vector2, target: Vector2): var start_cell = HexCell.new_hex(WorldToHex(start)) var target_coord = WorldToHex(target) var path_cells = start_cell.line_to(target_coord) var path = [] for cell in path_cells: path.append(HexToWorld(cell.axial_coords)) return path