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
|
extends Node3D
|
||||||
|
|
||||||
var survivors: int = 5
|
@export var batch_duration: float = 16.0
|
||||||
var survivor_rate: float = .75
|
@export var lateral_variance: float = 1.5
|
||||||
var speed_modifer: int = 0
|
|
||||||
var spawn_readiness: bool = false
|
var _active_walkers: Array[Node] = []
|
||||||
|
var _batch_generation: int = 0
|
||||||
|
|
||||||
@onready var survivor = preload("res://scenes/survivor.tscn")
|
@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 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:
|
func _enter_tree() -> void:
|
||||||
start()
|
EventBus.floor_started.connect(_on_floor_started, CONNECT_DEFERRED)
|
||||||
|
|
||||||
func start() -> void:
|
func _on_floor_started(count: int) -> void:
|
||||||
spawn_readiness = true
|
_batch_generation += 1
|
||||||
spawn_survivor()
|
_clear_active_walkers()
|
||||||
|
if count <= 0:
|
||||||
|
return
|
||||||
|
_run_batch(count, _batch_generation)
|
||||||
|
|
||||||
#func _physics_process(delta):
|
func _clear_active_walkers() -> void:
|
||||||
#if spawn_readiness == true:
|
for w in _active_walkers:
|
||||||
#spawn_survivor()
|
if is_instance_valid(w):
|
||||||
#spawn_readiness = false
|
w.queue_free()
|
||||||
#
|
_active_walkers.clear()
|
||||||
#else: pass
|
|
||||||
|
|
||||||
func spawn_survivor():
|
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
|
||||||
|
|
||||||
if spawn_readiness == false: pass
|
func _spawn_one() -> void:
|
||||||
|
|
||||||
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()
|
var s = survivor.instantiate()
|
||||||
|
var offset := Vector3(randf_range(-lateral_variance, lateral_variance), 0, 0)
|
||||||
get_tree().root.add_child.call_deferred(s)
|
get_tree().root.add_child.call_deferred(s)
|
||||||
#get_node("/root/Game/World").add_child(s)
|
s.position = start_pos + offset
|
||||||
s.position = start_pos + start_variance
|
_active_walkers.append(s)
|
||||||
await get_tree().create_timer(survivor_rate * survivor_delay).timeout
|
|
||||||
spawn_readiness = true
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ func _start_floor():
|
||||||
|
|
||||||
EventBus.people_changed.emit(people_in_elevator, threshold)
|
EventBus.people_changed.emit(people_in_elevator, threshold)
|
||||||
EventBus.floor_changed.emit(current_floor)
|
EventBus.floor_changed.emit(current_floor)
|
||||||
|
EventBus.floor_started.emit(survivors_remaining)
|
||||||
|
|
||||||
var screen = $PanelMargin/PanelColumn/Screen
|
var screen = $PanelMargin/PanelColumn/Screen
|
||||||
screen.start()
|
screen.start()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
extends Node3D
|
extends Node3D
|
||||||
|
|
||||||
func _ready() -> void:
|
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 people_changed(count: int, threshold: int)
|
||||||
signal game_won
|
signal game_won
|
||||||
signal game_lost
|
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
|
@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