PirateTreasureHunt/GameScene.gd

60 lines
1.6 KiB
GDScript
Raw Normal View History

2021-06-12 17:48:58 +02:00
extends Node2D
var Player
var Level
var GameCamera
var DebugLayer
var NavTarget
var DebugLabel
var DigSite
var DiggedSites = {}
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
Player = get_node("Player")
Level = get_node("Level")
GameCamera = get_node("GameCamera")
DebugLayer = get_node("DebugLayer")
NavTarget = get_node("DebugLayer/NavTarget")
DebugLabel = GameCamera.get_node("Widgets/HBoxContainer/DebugLabel")
DigSite = preload("res://DigSite.tscn")
Globals.DebugLabel = DebugLabel
Player.connect("DigSiteReached", self, "handle_dig_site_reached")
Player.connect("DigStop", self, "handle_dig_stop")
func handle_dig_site_reached(dig_grid_coords):
if not DiggedSites.has(dig_grid_coords):
print ("Starting digging at ", dig_grid_coords)
var new_digsite = DigSite.instance()
new_digsite.transform.origin = dig_grid_coords
print ("digsite world:", new_digsite.transform.origin)
Level.add_child(new_digsite)
DiggedSites[dig_grid_coords] = true
Player.start_dig()
func handle_dig_stop():
print ("Stopping digging")
func _process(delta):
Globals.ClearDebugLabel()
GameCamera.transform.origin = Player.transform.origin
func _input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
var event_world_pos = GameCamera.screenToWorld(event.position)
NavTarget.transform.origin = event_world_pos
Player.NavTarget = Globals.WorldToGridCenter(event_world_pos)
DebugLabel.text = str(event_world_pos)
if event.button_index == BUTTON_WHEEL_UP and event.pressed:
print("Wheel up")