forked from kanium/starcheese
36 lines
937 B
GDScript3
36 lines
937 B
GDScript3
|
|
extends Button
|
||
|
|
|
||
|
|
@onready var reward_spawner = get_node("/root/Main/RewardSpawner")
|
||
|
|
|
||
|
|
func _ready():
|
||
|
|
pressed.connect(on_button_pressed)
|
||
|
|
|
||
|
|
func on_button_pressed():
|
||
|
|
if reward_spawner:
|
||
|
|
var spawn_position = get_debug_spawn_position()
|
||
|
|
reward_spawner.spawn_reward_directly("asteroid", spawn_position)
|
||
|
|
else:
|
||
|
|
print("Error: RewardSpawner not found.")
|
||
|
|
|
||
|
|
disable_temporarily()
|
||
|
|
|
||
|
|
func disable_temporarily():
|
||
|
|
self.disabled = true
|
||
|
|
self.release_focus()
|
||
|
|
var timer = Timer.new()
|
||
|
|
timer.wait_time = 0.1
|
||
|
|
timer.one_shot = true
|
||
|
|
timer.timeout.connect(self.on_timeout)
|
||
|
|
add_child(timer)
|
||
|
|
timer.start()
|
||
|
|
|
||
|
|
func on_timeout():
|
||
|
|
self.disabled = false
|
||
|
|
|
||
|
|
func get_debug_spawn_position() -> Vector2:
|
||
|
|
var player = get_node_or_null("/root/Main/spaceship")
|
||
|
|
if player:
|
||
|
|
return player.global_position + Vector2(randf_range(-500, 500), randf_range(-500, 500))
|
||
|
|
else:
|
||
|
|
return Vector2(randf_range(0, get_viewport().size.x), randf_range(0, get_viewport().size.y))
|