diff --git a/objects/brick_player.tscn b/objects/brick_player.tscn index 511b678..789adfa 100644 --- a/objects/brick_player.tscn +++ b/objects/brick_player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=15 format=3 uid="uid://bqi5s710xb1ju"] +[gd_scene load_steps=16 format=3 uid="uid://bqi5s710xb1ju"] [ext_resource type="Script" path="res://scripts/player.gd" id="1_8j4h4"] [ext_resource type="Texture2D" uid="uid://b7gp0gqvkv8j4" path="res://sprites/MrBrick_base.png" id="2_bc55y"] @@ -11,7 +11,8 @@ [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="PackedScene" uid="uid://bymro4t7angv5" path="res://objects/brick.tscn" id="11_qutq2"] -[ext_resource type="Script" path="res://scripts/components/StompDamageComponent.gd" id="12_0nvxt"] +[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"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_hdsg1"] size = Vector2(16, 31) @@ -86,10 +87,28 @@ timer = NodePath("../ThrowTimer") [node name="ThrowTimer" type="Timer" parent="."] [node name="StompDamageComponent" type="Node" parent="." node_paths=PackedStringArray("area2d", "root")] -script = ExtResource("12_0nvxt") +script = ExtResource("12_payr4") damage = 4.0 area2d = NodePath("../StompDamageArea") root = NodePath("..") +[node name="FlashingComponent Base" type="Node" parent="." node_paths=PackedStringArray("sprite", "health_component")] +script = ExtResource("13_hrtyn") +sprite = NodePath("../Root/Base") +flash_duration = 1.0 +health_component = NodePath("../HealthComponent") + +[node name="FlashingComponent LEye" type="Node" parent="." node_paths=PackedStringArray("sprite", "health_component")] +script = ExtResource("13_hrtyn") +sprite = NodePath("../Root/Left Eye") +flash_duration = 1.0 +health_component = NodePath("../HealthComponent") + +[node name="FlashingComponent REye" type="Node" parent="." node_paths=PackedStringArray("sprite", "health_component")] +script = ExtResource("13_hrtyn") +sprite = NodePath("../Root/Right Eye") +flash_duration = 1.0 +health_component = NodePath("../HealthComponent") + [connection signal="on_death" from="HealthComponent" to="PlayerDeathComponent" method="_on_health_component_on_death"] [connection signal="on_health_change" from="HealthComponent" to="KnockbackComponent" method="_on_health_component_on_health_change"] diff --git a/objects/enemy.tscn b/objects/enemy.tscn index 8a1a926..50fb05d 100644 --- a/objects/enemy.tscn +++ b/objects/enemy.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://bwdlmualj6xbw"] +[gd_scene load_steps=10 format=3 uid="uid://bwdlmualj6xbw"] [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"] @@ -6,6 +6,7 @@ [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/enemy_death.gd" id="6_6p3gr"] +[ext_resource type="Script" path="res://scripts/components/flashing_component.gd" id="7_xsaiy"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_pwwji"] size = Vector2(18, 27) @@ -65,3 +66,8 @@ position = Vector2(-16, 13) [node name="Right Ray" type="RayCast2D" parent="."] position = Vector2(16, 13) + +[node name="FlashingComponent" type="Node" parent="." node_paths=PackedStringArray("sprite", "health_component")] +script = ExtResource("7_xsaiy") +sprite = NodePath("../Sprite2D") +health_component = NodePath("../HealthComponent") diff --git a/scripts/components/flashing_component.gd b/scripts/components/flashing_component.gd new file mode 100644 index 0000000..a3134a3 --- /dev/null +++ b/scripts/components/flashing_component.gd @@ -0,0 +1,55 @@ +class_name FlashingComponent +extends Node + +@export var sprite: Node2D +@export var flash_duration: float = 0.5 +@export var flash_time: float = 0.1 +@export var use_modulate: bool = true +@export var health_component: HealthComponent + +var tween: Tween + + +func _ready() -> void: + if health_component: + health_component.on_health_change.connect(on_health_change) + health_component.on_death.connect(on_death) + + if not sprite: + printerr("No sprite assigned!") + return + + +func start_flashing() -> void: + if not sprite: + return + + if tween: + tween.kill() + + tween = create_tween() + tween.set_parallel(false) + + var flashes: int = int(flash_duration / flash_time) + for i in range(flashes): + var opacity: float = 0.3 if i % 2 == 0 else 1.0 + tween.tween_property(sprite, "modulate:a" if use_modulate else "visible", opacity if use_modulate else float(i % 2 == 0), flash_time) + + tween.tween_callback(stop_flashing) + + +func stop_flashing() -> void: + if use_modulate: + sprite.modulate.a = 1.0 + else: + sprite.visible = true + + +func on_health_change(delta: float, _total_health: float) -> void: + if delta < 0: + start_flashing() + + +func on_death() -> void: + stop_flashing() + \ No newline at end of file