forked from kanium/starcheese
21 lines
627 B
GDScript
21 lines
627 B
GDScript
class_name RewardSpawner
|
|
extends Node
|
|
|
|
var event_bus: EventBus
|
|
|
|
func _ready():
|
|
event_bus = get_node("/root/Main/MainEventBus")
|
|
event_bus.subscribe_to(get_node("/root/Main/DestroyedEventScope"), "DestroyedEvent", Callable(self, "on_destroyed"))
|
|
|
|
func on_destroyed(event: DestroyedEvent):
|
|
if event.object_type == "asteroid":
|
|
spawn_cheese(event.position)
|
|
|
|
func spawn_cheese(position: Vector2):
|
|
var cheese_scene = load("res://cheese.tscn")
|
|
var cheese_instance = cheese_scene.instantiate()
|
|
|
|
cheese_instance.global_position = position + Vector2(randf() * 50 - 25, randf() * 50 - 25)
|
|
|
|
get_parent().add_child(cheese_instance)
|