diff --git a/assets/LevelBlockouts/hub_1.tscn b/assets/LevelBlockouts/hub_1.tscn index e0dd41f..a62f2ff 100644 --- a/assets/LevelBlockouts/hub_1.tscn +++ b/assets/LevelBlockouts/hub_1.tscn @@ -451,6 +451,7 @@ transform = Transform3D(-0.992703, 0, -0.120587, 0, 1, 0, 0.120587, 0, -0.992703 [node name="RATS" type="Node3D" parent="."] script = ExtResource("24_4o8us") +spawn_rat_pickups = 0 [node name="RatHole2" parent="RATS" instance=ExtResource("24_dblmv")] transform = Transform3D(1.19249e-08, 0, -1, 0, 1, 0, 1, 0, 1.19249e-08, -13.0478, 0.410853, -9.74827) diff --git a/assets/rat_hole.tscn b/assets/rat_hole.tscn index 61e3611..eb98ebc 100644 --- a/assets/rat_hole.tscn +++ b/assets/rat_hole.tscn @@ -21,8 +21,8 @@ rat = ExtResource("2_dih3n") mesh = SubResource("BoxMesh_7h30q") [node name="Area3D" type="Area3D" parent="."] -collision_layer = 2 -collision_mask = 2 +collision_layer = 64 +collision_mask = 64 [node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0113525, -0.302734) diff --git a/scripts/Rat_Control.gd b/scripts/Rat_Control.gd index 353409a..c3ac879 100644 --- a/scripts/Rat_Control.gd +++ b/scripts/Rat_Control.gd @@ -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) diff --git a/scripts/rat.gd b/scripts/rat.gd index dfbd9f1..aefead6 100644 --- a/scripts/rat.gd +++ b/scripts/rat.gd @@ -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 diff --git a/scripts/rat_hole.gd b/scripts/rat_hole.gd index b20f6b1..227c367 100644 --- a/scripts/rat_hole.gd +++ b/scripts/rat_hole.gd @@ -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()