Fire effect and ice effect

This commit is contained in:
2025-03-01 20:30:35 +01:00
parent a9f8fb717e
commit 9054777a05
7 changed files with 220 additions and 3 deletions

View File

@@ -3,6 +3,8 @@ extends Node
@export var damage: float = 0.25
@export var area2d: Area2D
@export var is_fire_brick: bool = false
@export var is_ice_brick: bool = false
func _ready() -> void:
@@ -21,10 +23,20 @@ func on_area2d_body_entered(body: Node2D) -> void:
if body.has_node("HealthComponent"):
var health_component: HealthComponent = body.get_node("HealthComponent")
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():
return
if fire_effect_component and is_fire_brick:
fire_effect_component.activate()
return
if ice_effect_component and is_ice_brick:
ice_effect_component.activate()
return
deal_damage(health_component)
if invulnerability_component:

View File

@@ -0,0 +1,56 @@
class_name FireEffectComponent
extends Node
@export var duration: float = 1.0
@export var damage_per_second: float = 1.0
@export var health_component: HealthComponent
@export var root: Node2D
var timer: Timer
var should_deal_damage: bool = false
var time_elapsed: float = 0.0
func _ready() -> void:
if not health_component:
health_component = root.get_node("HealthComponent")
if not health_component:
printerr("No HealthComponent assigned!")
return
timer = Timer.new()
timer.timeout.connect(on_timer_timeout)
prepare_timer()
add_child(timer)
func _process(delta: float) -> void:
if not should_deal_damage or not health_component:
return
time_elapsed += delta
if time_elapsed >= 1.0:
health_component.decrease_health(damage_per_second)
time_elapsed = 0.0
func on_timer_timeout() -> void:
deactivate()
func activate() -> void:
should_deal_damage = true
timer.start()
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

@@ -0,0 +1,52 @@
class_name IceEffectComponent
extends Node
@export var duration: float = 1.0
@export var side_to_side_movement: SideToSideMovement
@export var periodic_shooting: PeriodicShootingComponent
var timer: Timer
var is_frozen: bool = false
var movement_speed: float = 0.0
func _ready() -> void:
timer = Timer.new()
timer.timeout.connect(on_timer_timeout)
prepare_timer()
add_child(timer)
if side_to_side_movement:
movement_speed = side_to_side_movement.speed
func _process(_delta: float) -> void:
if not side_to_side_movement or not periodic_shooting:
return
if is_frozen:
side_to_side_movement.process_mode = PROCESS_MODE_DISABLED
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:
deactivate()
func activate() -> void:
is_frozen = true
timer.start()
func deactivate() -> void:
is_frozen = false
timer.stop()
func prepare_timer() -> void:
timer.set_wait_time(duration)
timer.set_one_shot(true)
timer.stop()