Sync survivor spawning with per-floor pacing
Clear runners on each new floor as well
This commit is contained in:
parent
ec958717b1
commit
6b2065f4b2
4 changed files with 38 additions and 39 deletions
|
|
@ -1,44 +1,43 @@
|
|||
extends Node3D
|
||||
|
||||
var survivors: int = 5
|
||||
var survivor_rate: float = .75
|
||||
var speed_modifer: int = 0
|
||||
var spawn_readiness: bool = false
|
||||
@export var batch_duration: float = 16.0
|
||||
@export var lateral_variance: float = 1.5
|
||||
|
||||
var _active_walkers: Array[Node] = []
|
||||
var _batch_generation: int = 0
|
||||
|
||||
@onready var survivor = preload("res://scenes/survivor.tscn")
|
||||
@onready var world = preload("res://scenes/world.tscn")
|
||||
|
||||
@onready var survivor_spawn = get_node("/root/Game/World/SuvivorSpawn")
|
||||
@onready var start_pos = survivor_spawn.global_position
|
||||
@onready var start_pos: Vector3 = survivor_spawn.global_position
|
||||
|
||||
func _ready() -> void:
|
||||
start()
|
||||
func _enter_tree() -> void:
|
||||
EventBus.floor_started.connect(_on_floor_started, CONNECT_DEFERRED)
|
||||
|
||||
func start() -> void:
|
||||
spawn_readiness = true
|
||||
spawn_survivor()
|
||||
func _on_floor_started(count: int) -> void:
|
||||
_batch_generation += 1
|
||||
_clear_active_walkers()
|
||||
if count <= 0:
|
||||
return
|
||||
_run_batch(count, _batch_generation)
|
||||
|
||||
#func _physics_process(delta):
|
||||
#if spawn_readiness == true:
|
||||
#spawn_survivor()
|
||||
#spawn_readiness = false
|
||||
#
|
||||
#else: pass
|
||||
func _clear_active_walkers() -> void:
|
||||
for w in _active_walkers:
|
||||
if is_instance_valid(w):
|
||||
w.queue_free()
|
||||
_active_walkers.clear()
|
||||
|
||||
func spawn_survivor():
|
||||
|
||||
if spawn_readiness == false: pass
|
||||
|
||||
else:
|
||||
|
||||
var survivor_delay: float = randf_range(1, 2.5)
|
||||
var start_variance = Vector3((randf_range(-1, 2)),0,0)
|
||||
|
||||
for x in range(survivors):
|
||||
var s = survivor.instantiate()
|
||||
get_tree().root.add_child.call_deferred(s)
|
||||
#get_node("/root/Game/World").add_child(s)
|
||||
s.position = start_pos + start_variance
|
||||
await get_tree().create_timer(survivor_rate * survivor_delay).timeout
|
||||
spawn_readiness = true
|
||||
func _run_batch(count: int, generation: int) -> void:
|
||||
var gap: float = batch_duration / float(count)
|
||||
for i in range(count):
|
||||
if generation != _batch_generation:
|
||||
return
|
||||
_spawn_one()
|
||||
var jitter: float = randf_range(-gap * 0.25, gap * 0.25)
|
||||
await get_tree().create_timer(max(0.05, gap + jitter)).timeout
|
||||
|
||||
func _spawn_one() -> void:
|
||||
var s = survivor.instantiate()
|
||||
var offset := Vector3(randf_range(-lateral_variance, lateral_variance), 0, 0)
|
||||
get_tree().root.add_child.call_deferred(s)
|
||||
s.position = start_pos + offset
|
||||
_active_walkers.append(s)
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ func _start_floor():
|
|||
|
||||
EventBus.people_changed.emit(people_in_elevator, threshold)
|
||||
EventBus.floor_changed.emit(current_floor)
|
||||
EventBus.floor_started.emit(survivors_remaining)
|
||||
|
||||
var screen = $PanelMargin/PanelColumn/Screen
|
||||
screen.start()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
extends Node3D
|
||||
|
||||
func _ready() -> void:
|
||||
$ComponentSpawn.spawn_survivor()
|
||||
|
||||
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -8,5 +8,6 @@ signal score_changed(new_score: int)
|
|||
signal people_changed(count: int, threshold: int)
|
||||
signal game_won
|
||||
signal game_lost
|
||||
signal floor_started(survivor_count: int)
|
||||
|
||||
@warning_ignore_restore("unused_signal") # put any future signals you add between the two ignore annotations
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue