72 lines
2.1 KiB
GDScript
72 lines
2.1 KiB
GDScript
extends Node2D
|
|
|
|
var Player
|
|
var Level
|
|
var GameCamera
|
|
var DebugLayer
|
|
var BackgroundWater
|
|
var NavTarget
|
|
var DebugLabel
|
|
var DigSite
|
|
var DiggedSites = {}
|
|
var ChestLocations = {}
|
|
|
|
|
|
# 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")
|
|
BackgroundWater = get_node("GameCamera/BackgroundWater")
|
|
DebugLabel = GameCamera.get_node("Widgets/HBoxContainer/DebugLabel")
|
|
DigSite = preload("res://DigSite.tscn")
|
|
Globals.DebugLabel = DebugLabel
|
|
ChestLocations[Vector2(3,3)] = true
|
|
|
|
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)
|
|
Player.CurrentDigGridCoords = dig_grid_coords
|
|
Player.start_dig()
|
|
|
|
|
|
func handle_dig_stop():
|
|
print ("Stopping digging")
|
|
var dig_grid_coords = Player.CurrentDigGridCoords
|
|
if dig_grid_coords == null:
|
|
print ("Error: handling stop dig but have no dig coords!")
|
|
return
|
|
|
|
var has_treasure = ChestLocations.has(dig_grid_coords)
|
|
DiggedSites[dig_grid_coords] = true
|
|
|
|
var new_digsite = DigSite.instance()
|
|
new_digsite.HasTreasure = has_treasure
|
|
new_digsite.transform.origin = Globals.GridCenterToWorldCoord(dig_grid_coords)
|
|
Level.add_child(new_digsite)
|
|
|
|
Player.CurrentDigGridCoords = null
|
|
|
|
|
|
func _process(delta):
|
|
Globals.ClearDebugLabel()
|
|
var screen_size = OS.get_window_safe_area().size
|
|
GameCamera.transform.origin = Player.transform.origin - screen_size * 0
|
|
BackgroundWater.world_offset = GameCamera.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")
|