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

@@ -66,3 +66,8 @@ func checksum(check_data):
checksum_final = hash(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()
spawn_crown()
#global randomize function
randomize()
#clear spawned in objects
for node in get_tree().get_nodes_in_group("spawned"):
node.queue_free()
HelperFuncs.clear_spawned_objects()
#find enemy hiveminds
for node in get_tree().get_nodes_in_group("enemy_hivemind"):
enemy_hiveminds.append(node)
#count starting enemies
enemy_count()
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
spawn_chests()
func refresh_scene():
@@ -108,6 +87,24 @@ func spawn_crown():
if crown_target.is_in_group("enemy"):
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):
#loop around if scrolling past available guns

View File

@@ -22,11 +22,6 @@ func _ready() -> void:
GameGlobals.chests_spawned += 1
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):
health -= dam
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 cloud = preload("res://cloud1.tscn")
@@ -10,10 +10,7 @@ func spawn_clouds():
while number_of_clouds >= 0:
number_of_clouds -= 1
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)
var spawn_pos = Vector3(x,y,z)
var spawn_pos = random_box_pos()
var cloud = cloud.instantiate()
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
if active and entered:
HelperFuncs.clear_spawned_objects()
var spawned_stuff = scene_holder.get_children()
for i in spawned_stuff:
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:
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