diff options
Diffstat (limited to 'Spawner.gd')
-rw-r--r-- | Spawner.gd | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Spawner.gd b/Spawner.gd new file mode 100644 index 0000000..153d9bf --- /dev/null +++ b/Spawner.gd @@ -0,0 +1,28 @@ +extends Node + +@export var asteroid : PackedScene +@export var root : Node2D +@export var player : RigidBody2D +@export var v1 : Vector2 +@export var v2 : Vector2 +@export var speed : float + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func _on_timer_timeout(): + if player != null: + var new : RigidBody2D = asteroid.instantiate() + + new.position = Vector2(randf_range(v1.x, v2.x), randf_range(v1.y, v2.y)) + new.look_at(player.position) + new.linear_velocity = Vector2(0, speed).rotated(new.rotation + deg_to_rad(-90)) + root.add_child(new) + + $"Timer".wait_time = randf_range(1, 3) + $"Timer".start() |