forked from romlok/godot-gdhexgrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_2d.gd
25 lines (19 loc) · 784 Bytes
/
demo_2d.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Script to attach to a node which represents a hex grid
extends Node2D
var HexGrid = preload("./HexGrid.gd").new()
@onready var highlight = $"Highlight"
@onready var area_coords = $"Highlight/AreaCoords"
@onready var hex_coords = $"Highlight/HexCoords"
func _ready():
HexGrid.hex_scale = Vector2(50, 50)
func _unhandled_input(event):
if 'position' in event:
var relative_pos = self.transform.affine_inverse() * event.position
# Display the coords used
if area_coords != null:
area_coords.text = str(relative_pos)
if hex_coords != null:
hex_coords.text = str(HexGrid.get_hex_at(relative_pos).axial_coords)
# Snap the highlight to the nearest grid cell
if highlight != null:
highlight.position = HexGrid.get_hex_center(HexGrid.get_hex_at(relative_pos))