Added effects manager and two effects to test attached to the player
scene.
This commit is contained in:
parent
1200ac7e32
commit
b4c4a66ce8
19 changed files with 322 additions and 40 deletions
34
scripts/effects/effects_component.gd
Normal file
34
scripts/effects/effects_component.gd
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
class_name EffectComponent
|
||||
extends Node
|
||||
|
||||
## The node this component applies effects to.
|
||||
## If left null, defaults to the first parent CanvasItem.
|
||||
@export var target_node: Node = null
|
||||
|
||||
var active_effects: Array[BaseEffect] = []
|
||||
|
||||
func _ready() -> void:
|
||||
if target_node == null:
|
||||
# Auto-resolve to the parent if nothing is set
|
||||
target_node = get_parent()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if target_node == null:
|
||||
return
|
||||
|
||||
# Process all active effects backwards so we can safely remove finished ones
|
||||
for i in range(active_effects.size() - 1, -1, -1):
|
||||
var effect = active_effects[i]
|
||||
effect.process(delta, target_node)
|
||||
|
||||
if effect.is_finished():
|
||||
remove_effect(effect)
|
||||
|
||||
func apply_effect(effect: BaseEffect) -> void:
|
||||
var instance = effect.duplicate()
|
||||
instance.start(target_node)
|
||||
active_effects.append(instance)
|
||||
|
||||
func remove_effect(effect: BaseEffect) -> void:
|
||||
effect.stop(target_node)
|
||||
active_effects.erase(effect)
|
||||
Loading…
Add table
Add a link
Reference in a new issue