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)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
extends CharacterBody3D
|
||||
class_name Rat
|
||||
|
||||
@export var dead_rat : Resource
|
||||
@export var SPEED = 5
|
||||
@@ -9,8 +10,8 @@ extends CharacterBody3D
|
||||
@onready var nav_agent = $NavigationAgent3D
|
||||
|
||||
var end_hole
|
||||
var number_of_drops = 1
|
||||
|
||||
const number_of_drops = 1
|
||||
const MAX_LV = 20
|
||||
const MAX_AV = 10
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@ class_name RatHole
|
||||
@onready var spawnpos: Marker3D = $spawnpos
|
||||
@onready var area_3d = $Area3D
|
||||
|
||||
func spawn_rat(end_hole):
|
||||
func spawn_rat(end_hole,number_of_pickups):
|
||||
var spawn_rat = rat.instantiate()
|
||||
spawn_rat.position = spawnpos.global_position
|
||||
spawn_rat.end_hole = end_hole
|
||||
spawn_rat.number_of_drops = number_of_pickups
|
||||
get_parent().add_child(spawn_rat)
|
||||
|
||||
func _on_area_3d_body_entered(body):
|
||||
if body.is_in_group("rat"):
|
||||
if body is Rat:
|
||||
if body.end_hole == self:
|
||||
#body.control_node.spawn_amount += 1 #signal to control node that another rat can enter the scene
|
||||
body.queue_free()
|
||||
|
||||
Reference in New Issue
Block a user