starcheese/main.gd

74 lines
1.8 KiB
GDScript3
Raw Permalink Normal View History

2024-10-03 18:12:33 +01:00
extends Node
2025-01-04 02:25:39 +01:00
signal collectible_spawned(collectible: Node)
@export var debug_spawn_distance: float = 500.0
2024-10-03 18:12:33 +01:00
func _init() -> void:
2025-01-04 02:25:39 +01:00
# Initialize subsystems
2024-10-03 18:12:33 +01:00
var node = WeaponsSystem.new()
node.set_name("WeaponsSystem")
add_child(node)
2025-01-04 02:25:39 +01:00
2024-10-03 18:12:33 +01:00
node = DefaultEventBus.new()
node.set_name("MainEventBus")
add_child(node)
2025-01-04 02:25:39 +01:00
2024-10-03 18:12:33 +01:00
node = EventScope.new()
node.set_name("InputEventScope")
add_child(node)
2025-01-04 02:25:39 +01:00
node = EventScope.new()
node.set_name("DamageEventScope")
add_child(node)
2025-01-04 02:25:39 +01:00
node = EventScope.new()
node.set_name("DestroyedEventScope")
add_child(node)
2025-01-04 02:25:39 +01:00
node = RewardSpawner.new()
node.set_name("RewardSpawner")
add_child(node)
2024-10-03 18:12:33 +01:00
func _ready() -> void:
2025-01-04 02:25:39 +01:00
print("Main node ready.")
2024-10-03 18:12:33 +01:00
2024-11-12 15:05:38 +01:00
func _process(_delta: float) -> void:
2024-10-03 18:12:33 +01:00
var actions = [
"ui_fire",
"ui_up",
"ui_down",
"ui_left",
"ui_right",
2025-01-04 02:25:39 +01:00
]
2024-10-03 18:12:33 +01:00
for action in actions:
if Input.is_action_pressed(action):
2025-01-04 02:25:39 +01:00
get_node("/root/Main/MainEventBus").publish(
get_node("/root/Main/InputEventScope"),
KeyboardInputEvent.new(action, true)
)
2024-10-03 18:12:33 +01:00
elif Input.is_action_just_released(action):
2025-01-04 02:25:39 +01:00
get_node("/root/Main/MainEventBus").publish(
get_node("/root/Main/InputEventScope"),
KeyboardInputEvent.new(action, false)
)
2025-01-04 02:25:39 +01:00
func get_debug_spawn_position() -> Vector2:
var player = get_node_or_null("spaceship")
if player:
var screen_size = get_viewport().size
var spawn_position = player.global_position + Vector2(
randf_range(-debug_spawn_distance, debug_spawn_distance),
randf_range(-debug_spawn_distance, debug_spawn_distance)
)
2025-01-04 02:25:39 +01:00
spawn_position.x = clamp(spawn_position.x, 0, screen_size.x)
spawn_position.y = clamp(spawn_position.y, 0, screen_size.y)
return spawn_position
else:
print("Warning: Player node not found. Using random position.")
return Vector2(
randf_range(0, get_viewport().size.x),
randf_range(0, get_viewport().size.y)
)