Add functionality to automatically spawn mobs
This commit is contained in:
parent
16e6affb3c
commit
e283d03ca4
|
@ -0,0 +1,17 @@
|
|||
extends Node2D
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
|
||||
func spawn_mob():
|
||||
var new_mob = preload("res://mob.tscn").instantiate()
|
||||
(%PathFollow2D as PathFollow2D).progress_ratio = randf()
|
||||
new_mob.global_position = %PathFollow2D.global_position
|
||||
add_child(new_mob)
|
||||
|
||||
|
||||
func _on_timer_timeout():
|
||||
spawn_mob()
|
33
game.tscn
33
game.tscn
|
@ -1,11 +1,18 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://d3kqbqj714401"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://d3kqbqj714401"]
|
||||
|
||||
[ext_resource type="Script" path="res://game.gd" id="1_4hu4a"]
|
||||
[ext_resource type="PackedScene" uid="uid://ba1onw8ja6l24" path="res://player.tscn" id="1_8q3da"]
|
||||
[ext_resource type="PackedScene" uid="uid://kgt01hip1yu5" path="res://pine_tree.tscn" id="2_wk3w0"]
|
||||
[ext_resource type="PackedScene" uid="uid://gonj65d0uldf" path="res://mob.tscn" id="3_4vicn"]
|
||||
|
||||
[sub_resource type="Curve2D" id="Curve2D_3cog5"]
|
||||
_data = {
|
||||
"points": PackedVector2Array(0, 0, 0, 0, -192, -201, 0, 0, 0, 0, 2021, -198, 0, 0, 0, 0, 2023, 1229, 0, 0, 0, 0, -200, 1220, 0, 0, 0, 0, -192, -201)
|
||||
}
|
||||
point_count = 5
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
y_sort_enabled = true
|
||||
script = ExtResource("1_4hu4a")
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
layer = -1
|
||||
|
@ -17,6 +24,15 @@ offset_bottom = 1080.0
|
|||
[node name="Player" parent="." instance=ExtResource("1_8q3da")]
|
||||
position = Vector2(859, 491)
|
||||
|
||||
[node name="Path2D" type="Path2D" parent="Player"]
|
||||
position = Vector2(-858, -466)
|
||||
curve = SubResource("Curve2D_3cog5")
|
||||
|
||||
[node name="PathFollow2D" type="PathFollow2D" parent="Player/Path2D"]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2(-192, -201)
|
||||
rotation = 0.00135562
|
||||
|
||||
[node name="PineTree" parent="." instance=ExtResource("2_wk3w0")]
|
||||
position = Vector2(291, 798)
|
||||
|
||||
|
@ -35,13 +51,8 @@ position = Vector2(1349, 521)
|
|||
[node name="PineTree6" parent="." instance=ExtResource("2_wk3w0")]
|
||||
position = Vector2(1492, 530)
|
||||
|
||||
[node name="Mob" parent="." instance=ExtResource("3_4vicn")]
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
wait_time = 0.3
|
||||
autostart = true
|
||||
|
||||
[node name="Mob2" parent="." instance=ExtResource("3_4vicn")]
|
||||
position = Vector2(113, 567)
|
||||
|
||||
[node name="Mob3" parent="." instance=ExtResource("3_4vicn")]
|
||||
position = Vector2(1635, 60)
|
||||
|
||||
[node name="Mob4" parent="." instance=ExtResource("3_4vicn")]
|
||||
position = Vector2(98, 184)
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
||||
|
|
Loading…
Reference in New Issue