working on rat

This commit is contained in:
derek
2025-05-12 16:43:25 -05:00
parent 4c98bca83b
commit ed3c47e9cf
10 changed files with 119 additions and 92 deletions

View File

@@ -1,34 +1,38 @@
extends Node3D
@export var rat : Resource
@export var spawn_amount = 10 #max amount in level at any given time
@export var spawn_time_max = 5
var rng = RandomNumberGenerator.new()
var spawn_timer
var holes = []
var start_hole_id
var start_hole
var end_hole_id
var end_hole
var hole_length_id
var control_node = self
# Called when the node enters the scene tree for the first time.
func _ready():
holes = get_children()
hole_length_id = holes.size() - 1
func _ready() -> void:
#get holes
for node in self.get_children():
if node is RatHole:
holes.append(node)
print("HOLES : ",holes)
spawn_rat_at_random_hole()
reset_spawn_timer()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if spawn_amount > 0:
start_hole_id = rng.randi_range(0,hole_length_id)
start_hole = holes[start_hole_id]
end_hole_id = rng.randi_range(0,hole_length_id)
while start_hole_id == end_hole_id:
end_hole_id = rng.randi_range(0,hole_length_id)
end_hole = holes[end_hole_id]
#spawn rat at first hole and pass position of next hole
start_hole.spawn_rat(end_hole,control_node)
spawn_amount -= 1
func _process(delta: float) -> void:
print("TIME UNTIL NEXT SPAWN : ",spawn_timer)
if spawn_timer > 0:
spawn_timer -= delta
else:
reset_spawn_timer()
spawn_rat_at_random_hole()
func spawn_rat_at_random_hole():
if holes.size() >= 2:
var hole_options = holes.duplicate()
hole_options.shuffle()
var spawn_hole = hole_options.pop_front()
var destination_hole = hole_options.pop_front()
print("SPAWN HOLE : ", spawn_hole)
print("END_HOLE : ",destination_hole)
spawn_hole.spawn_rat(destination_hole)
func reset_spawn_timer():
spawn_timer = randf_range(1,spawn_time_max)