add feature to wave logic for boss wave

pull/9/head
Jaro Winkelhausen 2026-04-15 18:19:32 +02:00
parent fc40a5c368
commit 8720727609
2 changed files with 7 additions and 1 deletions

View File

@ -5,3 +5,4 @@ class_name StageEntry
@export var count_at_start: int = 0
@export var count_at_end: int = 20
@export var min_interval: float = 0.3
@export var max_spawns: int = -1 # -1 = unlimited

View File

@ -29,7 +29,7 @@ func _ready() -> void:
for si in stages.size():
for ei in stages[si].entries.size():
_state[Vector2i(si, ei)] = { "timer": 0.0, "alive": 0 }
_state[Vector2i(si, ei)] = { "timer": 0.0, "alive": 0, "spawned_total": 0 }
func _load_stages(path: String) -> void:
var file = FileAccess.open(path, FileAccess.READ)
@ -50,6 +50,7 @@ func _load_stages(path: String) -> void:
entry.count_at_start = int(ed["count_at_start"])
entry.count_at_end = int(ed["count_at_end"])
entry.min_interval = float(ed["min_interval"])
entry.max_spawns = int(ed.get("max_spawns", -1))
stage.entries.append(entry)
stages.append(stage)
@ -94,6 +95,9 @@ func _process(delta: float) -> void:
var entry: StageEntry = stage.entries[ei]
var state: Dictionary = _state[Vector2i(si, ei)]
if entry.max_spawns != -1 and state["spawned_total"] >= entry.max_spawns:
continue
var target: int = roundi(lerpf(float(entry.count_at_start), float(entry.count_at_end), t))
var deficit: int = target - state["alive"]
if deficit <= 0:
@ -108,5 +112,6 @@ func _spawn_one(entry: StageEntry, state: Dictionary) -> void:
var enemy = entry.enemy.instantiate()
enemy.global_position = get_spawn_position()
state["alive"] += 1
state["spawned_total"] += 1
enemy.tree_exited.connect(func(): state["alive"] -= 1)
add_child(enemy)