forked from kanium/starcheese
74 lines
1.8 KiB
GDScript
74 lines
1.8 KiB
GDScript
extends Node
|
|
|
|
signal collectible_spawned(collectible: Node)
|
|
|
|
@export var debug_spawn_distance: float = 500.0
|
|
|
|
func _init() -> void:
|
|
# Initialize subsystems
|
|
var node = WeaponsSystem.new()
|
|
node.set_name("WeaponsSystem")
|
|
add_child(node)
|
|
|
|
node = DefaultEventBus.new()
|
|
node.set_name("MainEventBus")
|
|
add_child(node)
|
|
|
|
node = EventScope.new()
|
|
node.set_name("InputEventScope")
|
|
add_child(node)
|
|
|
|
node = EventScope.new()
|
|
node.set_name("DamageEventScope")
|
|
add_child(node)
|
|
|
|
node = EventScope.new()
|
|
node.set_name("DestroyedEventScope")
|
|
add_child(node)
|
|
|
|
node = RewardSpawner.new()
|
|
node.set_name("RewardSpawner")
|
|
add_child(node)
|
|
|
|
func _ready() -> void:
|
|
print("Main node ready.")
|
|
|
|
func _process(_delta: float) -> void:
|
|
var actions = [
|
|
"ui_fire",
|
|
"ui_up",
|
|
"ui_down",
|
|
"ui_left",
|
|
"ui_right",
|
|
]
|
|
for action in actions:
|
|
if Input.is_action_pressed(action):
|
|
get_node("/root/Main/MainEventBus").publish(
|
|
get_node("/root/Main/InputEventScope"),
|
|
KeyboardInputEvent.new(action, true)
|
|
)
|
|
elif Input.is_action_just_released(action):
|
|
get_node("/root/Main/MainEventBus").publish(
|
|
get_node("/root/Main/InputEventScope"),
|
|
KeyboardInputEvent.new(action, false)
|
|
)
|
|
|
|
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)
|
|
)
|
|
|
|
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)
|
|
)
|