From 0b47cc7b3881a77b35a870a10453408cf74487c3 Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 10 May 2026 13:52:23 +0100 Subject: [PATCH] =?UTF-8?q?My=20version=20of=20spawning=E2=80=A6spawns=20t?= =?UTF-8?q?oo=20many=20survivors!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scenes/component_spawn.gd | 42 +++++++++++++++++++++++++++++++++++ scenes/component_spawn.gd.uid | 1 + scenes/component_spawn.tscn | 10 +++++++++ scenes/game.gd | 6 +++++ scenes/game.gd.uid | 1 + scenes/game.tscn | 5 +++++ scenes/survivor.gd | 11 +++++---- scenes/world.tscn | 32 +++++++++++++++----------- 8 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 scenes/component_spawn.gd create mode 100644 scenes/component_spawn.gd.uid create mode 100644 scenes/component_spawn.tscn create mode 100644 scenes/game.gd create mode 100644 scenes/game.gd.uid diff --git a/scenes/component_spawn.gd b/scenes/component_spawn.gd new file mode 100644 index 0000000..13606c9 --- /dev/null +++ b/scenes/component_spawn.gd @@ -0,0 +1,42 @@ +extends Node3D + +var survivors: int = 5 +var survivor_rate: float = .75 +var speed_modifer: int = 0 +var spawn_readiness: bool = false + +@onready var survivor = preload("res://scenes/survivor.tscn") +@onready var world = preload("res://scenes/world.tscn") + +@onready var survivor_spawn = get_node("/root/Game/World/SuvivorSpawn") +@onready var start_pos = survivor_spawn.global_position + +func _ready() -> void: + spawn_readiness = false + +func _physics_process(delta): + if spawn_readiness == true: + spawn_survivor() + spawn_readiness = false + + else: + await get_tree().create_timer(survivor_rate).timeout + spawn_readiness = true + + +func spawn_survivor(): + + if spawn_readiness == false: pass + + else: + + var survivor_delay: float = randf_range(1, 2.5) + var s = survivor.instantiate() + + for x in range(survivors): + get_tree().root.add_child(s) + #get_node("/root/Game/World").add_child(s) + s.position = start_pos + await get_tree().create_timer(survivor_rate * survivor_delay).timeout + spawn_readiness = true + diff --git a/scenes/component_spawn.gd.uid b/scenes/component_spawn.gd.uid new file mode 100644 index 0000000..256c5e7 --- /dev/null +++ b/scenes/component_spawn.gd.uid @@ -0,0 +1 @@ +uid://dr7xg7ly6q13g diff --git a/scenes/component_spawn.tscn b/scenes/component_spawn.tscn new file mode 100644 index 0000000..0dd14c8 --- /dev/null +++ b/scenes/component_spawn.tscn @@ -0,0 +1,10 @@ +[gd_scene format=3 uid="uid://bb0o3ov6u308v"] + +[ext_resource type="Script" uid="uid://dr7xg7ly6q13g" path="res://scenes/component_spawn.gd" id="1_wr5sp"] + +[node name="Component Spawn" type="Node3D" unique_id=649225939] +script = ExtResource("1_wr5sp") + +[node name="SpawnMarker" type="Marker3D" parent="." unique_id=1293702318] +unique_name_in_owner = true +gizmo_extents = 1.15 diff --git a/scenes/game.gd b/scenes/game.gd new file mode 100644 index 0000000..af525c2 --- /dev/null +++ b/scenes/game.gd @@ -0,0 +1,6 @@ +extends Node3D + +func _ready() -> void: + $ComponentSpawn.spawn_survivor() + + diff --git a/scenes/game.gd.uid b/scenes/game.gd.uid new file mode 100644 index 0000000..3b49d0a --- /dev/null +++ b/scenes/game.gd.uid @@ -0,0 +1 @@ +uid://bo7jao24qe2o7 diff --git a/scenes/game.tscn b/scenes/game.tscn index 7fb3ba6..acb45e6 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,10 +1,13 @@ [gd_scene format=3 uid="uid://b4llhxe3hjbgv"] +[ext_resource type="Script" uid="uid://bo7jao24qe2o7" path="res://scenes/game.gd" id="1_lbhrr"] [ext_resource type="PackedScene" uid="uid://bnv1xxgceqbrc" path="res://scenes/world.tscn" id="1_uwrxv"] [ext_resource type="PackedScene" uid="uid://cbvi51vvpt7mu" path="res://scenes/hud.tscn" id="2_yqjtg"] [ext_resource type="PackedScene" uid="uid://nca1hcujxru0" path="res://scenes/elevator_panel.tscn" id="3_lnu2h"] +[ext_resource type="PackedScene" uid="uid://bb0o3ov6u308v" path="res://scenes/component_spawn.tscn" id="5_iywne"] [node name="Game" type="Node3D" unique_id=1456297160] +script = ExtResource("1_lbhrr") [node name="World" parent="." unique_id=831374579 instance=ExtResource("1_uwrxv")] @@ -15,3 +18,5 @@ [node name="CanvasPanel" type="CanvasLayer" parent="." unique_id=667193210] [node name="ElevatorPanel" parent="CanvasPanel" unique_id=574176994 instance=ExtResource("3_lnu2h")] + +[node name="ComponentSpawn" parent="." unique_id=649225939 instance=ExtResource("5_iywne")] diff --git a/scenes/survivor.gd b/scenes/survivor.gd index 345aa93..2296285 100644 --- a/scenes/survivor.gd +++ b/scenes/survivor.gd @@ -3,16 +3,19 @@ extends CharacterBody3D var speed: int = 5 var clumsiness: int = 0 +@onready var safety_zone = get_node("/root/Game/World/ElevatorDoors/ElevatorSafeZone") -func start(xform): - transform = xform - velocity = (-xform.basis.z * speed).rotated(Vector3.UP, randf_range(-PI/4, PI/4)) + +#func start(xform): + #transform = xform + #velocity = (-xform.basis.z * speed).rotated(Vector3.UP, randf_range(-PI/4, PI/4)) func _physics_process(delta): velocity.z -= speed * delta move_and_slide() func _on_area_3d_area_entered(area: Area3D) -> void: - var safety = %ElevatorSafeZone + var safety = safety_zone if area == safety: print("Safe!") + queue_free() diff --git a/scenes/world.tscn b/scenes/world.tscn index db312bf..48f9369 100644 --- a/scenes/world.tscn +++ b/scenes/world.tscn @@ -14,6 +14,10 @@ size = Vector3(9.291687, 1, 1.9597168) [node name="World" type="Node3D" unique_id=831374579] +[node name="Camera3D" parent="." unique_id=691202574 instance=ExtResource("1_f3sb7")] +transform = Transform3D(-0.9999863, 0.005235964, 8.742278e-08, 0.005235964, 0.9999863, 0, -8.7421576e-08, 4.577425e-10, -1, 0.003270626, 2.9093587, -9.910637) +fov = 90.0 + [node name="Hall" type="Node3D" parent="." unique_id=2096979798] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.10000013, 0) @@ -29,35 +33,37 @@ transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 0, 0 [node name="HallBlock0" parent="Hall" unique_id=1901572100 instance=ExtResource("1_tlwt5")] transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 0, 0, -5.4) -[node name="Camera3D" parent="." unique_id=691202574 instance=ExtResource("1_f3sb7")] -transform = Transform3D(-0.9999863, 0.005235964, 8.742278e-08, 0.005235964, 0.9999863, 0, -8.7421576e-08, 4.577425e-10, -1, 0.003270626, 2.9093587, -9.910637) -fov = 90.0 - -[node name="StaticBody3D" type="StaticBody3D" parent="." unique_id=133407620] +[node name="Enemy Placeholder" type="StaticBody3D" parent="." unique_id=133407620] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.6470537, 0, 4.4912777) -[node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody3D" unique_id=996721213] +[node name="MeshInstance3D" type="MeshInstance3D" parent="Enemy Placeholder" unique_id=996721213] transform = Transform3D(2.75, 0, 0, 0, 2.75, 0, 0, 0, 2.75, -2.6999998, 2.9387112, 3.8988447) mesh = SubResource("CapsuleMesh_tlwt5") -[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" unique_id=1517735028] +[node name="CollisionShape3D" type="CollisionShape3D" parent="Enemy Placeholder" unique_id=1517735028] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.7, 1.048, 3.899) shape = SubResource("CapsuleShape3D_aqk2v") +disabled = true -[node name="Elevator Doors" type="Node3D" parent="." unique_id=351419432] +[node name="ElevatorDoors" type="Node3D" parent="." unique_id=351419432] -[node name="ElevatorSafeZone" type="Area3D" parent="Elevator Doors" unique_id=1186678129] +[node name="ElevatorSafeZone" type="Area3D" parent="ElevatorDoors" unique_id=1186678129] unique_name_in_owner = true -[node name="CollisionShape3D" type="CollisionShape3D" parent="Elevator Doors/ElevatorSafeZone" unique_id=264489586] +[node name="CollisionShape3D" type="CollisionShape3D" parent="ElevatorDoors/ElevatorSafeZone" unique_id=264489586] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.36001587, 2.5895514, -8.097411) shape = SubResource("BoxShape3D_k0juu") -[node name="DoorLeft" parent="Elevator Doors" unique_id=1751198646 instance=ExtResource("3_k0juu")] +[node name="DoorLeft" parent="ElevatorDoors" unique_id=1751198646 instance=ExtResource("3_k0juu")] transform = Transform3D(4, 0, 0, 0, 4, 0, 0, 0, 4, 4.5, 2.9909716, -8.27242) -[node name="DoorRight" parent="Elevator Doors" unique_id=551316937 instance=ExtResource("3_k0juu")] +[node name="DoorRight" parent="ElevatorDoors" unique_id=551316937 instance=ExtResource("3_k0juu")] transform = Transform3D(-4, 0, 3.496911e-07, 0, 4, 0, -3.496911e-07, 0, -4, -4.4, 2.9909716, -8.27242) [node name="Survivor" parent="." unique_id=510103859 instance=ExtResource("3_4wyf3")] -transform = Transform3D(1.5, 0, 0, 0, 1.5, 0, 0, 0, 1.5, 1.3680804, 1.6999999, 4.7656555) +transform = Transform3D(1.5, 0, 0, 0, 1.5, 0, 0, 0, 1.5, 0.9680804, 1.8453895, 5.186021) + +[node name="SuvivorSpawn" type="Marker3D" parent="." unique_id=1095768768] +unique_name_in_owner = true +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.9181392, 13.711893) +gizmo_extents = 1.46