27 lines
811 B
GDScript
27 lines
811 B
GDScript
extends Node2D
|
|
|
|
func _ready() -> void:
|
|
randomize()
|
|
var keyscene = load("res://Star/Star.tscn")
|
|
var keyspawns = get_tree().get_nodes_in_group("KeySpawners")
|
|
for keyspawn in keyspawns:
|
|
var key = keyscene.instance()
|
|
key.position = random_position(keyspawn)
|
|
add_child(key)
|
|
|
|
|
|
static func random_position(area: CollisionShape2D) -> Vector2:
|
|
var _topleft : Vector2 = area.global_position - area.shape.extents
|
|
var _botright : Vector2 = area.global_position + area.shape.extents
|
|
var _x = rand_range(_topleft.x, _botright.x)
|
|
var _y = rand_range(_topleft.y, _botright.y)
|
|
return Vector2(_x, _y)
|
|
|
|
|
|
|
|
func _on_HazardTimer_timeout() -> void:
|
|
var poison_scene = load("res://Hazards/Poison/Poison.tscn")
|
|
var poison = poison_scene.instance()
|
|
add_child(poison)
|
|
poison.position = random_position($HazardSpawner)
|