GodotComponentTest/scenes/HexGrid3DTest.gd

46 lines
1.6 KiB
GDScript

extends Spatial
onready var hexgrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
onready var HexTile3D = preload("res://scenes/HexTile3D.tscn")
onready var tiles = $Tiles
onready var fps_label = $CanvasLayer/HBoxContainer/FPSLabel
onready var player_pos_label = $CanvasLayer/HBoxContainer/PlayerPos
onready var tile_pos_label = $CanvasLayer/HBoxContainer/TilePos
onready var Island = preload("res://scenes/Island.gd")
onready var player = $Player
onready var world = $World
var player_velocity = Vector3.ZERO
var player_speed = 5
var target_coordinate = Vector3.ZERO
var is_first_process = true
func _ready():
print("_ready(): ", OS.get_ticks_msec())
for node in world.get_children():
if node is Island:
node.generate()
node.connect("island_tile_selected", self, "on_island_tile_selected")
node.connect("island_tile_hover", self, "on_island_tile_hover")
func _process(_delta):
if is_first_process:
print("_process(): ", OS.get_ticks_msec())
is_first_process = false
fps_label.text = "FPS: " + str(Performance.get_monitor(Performance.TIME_FPS))
player_pos_label.text = "Pos: " + str(player.transform.origin)
# query world what is happening on
func on_island_tile_selected(island, tile):
target_coordinate = tile.global_transform.origin
player.set_movable_target(tile.global_transform.origin)
var position_error = target_coordinate - player.transform.origin
print ("clicked on tile " + str(target_coordinate) + " error: " + str(position_error))
func on_island_tile_hover(_island, tile):
tile_pos_label.text = "TilePos: " + str(tile.global_transform.origin)