ld-56/main.gd

89 lines
2.6 KiB
GDScript3
Raw Normal View History

2024-10-07 05:05:27 +00:00
extends Node2D
@onready var zones = Data.data.zones
const CURSOR = preload("res://components/Cursor/Cursor.tscn")
const ZONE = preload("res://src/Zone.tscn")
2024-10-07 08:25:58 +00:00
const UI_BUTTONS = preload("res://src/UIButtons.tscn")
const PAUSE_WINDOW = preload("res://src/PauseWindow.tscn")
const BUILD_WINDOW = preload("res://src/BuildWindow.tscn")
2024-10-07 17:07:46 +00:00
const CREATURE_WINDOW = preload("res://src/CreatureWindow.tscn")
2024-10-07 08:25:58 +00:00
var build_object
2024-10-07 05:05:27 +00:00
2024-10-07 18:53:09 +00:00
@onready var upgrade_pool = Data.data.upgrades.keys()
@onready var zone_pool = Data.data.zones.keys()
2024-10-07 21:37:16 +00:00
@onready var audio_stream_player_2: AudioStreamPlayer = $AudioStreamPlayer2
@onready var audio_stream_player_3: AudioStreamPlayer = $AudioStreamPlayer3
@onready var audio_stream_player_4: AudioStreamPlayer = $AudioStreamPlayer4
2024-10-07 18:53:09 +00:00
2024-10-07 05:05:27 +00:00
func _ready() -> void:
2024-10-07 18:53:09 +00:00
Persister.persist_data("creature_resource_spawn_rate", 20)
2024-10-07 05:05:27 +00:00
Triggerer.listen("spawn_window", _on_spawn_window)
2024-10-07 08:25:58 +00:00
Triggerer.listen("upgrade_menu", _on_build_menu)
2024-10-07 05:05:27 +00:00
Triggerer.listen("quit", _on_quit)
2024-10-07 21:37:16 +00:00
Triggerer.listen("creature_sound", _on_creature_sound)
Triggerer.listen("coin_sound", _on_coin_sound)
Triggerer.listen("coin_collect_sound", _on_coin_collect_sound)
2024-10-07 05:05:27 +00:00
DisplayServer.window_set_title("Home")
get_viewport().transparent_bg = true
2024-10-07 08:25:58 +00:00
DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_MOUSE_PASSTHROUGH, true)
var new_buttons = UI_BUTTONS.instantiate()
var new_cursor = CURSOR.instantiate()
new_buttons.add_child(new_cursor)
add_child(new_buttons)
2024-10-07 05:05:27 +00:00
2024-10-07 21:37:16 +00:00
func _on_creature_sound(_data):
audio_stream_player_2.play()
func _on_coin_collect_sound(_data):
audio_stream_player_3.play()
func _on_coin_sound(_data):
audio_stream_player_4.play()
2024-10-07 05:05:27 +00:00
func _process(delta: float) -> void:
if Input.is_action_just_pressed("test"):
Triggerer.trigger("spawn_window", {"key": ["farm", "desert", "lake", "forest"].pick_random()})
func _on_spawn_window(data) -> void:
var zone = zones[data.key]
var new_window = ZONE.instantiate()
new_window.key = data.key
new_window.size = Vector2(int(zone.size[0]) * 12 * 4, int(zone.size[1]) * 12 * 4)
var new_cursor = CURSOR.instantiate()
new_window.add_child(new_cursor)
get_tree().root.add_child(new_window)
func _on_quit(_data) -> void:
get_tree().quit()
2024-10-07 08:25:58 +00:00
func _on_build_menu(data):
if data.value:
var new_window = BUILD_WINDOW.instantiate()
var new_cursor = CURSOR.instantiate()
new_window.add_child(new_cursor)
add_child(new_window)
build_object = new_window
else:
build_object.queue_free()
2024-10-07 17:07:46 +00:00
func _on_timer_timeout() -> void:
var new_window = CREATURE_WINDOW.instantiate()
var new_cursor = CURSOR.instantiate()
new_window.add_child(new_cursor)
add_child(new_window)
Triggerer.trigger("spawn_window", {"key": ["forest"].pick_random()})