spawning chests in csg boxes, working on making them root of scene so they aren't cleared with the scene on exit

This commit is contained in:
derek
2025-04-04 16:30:51 -05:00
parent 6cd06193b5
commit ce08df66e6
15 changed files with 99 additions and 76 deletions

View File

@@ -1,20 +0,0 @@
[gd_scene load_steps=4 format=3 uid="uid://db7xqf12sayj0"]
[sub_resource type="BoxMesh" id="BoxMesh_nbeyo"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_3gsvj"]
[sub_resource type="CylinderMesh" id="CylinderMesh_cbsxv"]
top_radius = 0.1
bottom_radius = 0.1
height = 1.0
[node name="ChestSpawner" type="Node3D" groups=["chest_spawner"]]
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = SubResource("BoxMesh_nbeyo")
surface_material_override/0 = SubResource("StandardMaterial3D_3gsvj")
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 1.01635)
mesh = SubResource("CylinderMesh_cbsxv")

View File

@@ -2,7 +2,7 @@
[ext_resource type="Script" uid="uid://bdecyikiye08i" path="res://scripts/die_particles.gd" id="1_frf2k"] [ext_resource type="Script" uid="uid://bdecyikiye08i" path="res://scripts/die_particles.gd" id="1_frf2k"]
[ext_resource type="AudioStream" uid="uid://wd061pl0d7rl" path="res://assets/Audio/deep-low-explosion-SBA-300054677.wav" id="2_ddmln"] [ext_resource type="AudioStream" uid="uid://wd061pl0d7rl" path="res://assets/Audio/deep-low-explosion-SBA-300054677.wav" id="2_ddmln"]
[ext_resource type="Texture2D" uid="uid://dmyn4eq2r12ue" path="res://assets/Models/spider1.albedoRAW.png" id="3_81mhs"] [ext_resource type="Texture2D" uid="uid://c6nvp1khihvhj" path="res://assets/Models/spider1.albedoRAW.png" id="3_81mhs"]
[ext_resource type="Texture2D" uid="uid://dqhke14ulten2" path="res://assets/Models/spider1.roughnessRAW.png" id="4_ahnbu"] [ext_resource type="Texture2D" uid="uid://dqhke14ulten2" path="res://assets/Models/spider1.roughnessRAW.png" id="4_ahnbu"]
[ext_resource type="Texture2D" uid="uid://b4s3w1qnqcmgq" path="res://assets/Models/spider1.gunbarrel.albedo.png" id="4_pb8pm"] [ext_resource type="Texture2D" uid="uid://b4s3w1qnqcmgq" path="res://assets/Models/spider1.gunbarrel.albedo.png" id="4_pb8pm"]
[ext_resource type="Texture2D" uid="uid://d4l5wf34qdvli" path="res://assets/Models/spider1.turret.png" id="5_hogev"] [ext_resource type="Texture2D" uid="uid://d4l5wf34qdvli" path="res://assets/Models/spider1.turret.png" id="5_hogev"]

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +1,6 @@
[gd_scene load_steps=21 format=3 uid="uid://uo43j7bomkf3"] [gd_scene load_steps=22 format=3 uid="uid://uo43j7bomkf3"]
[ext_resource type="Script" uid="uid://pm8n67yhip1p" path="res://scripts/sublevel.gd" id="1_e6kt2"]
[ext_resource type="PackedScene" uid="uid://cwy8iv8nlwqrc" path="res://assets/realtime_day_night_cycle.tscn" id="3_uc3ig"] [ext_resource type="PackedScene" uid="uid://cwy8iv8nlwqrc" path="res://assets/realtime_day_night_cycle.tscn" id="3_uc3ig"]
[ext_resource type="Script" uid="uid://12l74jckdnpl" path="res://scripts/room_manager.gd" id="4_iqtg8"] [ext_resource type="Script" uid="uid://12l74jckdnpl" path="res://scripts/room_manager.gd" id="4_iqtg8"]
[ext_resource type="PackedScene" uid="uid://djr7vnr1hcx82" path="res://assets/spider2.tscn" id="5_vb31s"] [ext_resource type="PackedScene" uid="uid://djr7vnr1hcx82" path="res://assets/spider2.tscn" id="5_vb31s"]
@@ -10,8 +11,8 @@
[ext_resource type="PackedScene" uid="uid://24slv0pyxcd5" path="res://assets/level_bounds.tscn" id="16_8ulfh"] [ext_resource type="PackedScene" uid="uid://24slv0pyxcd5" path="res://assets/level_bounds.tscn" id="16_8ulfh"]
[ext_resource type="PackedScene" uid="uid://bj1y0fbjtul4a" path="res://post_processing.tscn" id="17_6thjn"] [ext_resource type="PackedScene" uid="uid://bj1y0fbjtul4a" path="res://post_processing.tscn" id="17_6thjn"]
[ext_resource type="PackedScene" uid="uid://dc0fxhbw6x1h3" path="res://tube_top.tscn" id="17_57hjo"] [ext_resource type="PackedScene" uid="uid://dc0fxhbw6x1h3" path="res://tube_top.tscn" id="17_57hjo"]
[ext_resource type="PackedScene" uid="uid://c5t4uqihf8q0i" path="res://scripts/chest_spawner.tscn" id="17_e6kt2"]
[ext_resource type="PackedScene" uid="uid://dt4t2a48204v1" path="res://assets/spikes_1.tscn" id="17_hpnr5"] [ext_resource type="PackedScene" uid="uid://dt4t2a48204v1" path="res://assets/spikes_1.tscn" id="17_hpnr5"]
[ext_resource type="PackedScene" uid="uid://db7xqf12sayj0" path="res://assets/chest_spawner.tscn" id="17_mw655"]
[ext_resource type="PackedScene" uid="uid://20csd6dmwj4y" path="res://assets/jump_platform.tscn" id="18_1ool5"] [ext_resource type="PackedScene" uid="uid://20csd6dmwj4y" path="res://assets/jump_platform.tscn" id="18_1ool5"]
[ext_resource type="PackedScene" uid="uid://c0vc26f4warsi" path="res://scripts/cloud_spawner.tscn" id="18_e6kt2"] [ext_resource type="PackedScene" uid="uid://c0vc26f4warsi" path="res://scripts/cloud_spawner.tscn" id="18_e6kt2"]
[ext_resource type="PackedScene" uid="uid://do6gt53xr2l23" path="res://assets/garbage_bin.tscn" id="18_r6s5q"] [ext_resource type="PackedScene" uid="uid://do6gt53xr2l23" path="res://assets/garbage_bin.tscn" id="18_r6s5q"]
@@ -29,6 +30,7 @@ albedo_color = Color(0.300579, 0.462784, 0.249767, 1)
size = Vector3(722.834, 289.347, 420.508) size = Vector3(722.834, 289.347, 420.508)
[node name="Highwire" type="Node3D"] [node name="Highwire" type="Node3D"]
script = ExtResource("1_e6kt2")
[node name="Realtime Day Night Cycle" parent="." instance=ExtResource("3_uc3ig")] [node name="Realtime Day Night Cycle" parent="." instance=ExtResource("3_uc3ig")]
transform = Transform3D(0.510503, -0.00501647, 0.859861, 0.00982605, 0.999952, 1.08313e-09, -0.85982, 0.00844904, 0.510527, -41.021, 0, 40.533) transform = Transform3D(0.510503, -0.00501647, 0.859861, 0.00982605, 0.999952, 1.08313e-09, -0.85982, 0.00844904, 0.510527, -41.021, 0, 40.533)
@@ -299,21 +301,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -14.9072, -0.1705, 12.0777)
[node name="Spikes 5" parent="." instance=ExtResource("17_hpnr5")] [node name="Spikes 5" parent="." instance=ExtResource("17_hpnr5")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -203.179, -0.1705, 11.0759) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -203.179, -0.1705, 11.0759)
[node name="ChestSpawner" parent="." instance=ExtResource("17_mw655")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -197.055, 28.7598, -23.1374)
[node name="ChestSpawner2" parent="." instance=ExtResource("17_mw655")]
transform = Transform3D(0.326146, 0, 0.94532, 0, 1, 0, -0.94532, 0, 0.326146, -245.963, 17.0575, -26.9477)
[node name="ChestSpawner3" parent="." instance=ExtResource("17_mw655")]
transform = Transform3D(0.419579, 0, 0.907719, 0, 1, 0, -0.907719, 0, 0.419579, -237.2, 1.26645, -39.3357)
[node name="ChestSpawner4" parent="." instance=ExtResource("17_mw655")]
transform = Transform3D(0.419579, 0, 0.907719, 0, 1, 0, -0.907719, 0, 0.419579, -237.2, 1.26645, -70.919)
[node name="ChestSpawner5" parent="." instance=ExtResource("17_mw655")]
transform = Transform3D(0.419579, 0, 0.907719, 0, 1, 0, -0.907719, 0, 0.419579, -237.2, 1.26645, -98.4264)
[node name="GarbageBin" parent="." instance=ExtResource("18_r6s5q")] [node name="GarbageBin" parent="." instance=ExtResource("18_r6s5q")]
transform = Transform3D(-0.714729, 0, -0.699401, 0, 1, 0, 0.699401, 0, -0.714729, -4.96806, -0.170516, 18.2021) transform = Transform3D(-0.714729, 0, -0.699401, 0, 1, 0, 0.699401, 0, -0.714729, -4.96806, -0.170516, 18.2021)
@@ -352,3 +339,23 @@ size = Vector3(102.386, 146.752, 579.126)
[node name="Cloudspawn6" parent="." instance=ExtResource("18_e6kt2")] [node name="Cloudspawn6" parent="." instance=ExtResource("18_e6kt2")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -567.32, 59.7442, -47.1966) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -567.32, 59.7442, -47.1966)
size = Vector3(102.386, 146.752, 579.126) size = Vector3(102.386, 146.752, 579.126)
[node name="ChestSpawner" parent="." instance=ExtResource("17_e6kt2")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -230.434, 17.394, -66.4599)
size = Vector3(39, 4.19531, 120.959)
[node name="ChestSpawner2" parent="." instance=ExtResource("17_e6kt2")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -198.325, 27.2852, -20.5712)
size = Vector3(21.75, 2.03613, 19.1631)
[node name="ChestSpawner3" parent="." instance=ExtResource("17_e6kt2")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -237.215, 1.4657, -104.908)
size = Vector3(21.75, 2.03613, 19.1631)
[node name="ChestSpawner4" parent="." instance=ExtResource("17_e6kt2")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -237.215, 1.83144, -68.4389)
size = Vector3(21.75, 2.03613, 19.1631)
[node name="ChestSpawner5" parent="." instance=ExtResource("17_e6kt2")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -237.215, 1.62245, -39.3783)
size = Vector3(21.75, 2.03613, 19.1631)

View File

@@ -66,3 +66,8 @@ func checksum(check_data):
checksum_final = hash(checksum_final) checksum_final = hash(checksum_final)
return checksum_final return checksum_final
func clear_spawned_objects():
#clear spawned objects
for node in get_tree().get_nodes_in_group("spawned"):
node.queue_free()

View File

@@ -61,36 +61,15 @@ func _ready():
refresh_scene() refresh_scene()
spawn_crown() spawn_crown()
#global randomize function
randomize()
HelperFuncs.clear_spawned_objects()
#clear spawned in objects
for node in get_tree().get_nodes_in_group("spawned"):
node.queue_free()
#find enemy hiveminds #find enemy hiveminds
for node in get_tree().get_nodes_in_group("enemy_hivemind"): for node in get_tree().get_nodes_in_group("enemy_hivemind"):
enemy_hiveminds.append(node) enemy_hiveminds.append(node)
#count starting enemies #count starting enemies
enemy_count() enemy_count()
spawn_chests()
chest_spawners = get_tree().get_nodes_in_group("chest_spawner")
if chest_spawners.size() > 0:
for i in chest_spawners:
i.visible = false
var number_chests = randi_range(1,gamemode.max_number_of_chests)
while number_chests > 0:
var chest_loc = chest_spawners.pick_random()
var instance_chest = CHEST_1.instantiate()
print("SPAWNING CHEST AT : ",chest_loc.name)
add_child(instance_chest)
instance_chest.basis = chest_loc.basis
instance_chest.global_position = chest_loc.global_position
instance_chest.global_rotation = chest_loc.global_rotation
number_chests -= 1
func refresh_scene(): func refresh_scene():
@@ -108,6 +87,24 @@ func spawn_crown():
if crown_target.is_in_group("enemy"): if crown_target.is_in_group("enemy"):
crown_target.loot_amount = 10 crown_target.loot_amount = 10
func spawn_chests():
chest_spawners = get_tree().get_nodes_in_group("chest_spawner")
if chest_spawners.size() > 0:
for i in chest_spawners:
i.visible = false
var number_chests = randi_range(1,gamemode.max_number_of_chests)
while number_chests > 0:
var chest_loc = chest_spawners.pick_random()
var instance_chest = CHEST_1.instantiate()
print("SPAWNING CHEST AT : ",chest_loc.name)
add_child(instance_chest)
instance_chest.basis = chest_loc.basis
instance_chest.global_position = chest_loc.global_position
instance_chest.global_rotation = chest_loc.global_rotation
number_chests -= 1
func gun_spawn(index): func gun_spawn(index):
#loop around if scrolling past available guns #loop around if scrolling past available guns

View File

@@ -22,11 +22,6 @@ func _ready() -> void:
GameGlobals.chests_spawned += 1 GameGlobals.chests_spawned += 1
serial_label.text = "#" + str(serial_number).pad_zeros(4) serial_label.text = "#" + str(serial_number).pad_zeros(4)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func hit(dam): func hit(dam):
health -= dam health -= dam
if !open and health <= 0: if !open and health <= 0:

View File

@@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://c5t4uqihf8q0i"]
[ext_resource type="Script" uid="uid://fs6qd8efarl7" path="res://scripts/csg_spawner.gd" id="1_l7ryb"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_hthjk"]
transparency = 1
shading_mode = 0
albedo_color = Color(1, 1, 1, 0)
[node name="ChestSpawner" type="CSGBox3D" groups=["chest_spawner"]]
material = SubResource("StandardMaterial3D_hthjk")
script = ExtResource("1_l7ryb")

View File

@@ -1,4 +1,4 @@
extends CSGBox3D extends CSGSpawner
@export var number_of_clouds : int = 50 @export var number_of_clouds : int = 50
@export var cloud = preload("res://cloud1.tscn") @export var cloud = preload("res://cloud1.tscn")
@@ -10,10 +10,7 @@ func spawn_clouds():
while number_of_clouds >= 0: while number_of_clouds >= 0:
number_of_clouds -= 1 number_of_clouds -= 1
var x : float = randf_range(size.x / 2, -size.x /2) var spawn_pos = random_box_pos()
var y : float = randf_range(size.y/ 2, -size.y /2)
var z : float = randf_range(size.z / 2, -size.z /2)
var spawn_pos = Vector3(x,y,z)
var cloud = cloud.instantiate() var cloud = cloud.instantiate()
add_child(cloud) add_child(cloud)

8
scripts/csg_spawner.gd Normal file
View File

@@ -0,0 +1,8 @@
extends CSGBox3D
class_name CSGSpawner
func random_box_pos():
var x : float = randf_range(size.x / 2, -size.x /2)
var y : float = randf_range(size.y/ 2, -size.y /2)
var z : float = randf_range(size.z / 2, -size.z /2)
return Vector3(x,y,z)

View File

@@ -0,0 +1 @@
uid://fs6qd8efarl7

View File

@@ -26,14 +26,10 @@ func _on_body_entered(body: Node3D) -> void:
entered = true entered = true
if active and entered: if active and entered:
HelperFuncs.clear_spawned_objects()
var spawned_stuff = scene_holder.get_children() var spawned_stuff = scene_holder.get_children()
for i in spawned_stuff: for i in spawned_stuff:
i.queue_free() i.queue_free()
func clear_spawned_objects():
for i in get_tree().current_scene:
if i.is_in_group("spawned"):
i.queue_free()
func _on_start_activation_timeout() -> void: func _on_start_activation_timeout() -> void:
active = true active = true

24
scripts/sublevel.gd Normal file
View File

@@ -0,0 +1,24 @@
extends Node3D
const CHEST_1 = preload("res://chest1.tscn")
func _ready() -> void:
spawn_chests()
func spawn_chests():
var chest_spawners = get_tree().get_nodes_in_group("chest_spawner")
if chest_spawners.size() > 0:
for i in chest_spawners:
i.visible = false
var number_chests = 3
while number_chests > 0:
var chest_loc = chest_spawners.pick_random()
var instance_chest = CHEST_1.instantiate()
get_tree().current_scene.add_child(instance_chest)
instance_chest.global_position = chest_loc.global_position + chest_loc.random_box_pos()
print("CHEST SPAWNED AT : ",instance_chest.global_position)
number_chests -= 1

1
scripts/sublevel.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://pm8n67yhip1p