rat hole tweaks
This commit is contained in:
@@ -2,6 +2,8 @@ extends Node3D
|
||||
|
||||
@export var rat : Resource
|
||||
@export var spawn_time_max = 5
|
||||
@export var max_rats : float = 2
|
||||
@export var spawn_rat_pickups = 1
|
||||
|
||||
var spawn_timer
|
||||
var holes = []
|
||||
@@ -12,17 +14,16 @@ func _ready() -> void:
|
||||
for node in self.get_children():
|
||||
if node is RatHole:
|
||||
holes.append(node)
|
||||
print("HOLES : ",holes)
|
||||
spawn_rat_at_random_hole()
|
||||
reset_spawn_timer()
|
||||
|
||||
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()
|
||||
if can_spawn_more_rats():
|
||||
reset_spawn_timer()
|
||||
spawn_rat_at_random_hole()
|
||||
|
||||
func spawn_rat_at_random_hole():
|
||||
if holes.size() >= 2:
|
||||
@@ -30,9 +31,19 @@ func spawn_rat_at_random_hole():
|
||||
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)
|
||||
spawn_hole.spawn_rat(destination_hole,spawn_rat_pickups)
|
||||
|
||||
func can_spawn_more_rats():
|
||||
var rat_count = 0
|
||||
#count rats
|
||||
for node in get_children():
|
||||
if node is Rat:
|
||||
rat_count += 1
|
||||
#compare
|
||||
if rat_count < max_rats:
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func reset_spawn_timer():
|
||||
spawn_timer = randf_range(1,spawn_time_max)
|
||||
|
||||
Reference in New Issue
Block a user