added chest and chest spawners but they don't always show up?

This commit is contained in:
Derek
2025-03-02 22:17:04 -06:00
parent dc7ecf83ee
commit ea68629594
71 changed files with 3127 additions and 98 deletions

View File

@@ -15,9 +15,11 @@ class_name level
@onready var crown = preload("res://assets/crown.tscn")
var dead_player = preload("res://assets/dead_cam.tscn")
const DEAD_ANNOUNCE = preload("res://assets/dead_announce.tscn")
const CHEST_1 = preload("res://chest1.tscn")
var level_name
var paused = false
var chest_spawners = []
var pickups = []
var keys = []
@@ -32,6 +34,7 @@ var respawn_cam_rotation
var respawn_rot
var engine_time_scale_cache : float = 1.0
# Called when the node enters the scene tree for the first time.
func _ready():
level_name = self.get_name()
@@ -72,7 +75,7 @@ func _ready():
#global randomize function
randomize()
#clear spawned in objects
for node in get_tree().get_nodes_in_group("spawned"):
node.queue_free()
@@ -82,6 +85,23 @@ func _ready():
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)
instance_chest.global_position = chest_loc.global_position
instance_chest.global_rotation = chest_loc.global_rotation
get_tree().current_scene.add_child(instance_chest)
number_chests -= 1
func refresh_scene():
GameGlobals.health = gamemode.start_health

34
scripts/chest_1.gd Normal file
View File

@@ -0,0 +1,34 @@
extends RigidBody3D
@export var weapon_drops : Array[Resource]
var open = false
var drop_weapon
@onready var anim_player: AnimationPlayer = $AnimationPlayer
@onready var item_spawn: RayCast3D = $itemspawn
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
drop_weapon = weapon_drops.pick_random().instantiate()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func hit(dam):
if !open:
anim_player.play("open")
open = true
func spawn_drop():
drop_weapon.position = item_spawn.global_position
drop_weapon.transform.basis = item_spawn.global_transform.basis
drop_weapon.scale = Vector3(1,1,1)
drop_weapon.linear_velocity += Vector3(0,0,-5.0) * item_spawn.global_transform.basis
get_tree().current_scene.add_child(drop_weapon)
func interact():
hit(0)

View File

@@ -12,7 +12,6 @@ const MAX_LV = 10
const MAX_AV = 10
@export_enum("Enemy", "Trap") var enemy_type: int
@export var player_path : NodePath
@export var bullet : Resource
@export var casing : Resource
@export var bullet_speed = 150
@@ -95,9 +94,10 @@ func _process(delta):
if !stunned:
stunned_stars.visible = false
#Sightline
if turret_look_next.is_colliding() and turret_look_next.get_collider().is_in_group("player"):
player_in_view = true
player_last_seen = turret_look_next.get_collider().global_position
if turret_look_next.get_collider() != null:
if turret_look_next.get_collider().is_in_group("player"):
player_in_view = true
player_last_seen = turret_look_next.get_collider().global_position
if player != null:
spider_look_next.look_at(Vector3(player.global_position.x, 0, player.global_position.z), Vector3.UP)
body.rotation.y = lerp(body.rotation.y, spider_look_next.rotation.y, delta * 1)

View File

@@ -0,0 +1,14 @@
extends StaticBody3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func hit(dam):
get_parent().hit(dam)