PirateTreasureHunt/Globals.gd

47 lines
1.0 KiB
GDScript
Raw Normal View History

2021-06-12 17:48:58 +02:00
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
2021-06-28 21:51:09 +02:00
var HexGrid = null
var hex_size = 128
2021-06-12 17:48:58 +02:00
# Called when the node enters the scene tree for the first time.
func _ready():
2021-06-28 21:51:09 +02:00
HexGrid = preload("../thirdparty/gdhexgrid/HexGrid.gd").new()
HexGrid.hex_scale = Vector2(hex_size, hex_size)
# add_child(HexGrid)
HexTileDrawer.hex_scale = Vector2(hex_size, hex_size)
2021-06-12 17:48:58 +02:00
func ClearDebugLabel():
if DebugLabel == null:
return
DebugLabel.text = ""
func DebugLabelAdd(text):
if DebugLabel == null:
return
DebugLabel.text = DebugLabel.text + text + "\n"
2021-06-28 21:51:09 +02:00
func ScreenToWorld(pos: Vector2, camera: Camera2D):
pos = pos - OS.get_window_safe_area().size * 0.5
return camera.offset + pos * camera.zoom
2021-06-12 17:48:58 +02:00
2021-06-28 21:51:09 +02:00
func ScreenToHex(pos: Vector2, camera: Camera2D):
return Globals.HexGrid.get_hex_at(ScreenToWorld(pos, camera)).axial_coords
func WorldToScreen(pos: Vector2, camera: Camera2D):
return pos * camera.zoom + camera.offset