paratate/systems/boss/boss_phase.gd
2026-01-03 20:47:31 -06:00

62 lines
1.3 KiB
GDScript

class_name BossPhase
extends Node
signal started()
signal ended()
signal damaged(damage: int)
## Amount of HP this boss stage has. If 0, the boss is invulnerable during
## this phase and must survive until time runs out or [method end_phase] is called.
@export_range(0, 1, 1, "or_greater") var hp: int = 0
## "Survival Time" of the phase. The phase will end when time is up, whether
## HP has been depleted or not.
@export_range(0.0, 1.0, 0.01, "or_greater", "suffix:s") var time: float = INF
## The phase to automatically proceed to when this phase ends.
@export var next_phase: BossPhase
## [code]true[/code] if the phase is currently active.
var active: bool = false
var hp_left: int:
set(value):
hp_left = value
if active and hp_left <= 0 and hp > 0:
end_phase()
var time_left: float = INF:
set(value):
time_left = value
if active and time_left <= 0.0:
end_phase()
func _physics_process(delta: float) -> void:
if active:
time_left -= delta
func start_phase() -> void:
if not active:
hp_left = hp
time_left = time
active = true
started.emit()
func end_phase() -> void:
if active:
active = false
ended.emit()
if next_phase:
next_phase.start_phase()
func hurt(damage: int) -> void:
if active:
hp_left = maxi(0, hp_left - damage)
damaged.emit(damage)