From ec0778c524f7b8f44d24197db8d633912b8e236b Mon Sep 17 00:00:00 2001 From: brakistad Date: Sun, 4 Feb 2024 23:04:46 +0100 Subject: [PATCH] Add HurtboxComponent to FadingGhostComponent --- scenes/component/fading_ghost_component.gd | 39 +++++++++++-------- scenes/component/hurtbox_component.gd | 5 ++- .../game_object/ghost_enemy/ghost_enemy.tscn | 9 +++-- scenes/game_object/player/player.tscn | 2 +- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/scenes/component/fading_ghost_component.gd b/scenes/component/fading_ghost_component.gd index 9caf170..2919440 100644 --- a/scenes/component/fading_ghost_component.gd +++ b/scenes/component/fading_ghost_component.gd @@ -4,6 +4,7 @@ extends Node @export var fade_material: ShaderMaterial @export var velocity_component: VelocityComponent @export var health_bar_component: HealthBarComponent +@export var hurt_box_component: HurtboxComponent @export var velocity_treshold: float = 50.0 @onready var timer_instance :Timer @@ -13,30 +14,34 @@ var is_faded: bool = false func _ready(): - sprite.material = fade_material - velocity_component.set_velocity_treshold(velocity_treshold) - velocity_component.signal_velocity_treshold_reached.connect(on_velocity_treshold_reached) - velocity_component.signal_velocity_treshold_lost.connect(on_velocity_treshold_lost) - + sprite.material = fade_material + velocity_component.set_velocity_treshold(velocity_treshold) + velocity_component.signal_velocity_treshold_reached.connect(on_velocity_treshold_reached) + velocity_component.signal_velocity_treshold_lost.connect(on_velocity_treshold_lost) + func fade_invinsible(percent: float, duration_variance: float = 0.0): - if fade_in_out_tween != null && fade_in_out_tween.is_valid(): - fade_in_out_tween.kill() - fade_in_out_tween = create_tween() - fade_in_out_tween.tween_property(sprite.material, "shader_parameter/invisibilty", percent, 0.2 + duration_variance) + if fade_in_out_tween != null && fade_in_out_tween.is_valid(): + fade_in_out_tween.kill() + fade_in_out_tween = create_tween() + fade_in_out_tween.tween_property(sprite.material, "shader_parameter/invisibilty", percent, 0.2 + duration_variance) func fade_in(percent: float, duration_variance: float = 0.0): - fade_invinsible(percent, duration_variance) - health_bar_component.health_bar.visible = true - is_faded = false + # becomes visible + fade_invinsible(percent, duration_variance) + health_bar_component.health_bar.visible = true + hurt_box_component.disabled = false + is_faded = false func fade_out(percent: float, duration_variance: float = 0.0): - fade_invinsible(percent, duration_variance) - health_bar_component.health_bar.visible = false - is_faded = true + # becomes invinsible + fade_invinsible(percent, duration_variance) + health_bar_component.health_bar.visible = false + hurt_box_component.disabled = true + is_faded = true func on_velocity_treshold_reached(): - fade_in( 0.2 - randf() * .2, randf() * 0.5) + fade_in( 0.2 - randf() * .2, randf() * 0.5) func on_velocity_treshold_lost(): - fade_out( .8 + randf() * .2, randf() * 0.5) + fade_out( .8 + randf() * .2, randf() * 0.5) diff --git a/scenes/component/hurtbox_component.gd b/scenes/component/hurtbox_component.gd index e53dd05..8a7afa6 100644 --- a/scenes/component/hurtbox_component.gd +++ b/scenes/component/hurtbox_component.gd @@ -6,7 +6,7 @@ signal hit @export var health_component: HealthComponent var floating_text_scene = preload("res://scenes/ui/floating_text.tscn") - +var disabled = false func _ready(): area_entered.connect(on_area_entered) @@ -19,6 +19,9 @@ func on_area_entered(other_area: Area2D): if health_component == null: return + if disabled: + return + var hitbox_component = other_area as HitboxComponent health_component.damage(hitbox_component.damage) diff --git a/scenes/game_object/ghost_enemy/ghost_enemy.tscn b/scenes/game_object/ghost_enemy/ghost_enemy.tscn index cc8fcf8..031969a 100644 --- a/scenes/game_object/ghost_enemy/ghost_enemy.tscn +++ b/scenes/game_object/ghost_enemy/ghost_enemy.tscn @@ -220,8 +220,8 @@ max_health = 15.0 [node name="VelocityComponent" parent="." instance=ExtResource("2_71ido")] max_speed = 130 -distancing = 80.0 -randomize_distancing = 80.0 +distancing = 100.0 +randomize_distancing = 100.0 [node name="VialDropComponent" parent="." node_paths=PackedStringArray("health_component") instance=ExtResource("3_4gxpp")] drop_percent = 0.7 @@ -232,12 +232,13 @@ health_component = NodePath("../HealthComponent") sprite = NodePath("../Visuals/Sprite2D") hit_flash_material = SubResource("ShaderMaterial_vnoy4") -[node name="FadingGhostComponent" parent="." node_paths=PackedStringArray("sprite", "velocity_component", "health_bar_component") instance=ExtResource("7_efgln")] +[node name="FadingGhostComponent" parent="." node_paths=PackedStringArray("sprite", "velocity_component", "health_bar_component", "hurt_box_component") instance=ExtResource("7_efgln")] sprite = NodePath("../Visuals/Sprite2D") fade_material = SubResource("ShaderMaterial_ey5la") velocity_component = NodePath("../VelocityComponent") health_bar_component = NodePath("../HealthBarComponent") -velocity_treshold = 100.0 +hurt_box_component = NodePath("../HurtboxComponent") +velocity_treshold = 70.0 [node name="HealthBarComponent" parent="." node_paths=PackedStringArray("health_component") instance=ExtResource("6_qtpm6")] health_component = NodePath("../HealthComponent") diff --git a/scenes/game_object/player/player.tscn b/scenes/game_object/player/player.tscn index 1a33aaa..1ff2a6b 100644 --- a/scenes/game_object/player/player.tscn +++ b/scenes/game_object/player/player.tscn @@ -132,7 +132,7 @@ libraries = { } [node name="VelocityComponent" parent="." instance=ExtResource("2_6ompf")] -max_speed = 80 +max_speed = 85 acceleration = 25.0 sprint_speed_percent = 1.5