Skip to content

Commit 25c6ca6

Browse files
authored
Merge pull request #42 from endlessm/push-zlopztszzluo
Add deliberately-broken enemy spawner
2 parents b84e1f8 + e084f5a commit 25c6ca6

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[gd_scene load_steps=3 format=3 uid="uid://bkkta0sx62l3t"]
2+
3+
[ext_resource type="Script" uid="uid://5k8i85vjjqgp" path="res://components/spawner/spawner_broken.gd" id="1_h3ru7"]
4+
[ext_resource type="PackedScene" uid="uid://dk0xon0k7ga23" path="res://components/enemy/enemy.tscn" id="2_7irji"]
5+
6+
[node name="EnemySpawnerBroken" type="Node2D"]
7+
script = ExtResource("1_h3ru7")
8+
scene_to_spawn = ExtResource("2_7irji")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class_name SpawnerBroken
2+
extends Node2D
3+
## @experimental
4+
## Periodically spawns a scene at this node's position.
5+
##
6+
## This could be used, for example, to have a new enemy appear every few seconds.
7+
## This class is marked experimental because it seems to be buggy.
8+
9+
## Number of seconds to wait between spawning [member scene_to_spawn].
10+
@export_range(1.0, 600.0, 1.0, "suffix:s", "or_greater") var spawn_interval := 5.0
11+
12+
## Scene to spawn every [member spawn_interval] seconds.
13+
@export var scene_to_spawn: PackedScene
14+
15+
16+
func _ready() -> void:
17+
var timer := Timer.new()
18+
add_child(timer)
19+
20+
timer.timeout.connect(spawn)
21+
22+
# Convert seconds to milliseconds for timer.start() method.
23+
# FIXME: Is this correct?? It seems to spawn too fast!
24+
timer.start(spawn_interval / 1000)
25+
26+
27+
## Spawns an instance of [member scene_to_spawn] at the same position as this node, as a sibling.
28+
func spawn() -> void:
29+
var scene := scene_to_spawn.instantiate()
30+
scene.global_position = global_position
31+
get_parent().add_child(scene)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://5k8i85vjjqgp

0 commit comments

Comments
 (0)