Skip to content

Commit

Permalink
Add HurtboxComponent to FadingGhostComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
Brakistad committed Feb 4, 2024
1 parent 0610fe7 commit ec0778c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
39 changes: 22 additions & 17 deletions scenes/component/fading_ghost_component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
5 changes: 4 additions & 1 deletion scenes/component/hurtbox_component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
9 changes: 5 additions & 4 deletions scenes/game_object/ghost_enemy/ghost_enemy.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion scenes/game_object/player/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ec0778c

Please sign in to comment.