Better status effects

This commit is contained in:
2025-03-02 02:50:05 +01:00
parent 9054777a05
commit a562079d71
17 changed files with 192 additions and 102 deletions

View File

@@ -10,7 +10,7 @@
[ext_resource type="Script" path="res://scripts/components/player_death.gd" id="8_1v23d"] [ext_resource type="Script" path="res://scripts/components/player_death.gd" id="8_1v23d"]
[ext_resource type="Script" path="res://scripts/components/knockback.gd" id="9_rjyu4"] [ext_resource type="Script" path="res://scripts/components/knockback.gd" id="9_rjyu4"]
[ext_resource type="Script" path="res://scripts/components/brick_throw.gd" id="10_u0v3b"] [ext_resource type="Script" path="res://scripts/components/brick_throw.gd" id="10_u0v3b"]
[ext_resource type="PackedScene" uid="uid://bcmx07k12gcsc" path="res://objects/ice_brick.tscn" id="11_ktjj0"] [ext_resource type="PackedScene" uid="uid://bcmx07k12gcsc" path="res://objects/ice_brick.tscn" id="11_thd7o"]
[ext_resource type="Script" path="res://scripts/components/stomp_damage_component.gd" id="12_payr4"] [ext_resource type="Script" path="res://scripts/components/stomp_damage_component.gd" id="12_payr4"]
[ext_resource type="Script" path="res://scripts/components/flashing_component.gd" id="13_hrtyn"] [ext_resource type="Script" path="res://scripts/components/flashing_component.gd" id="13_hrtyn"]
[ext_resource type="Script" path="res://scripts/components/invulnerability_component.gd" id="14_jopig"] [ext_resource type="Script" path="res://scripts/components/invulnerability_component.gd" id="14_jopig"]
@@ -84,7 +84,7 @@ knockback_force = 1500.0
[node name="BrickThrowComponent" type="Node" parent="." node_paths=PackedStringArray("player_controller", "timer")] [node name="BrickThrowComponent" type="Node" parent="." node_paths=PackedStringArray("player_controller", "timer")]
script = ExtResource("10_u0v3b") script = ExtResource("10_u0v3b")
brick_scene = ExtResource("11_ktjj0") brick_scene = ExtResource("11_thd7o")
fire_rate = 0.3 fire_rate = 0.3
player_controller = NodePath("..") player_controller = NodePath("..")
timer = NodePath("../ThrowTimer") timer = NodePath("../ThrowTimer")

View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://bhc7y4xugu4q7"] [gd_scene load_steps=5 format=3 uid="uid://bhc7y4xugu4q7"]
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_w543f"] [ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_w543f"]
[ext_resource type="Script" path="res://scripts/components/damage.gd" id="2_qkwsu"] [ext_resource type="Script" path="res://scripts/components/damage_component.gd" id="2_ll0xw"]
[ext_resource type="Script" path="res://scripts/components/bullet.gd" id="3_keogl"] [ext_resource type="Script" path="res://scripts/components/bullet.gd" id="3_keogl"]
[sub_resource type="CircleShape2D" id="CircleShape2D_txsw8"] [sub_resource type="CircleShape2D" id="CircleShape2D_txsw8"]
@@ -26,7 +26,7 @@ position = Vector2(2.38419e-07, 2.38419e-07)
scale = Vector2(0.4, 0.4) scale = Vector2(0.4, 0.4)
[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")] [node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")]
script = ExtResource("2_qkwsu") script = ExtResource("2_ll0xw")
area2d = NodePath("..") area2d = NodePath("..")
[node name="BulletComponent" type="Node2D" parent="." node_paths=PackedStringArray("root", "area2d", "visibility_notifier", "timer")] [node name="BulletComponent" type="Node2D" parent="." node_paths=PackedStringArray("root", "area2d", "visibility_notifier", "timer")]

View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://dfwpha0d18dmn"] [gd_scene load_steps=5 format=3 uid="uid://dfwpha0d18dmn"]
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_rwgpm"] [ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_rwgpm"]
[ext_resource type="Script" path="res://scripts/components/damage.gd" id="2_3cgd2"] [ext_resource type="Script" path="res://scripts/components/damage_component.gd" id="2_cprue"]
[ext_resource type="Script" path="res://scripts/components/beam_component.gd" id="3_jlh0s"] [ext_resource type="Script" path="res://scripts/components/beam_component.gd" id="3_jlh0s"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ptfn7"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ptfn7"]
@@ -21,7 +21,7 @@ region_rect = Rect2(176, 64, 16, 16)
shape = SubResource("RectangleShape2D_ptfn7") shape = SubResource("RectangleShape2D_ptfn7")
[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")] [node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")]
script = ExtResource("2_3cgd2") script = ExtResource("2_cprue")
area2d = NodePath("..") area2d = NodePath("..")
[node name="BeamComponent" type="Node2D" parent="." node_paths=PackedStringArray("root", "sprite2d", "collision_shape")] [node name="BeamComponent" type="Node2D" parent="." node_paths=PackedStringArray("root", "sprite2d", "collision_shape")]

View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://d3lt4rhxduv44"] [gd_scene load_steps=5 format=3 uid="uid://d3lt4rhxduv44"]
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_l5x2w"] [ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_l5x2w"]
[ext_resource type="Script" path="res://scripts/components/damage.gd" id="2_68sgi"] [ext_resource type="Script" path="res://scripts/components/damage_component.gd" id="2_mxy0q"]
[ext_resource type="Script" path="res://scripts/components/beam_component.gd" id="3_mcbof"] [ext_resource type="Script" path="res://scripts/components/beam_component.gd" id="3_mcbof"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ptfn7"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ptfn7"]
@@ -23,7 +23,7 @@ region_filter_clip_enabled = true
shape = SubResource("RectangleShape2D_ptfn7") shape = SubResource("RectangleShape2D_ptfn7")
[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")] [node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")]
script = ExtResource("2_68sgi") script = ExtResource("2_mxy0q")
area2d = NodePath("..") area2d = NodePath("..")
[node name="BeamComponent" type="Node2D" parent="." node_paths=PackedStringArray("root", "sprite2d", "collision_shape")] [node name="BeamComponent" type="Node2D" parent="." node_paths=PackedStringArray("root", "sprite2d", "collision_shape")]

View File

@@ -1,14 +1,15 @@
[gd_scene load_steps=15 format=3 uid="uid://bwdlmualj6xbw"] [gd_scene load_steps=16 format=3 uid="uid://bwdlmualj6xbw"]
[ext_resource type="Shader" uid="uid://bs4xvm4qkurpr" path="res://shaders/hit_flash.tres" id="1_ep4yr"] [ext_resource type="Shader" uid="uid://bs4xvm4qkurpr" path="res://shaders/hit_flash.tres" id="1_ep4yr"]
[ext_resource type="Texture2D" uid="uid://xes6mt2dd5gu" path="res://sprites/robot_cutout.png" id="1_uh38l"] [ext_resource type="Texture2D" uid="uid://xes6mt2dd5gu" path="res://sprites/robot_cutout.png" id="1_uh38l"]
[ext_resource type="Script" path="res://scripts/components/health.gd" id="2_o170m"] [ext_resource type="Script" path="res://scripts/components/health.gd" id="2_o170m"]
[ext_resource type="Script" path="res://scripts/components/damage.gd" id="3_8jl3u"] [ext_resource type="Script" path="res://scripts/components/damage_component.gd" id="4_4eajk"]
[ext_resource type="Script" path="res://scripts/components/side_to_side_movement.gd" id="4_gbsq8"] [ext_resource type="Script" path="res://scripts/components/side_to_side_movement.gd" id="4_gbsq8"]
[ext_resource type="Script" path="res://scripts/components/periodic_shooting.gd" id="5_m03v0"] [ext_resource type="Script" path="res://scripts/components/periodic_shooting.gd" id="5_m03v0"]
[ext_resource type="Script" path="res://scripts/components/enemy_death.gd" id="6_6p3gr"] [ext_resource type="Script" path="res://scripts/components/enemy_death.gd" id="6_6p3gr"]
[ext_resource type="Script" path="res://scripts/components/flashing_component.gd" id="7_xsaiy"] [ext_resource type="Script" path="res://scripts/components/flashing_component.gd" id="7_xsaiy"]
[ext_resource type="Script" path="res://scripts/components/hit_component.gd" id="9_0qjr4"] [ext_resource type="Script" path="res://scripts/components/hit_component.gd" id="9_0qjr4"]
[ext_resource type="Script" path="res://scripts/components/status_effect_component.gd" id="10_5i27q"]
[ext_resource type="Script" path="res://scripts/components/fire_effect_component.gd" id="10_ej8vg"] [ext_resource type="Script" path="res://scripts/components/fire_effect_component.gd" id="10_ej8vg"]
[ext_resource type="Script" path="res://scripts/components/ice_effect_component.gd" id="11_pq0k7"] [ext_resource type="Script" path="res://scripts/components/ice_effect_component.gd" id="11_pq0k7"]
@@ -38,7 +39,7 @@ texture = ExtResource("1_uh38l")
script = ExtResource("2_o170m") script = ExtResource("2_o170m")
[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")] [node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")]
script = ExtResource("3_8jl3u") script = ExtResource("4_4eajk")
area2d = NodePath("../Hitbox") area2d = NodePath("../Hitbox")
[node name="SideToSideMovement" type="Node" parent="." node_paths=PackedStringArray("root", "sprite2d", "left_ray", "right_ray")] [node name="SideToSideMovement" type="Node" parent="." node_paths=PackedStringArray("root", "sprite2d", "left_ray", "right_ray")]
@@ -89,15 +90,16 @@ script = ExtResource("9_0qjr4")
sprite = NodePath("../Sprite2D") sprite = NodePath("../Sprite2D")
health_component = NodePath("../HealthComponent") health_component = NodePath("../HealthComponent")
[node name="FireEffectComponent" type="Node" parent="." node_paths=PackedStringArray("health_component", "root")] [node name="StatusEffectComponent" type="Node" parent="."]
script = ExtResource("10_5i27q")
[node name="FireEffectComponent" type="Node" parent="." node_paths=PackedStringArray("health_component", "status_effect_component", "root")]
script = ExtResource("10_ej8vg") script = ExtResource("10_ej8vg")
duration = 5.0
damage_per_second = 0.1
health_component = NodePath("../HealthComponent") health_component = NodePath("../HealthComponent")
status_effect_component = NodePath("../StatusEffectComponent")
root = NodePath("..") root = NodePath("..")
[node name="IceEffectComponent" type="Node" parent="." node_paths=PackedStringArray("side_to_side_movement", "periodic_shooting")] [node name="IceEffectComponent" type="Node" parent="." node_paths=PackedStringArray("status_effect_component")]
script = ExtResource("11_pq0k7") script = ExtResource("11_pq0k7")
duration = 3.0 components_to_disable = [NodePath("../SideToSideMovement"), NodePath("../PeriodicShootingComponent")]
side_to_side_movement = NodePath("../SideToSideMovement") status_effect_component = NodePath("../StatusEffectComponent")
periodic_shooting = NodePath("../PeriodicShootingComponent")

View File

@@ -1,8 +1,10 @@
[gd_scene load_steps=5 format=3 uid="uid://daau4j5hbklk0"] [gd_scene load_steps=7 format=3 uid="uid://daau4j5hbklk0"]
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_52l28"] [ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_52l28"]
[ext_resource type="Script" path="res://scripts/components/bullet.gd" id="2_hjcob"] [ext_resource type="Script" path="res://scripts/components/bullet.gd" id="2_hjcob"]
[ext_resource type="Script" path="res://scripts/components/damage.gd" id="3_3ylb6"] [ext_resource type="Script" path="res://scripts/components/damage_component.gd" id="3_sog2h"]
[ext_resource type="Resource" uid="uid://obodgnkhxuhe" path="res://resources/status_effect/fire.tres" id="4_xx5l4"]
[ext_resource type="Script" path="res://scripts/components/effect_inflictor_component.gd" id="5_ofrqk"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ar0xf"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ar0xf"]
size = Vector2(16, 10) size = Vector2(16, 10)
@@ -36,6 +38,10 @@ scale = Vector2(0.8, 0.5)
[node name="Timer" type="Timer" parent="."] [node name="Timer" type="Timer" parent="."]
[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")] [node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")]
script = ExtResource("3_3ylb6") script = ExtResource("3_sog2h")
area2d = NodePath("..") area2d = NodePath("..")
is_fire_brick = true status_effect_data = ExtResource("4_xx5l4")
[node name="EffectInflictorComponent" type="Node" parent="." node_paths=PackedStringArray("damage")]
script = ExtResource("5_ofrqk")
damage = NodePath("../DamageComponent")

View File

@@ -1,8 +1,10 @@
[gd_scene load_steps=5 format=3 uid="uid://bcmx07k12gcsc"] [gd_scene load_steps=7 format=3 uid="uid://bcmx07k12gcsc"]
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_xusxl"] [ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_xusxl"]
[ext_resource type="Script" path="res://scripts/components/bullet.gd" id="2_ilnf5"] [ext_resource type="Script" path="res://scripts/components/bullet.gd" id="2_ilnf5"]
[ext_resource type="Script" path="res://scripts/components/damage.gd" id="3_htddx"] [ext_resource type="Script" path="res://scripts/components/damage_component.gd" id="3_3yf4g"]
[ext_resource type="Resource" uid="uid://02l4nbnf2aft" path="res://resources/status_effect/ice.tres" id="4_da7hn"]
[ext_resource type="Script" path="res://scripts/components/effect_inflictor_component.gd" id="5_x7vqb"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ar0xf"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ar0xf"]
size = Vector2(16, 10) size = Vector2(16, 10)
@@ -36,6 +38,10 @@ scale = Vector2(0.8, 0.5)
[node name="Timer" type="Timer" parent="."] [node name="Timer" type="Timer" parent="."]
[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")] [node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")]
script = ExtResource("3_htddx") script = ExtResource("3_3yf4g")
area2d = NodePath("..") area2d = NodePath("..")
is_ice_brick = true status_effect_data = ExtResource("4_da7hn")
[node name="EffectInflictorComponent" type="Node" parent="." node_paths=PackedStringArray("damage")]
script = ExtResource("5_x7vqb")
damage = NodePath("../DamageComponent")

View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://c7ku0k8n55hjv"] [gd_scene load_steps=5 format=3 uid="uid://c7ku0k8n55hjv"]
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_brnkm"] [ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_brnkm"]
[ext_resource type="Script" path="res://scripts/components/damage.gd" id="2_l84sa"] [ext_resource type="Script" path="res://scripts/components/damage_component.gd" id="2_x12f0"]
[ext_resource type="Script" path="res://scripts/components/beam_component.gd" id="3_6pj0h"] [ext_resource type="Script" path="res://scripts/components/beam_component.gd" id="3_6pj0h"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ptfn7"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ptfn7"]
@@ -21,7 +21,7 @@ region_rect = Rect2(176, 64, 16, 16)
shape = SubResource("RectangleShape2D_ptfn7") shape = SubResource("RectangleShape2D_ptfn7")
[node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")] [node name="DamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d")]
script = ExtResource("2_l84sa") script = ExtResource("2_x12f0")
area2d = NodePath("..") area2d = NodePath("..")
[node name="BeamComponent" type="Node2D" parent="." node_paths=PackedStringArray("root", "sprite2d", "collision_shape")] [node name="BeamComponent" type="Node2D" parent="." node_paths=PackedStringArray("root", "sprite2d", "collision_shape")]

View File

@@ -0,0 +1,9 @@
[gd_resource type="Resource" script_class="StatusEffectDataResource" load_steps=2 format=3 uid="uid://obodgnkhxuhe"]
[ext_resource type="Script" path="res://scripts/resources/status_effect_data_resource.gd" id="1_r8ycx"]
[resource]
script = ExtResource("1_r8ycx")
effect_type = 1
duration = 5.0
damage_per_second = 0.25

View File

@@ -0,0 +1,9 @@
[gd_resource type="Resource" script_class="StatusEffectDataResource" load_steps=2 format=3 uid="uid://02l4nbnf2aft"]
[ext_resource type="Script" path="res://scripts/resources/status_effect_data_resource.gd" id="1_kqthd"]
[resource]
script = ExtResource("1_kqthd")
effect_type = 2
duration = 3.0
damage_per_second = 0.0

View File

@@ -3,8 +3,8 @@ extends Node
@export var damage: float = 0.25 @export var damage: float = 0.25
@export var area2d: Area2D @export var area2d: Area2D
@export var is_fire_brick: bool = false @export var status_effect_data: StatusEffectDataResource
@export var is_ice_brick: bool = false signal effect_inflicted(target: Node2D, effect: StatusEffectDataResource)
func _ready() -> void: func _ready() -> void:
@@ -23,18 +23,12 @@ func on_area2d_body_entered(body: Node2D) -> void:
if body.has_node("HealthComponent"): if body.has_node("HealthComponent"):
var health_component: HealthComponent = body.get_node("HealthComponent") var health_component: HealthComponent = body.get_node("HealthComponent")
var invulnerability_component: InvulnerabilityComponent = body.get_node_or_null("InvulnerabilityComponent") var invulnerability_component: InvulnerabilityComponent = body.get_node_or_null("InvulnerabilityComponent")
var fire_effect_component: FireEffectComponent = body.get_node_or_null("FireEffectComponent")
var ice_effect_component: IceEffectComponent = body.get_node_or_null("IceEffectComponent")
if invulnerability_component and invulnerability_component.is_invulnerable(): if invulnerability_component and invulnerability_component.is_invulnerable():
return return
if fire_effect_component and is_fire_brick: if status_effect_data.effect_type != StatusEffectComponent.EffectType.NONE:
fire_effect_component.activate() effect_inflicted.emit(body, status_effect_data)
return
if ice_effect_component and is_ice_brick:
ice_effect_component.activate()
return return
deal_damage(health_component) deal_damage(health_component)

View File

@@ -0,0 +1,22 @@
class_name EffectInflictorComponent
extends Node
@export var damage: DamageComponent
func _ready() -> void:
if not damage:
printerr("No damage component assigned!")
return
damage.effect_inflicted.connect(on_effect_inflicted)
func on_effect_inflicted(target: Node2D, effect: StatusEffectDataResource) -> void:
var status_effect_component: StatusEffectComponent = target.get_node_or_null("StatusEffectComponent")
if not status_effect_component:
return
status_effect_component.apply_effect(effect)

View File

@@ -1,56 +1,49 @@
class_name FireEffectComponent class_name FireEffectComponent
extends Node extends Node
@export var duration: float = 1.0
@export var damage_per_second: float = 1.0
@export var health_component: HealthComponent @export var health_component: HealthComponent
@export var status_effect_component: StatusEffectComponent
@export var root: Node2D @export var root: Node2D
var timer: Timer var data: StatusEffectDataResource = null
var should_deal_damage: bool = false var should_deal_damage: bool = false
var time_elapsed: float = 0.0 var time_elapsed: float = 0.0
func _ready() -> void: func _ready() -> void:
if not health_component: if not health_component:
health_component = root.get_node("HealthComponent") health_component = root.get_node("HealthComponent")
if not status_effect_component:
status_effect_component = root.get_node("StatusEffectComponent")
if not health_component: if not health_component:
printerr("No HealthComponent assigned!") printerr("No HealthComponent assigned!")
return return
if not status_effect_component:
printerr("No StatusEffectComponent assigned!")
return
timer = Timer.new() status_effect_component.effect_applied.connect(on_effect_applied)
timer.timeout.connect(on_timer_timeout) status_effect_component.effect_removed.connect(on_effect_removed)
prepare_timer()
add_child(timer)
func _process(delta: float) -> void: func _process(delta: float) -> void:
if not should_deal_damage or not health_component: if not should_deal_damage or not health_component or not data:
return return
time_elapsed += delta time_elapsed += delta
if time_elapsed >= 1.0: if time_elapsed >= 1.0:
health_component.decrease_health(damage_per_second) health_component.decrease_health(data.damage_per_second)
time_elapsed = 0.0 time_elapsed = 0.0
func on_timer_timeout() -> void: func on_effect_applied(effect_data: StatusEffectDataResource) -> void:
deactivate() if effect_data.effect_type == StatusEffectComponent.EffectType.FIRE:
data = effect_data
should_deal_damage = true
func activate() -> void: func on_effect_removed(effect_type: StatusEffectComponent.EffectType) -> void:
should_deal_damage = true if effect_type == StatusEffectComponent.EffectType.FIRE:
timer.start() data = null
should_deal_damage = false
func deactivate() -> void:
should_deal_damage = false
timer.stop()
func prepare_timer() -> void:
timer.set_wait_time(duration)
timer.set_one_shot(true)
timer.stop()
time_elapsed = 0.0

View File

@@ -1,52 +1,49 @@
class_name IceEffectComponent class_name IceEffectComponent
extends Node extends Node
@export var duration: float = 1.0 @export var components_to_disable: Array = []
@export var side_to_side_movement: SideToSideMovement @export var status_effect_component: StatusEffectComponent
@export var periodic_shooting: PeriodicShootingComponent
var timer: Timer var data: StatusEffectDataResource = null
var is_frozen: bool = false
var movement_speed: float = 0.0
func _ready() -> void: func _ready() -> void:
timer = Timer.new() if not status_effect_component:
timer.timeout.connect(on_timer_timeout) status_effect_component = get_node("StatusEffectComponent")
prepare_timer()
add_child(timer)
if side_to_side_movement: if not status_effect_component:
movement_speed = side_to_side_movement.speed printerr("No StatusEffectComponent assigned!")
func _process(_delta: float) -> void:
if not side_to_side_movement or not periodic_shooting:
return return
if is_frozen: status_effect_component.effect_applied.connect(on_effect_applied)
side_to_side_movement.process_mode = PROCESS_MODE_DISABLED status_effect_component.effect_removed.connect(on_effect_removed)
periodic_shooting.process_mode = PROCESS_MODE_DISABLED
else:
side_to_side_movement.process_mode = PROCESS_MODE_ALWAYS
periodic_shooting.process_mode = PROCESS_MODE_ALWAYS
func on_timer_timeout() -> void: func on_effect_applied(effect_data: StatusEffectDataResource) -> void:
deactivate() if effect_data.effect_type == StatusEffectComponent.EffectType.ICE:
data = effect_data
apply_freeze()
func activate() -> void: func on_effect_removed(effect_type: StatusEffectComponent.EffectType) -> void:
is_frozen = true if effect_type == StatusEffectComponent.EffectType.ICE:
timer.start() data = null
remove_freeze()
func deactivate() -> void: func apply_freeze() -> void:
is_frozen = false for component_path in components_to_disable:
timer.stop() var component: Node = get_node_or_null(component_path)
if not component:
continue
component.process_mode = PROCESS_MODE_DISABLED
func prepare_timer() -> void: func remove_freeze() -> void:
timer.set_wait_time(duration) for component_path in components_to_disable:
timer.set_one_shot(true) var component: Node = get_node_or_null(component_path)
timer.stop() if not component:
continue
component.process_mode = PROCESS_MODE_ALWAYS

View File

@@ -0,0 +1,46 @@
class_name StatusEffectComponent
extends Node
enum EffectType {
NONE,
FIRE,
ICE
}
var active_effect: StatusEffectDataResource = null
var timer: Timer
var is_active: bool = false
var time_elapsed: float = 0.0
signal effect_applied(effect_data: StatusEffectDataResource)
signal effect_removed(effect_type: EffectType)
func _ready() -> void:
timer = Timer.new()
timer.timeout.connect(on_timer_timeout)
add_child(timer)
func apply_effect(effect_data: StatusEffectDataResource) -> void:
if is_active:
return
is_active = true
active_effect = effect_data
prepare_timer()
effect_applied.emit(active_effect)
timer.start()
func remove_effect() -> void:
is_active = false
effect_removed.emit(active_effect.effect_type)
func on_timer_timeout() -> void:
remove_effect()
func prepare_timer() -> void:
timer.set_wait_time(active_effect.duration)
timer.set_one_shot(true)
timer.stop()

View File

@@ -1,4 +1,4 @@
class_name StompDamageComponent class_name StompDamageComponent
extends Node extends Node
@export var damage: float = 0.25 @export var damage: float = 0.25
@@ -44,4 +44,4 @@ func on_area2d_body_entered(body: Node2D) -> void:
damage_component.set_process(false) damage_component.set_process(false)
await get_tree().process_frame await get_tree().process_frame
damage_component.set_process(true) damage_component.set_process(true)

View File

@@ -0,0 +1,6 @@
class_name StatusEffectDataResource
extends Resource
@export var effect_type: StatusEffectComponent.EffectType = StatusEffectComponent.EffectType.NONE
@export var duration: float = 1.0
@export var damage_per_second: float = 0.25