Life bar has damage lag

This commit is contained in:
Rob Kelly 2024-11-18 12:06:43 -07:00
parent 96c73c5587
commit 7c7458be65
9 changed files with 159 additions and 24 deletions

Binary file not shown.

BIN
assets/ui/lifebar_fill_damage.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dv8757eh7bgmm"
path="res://.godot/imported/lifebar_fill_damage.png-844591e686129d7c89c44d44c5c8df44.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/ui/lifebar_fill_damage.png"
dest_files=["res://.godot/imported/lifebar_fill_damage.png-844591e686129d7c89c44d44c5c8df44.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@ -79,16 +79,6 @@ func _finish_scene_load(instance: Node) -> void:
func _process(_delta: float) -> void: func _process(_delta: float) -> void:
# REMOVEME
if Input.is_action_just_pressed("debug_1"):
viewport.hit_lag(1)
if Input.is_action_just_pressed("debug_2"):
viewport.hit_lag_small()
if Input.is_action_just_pressed("debug_3"):
viewport.hit_lag_big()
if Input.is_action_just_pressed("debug_4"):
viewport.hit_lag_huge()
if _loading_resources and not loading_screen.visible: if _loading_resources and not loading_screen.visible:
loader_transition.play("fade_in") loader_transition.play("fade_in")

View File

@ -31,6 +31,9 @@ const WASTED_BALL_RETURN_DELAY := 3.5
## Shots above this threshold trigger a "big power" effect ## Shots above this threshold trigger a "big power" effect
const BIG_POWER_THRESHOLD := 0.7 const BIG_POWER_THRESHOLD := 0.7
## Amount of life lost when landing in water
const WATER_DAMAGE := 10.0
## In Driving Range mode, the ball can be retrieved in the shot phase. ## In Driving Range mode, the ball can be retrieved in the shot phase.
@export var driving_range := false @export var driving_range := false
@ -500,6 +503,7 @@ func _on_ball_entered_water() -> void:
if phase == Phase.SHOT: if phase == Phase.SHOT:
physics_ball.freeze = true physics_ball.freeze = true
hud.play_wasted_animation() hud.play_wasted_animation()
player.life -= WATER_DAMAGE
ball_return_timer.start(WASTED_BALL_RETURN_DELAY) ball_return_timer.start(WASTED_BALL_RETURN_DELAY)

View File

@ -0,0 +1,22 @@
@tool
extends TextureProgressBar
@export var damage_delay := 1.0
@export var damage_tween_time := 0.4
@onready var damage_bar: TextureProgressBar = %DamageBar
@onready var damage_update_timer: Timer = $DamageUpdateTimer
func _on_value_changed(_value: float) -> void:
damage_update_timer.start(damage_delay)
func _on_damage_update_timer_timeout() -> void:
var tween := get_tree().create_tween()
(
tween
. tween_property(damage_bar, "value", value, damage_tween_time)
. set_trans(Tween.TRANS_CUBIC)
. set_ease(Tween.EASE_OUT)
)

View File

@ -0,0 +1,46 @@
[gd_scene load_steps=5 format=3 uid="uid://dmciuk3pbjsae"]
[ext_resource type="Texture2D" uid="uid://dtdqninlnu10o" path="res://assets/ui/lifebar_fill_grey.png" id="1_nhls1"]
[ext_resource type="Script" path="res://src/ui/shot_hud/life_bar/life_bar.gd" id="2_6jpmf"]
[ext_resource type="Texture2D" uid="uid://bvwh0yunmvirp" path="res://assets/ui/lifebar_patch.png" id="3_8s5ot"]
[ext_resource type="Texture2D" uid="uid://dv8757eh7bgmm" path="res://assets/ui/lifebar_fill_damage.png" id="4_ohduq"]
[node name="LifeBar" type="TextureProgressBar"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
step = 0.01
nine_patch_stretch = true
stretch_margin_left = 32
stretch_margin_top = 16
stretch_margin_right = 32
stretch_margin_bottom = 16
texture_progress = ExtResource("1_nhls1")
script = ExtResource("2_6jpmf")
damage_tween_time = 0.6
[node name="DamageBar" type="TextureProgressBar" parent="."]
unique_name_in_owner = true
show_behind_parent = true
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
step = 0.01
nine_patch_stretch = true
stretch_margin_left = 32
stretch_margin_top = 16
stretch_margin_right = 32
stretch_margin_bottom = 16
texture_under = ExtResource("3_8s5ot")
texture_progress = ExtResource("4_ohduq")
tint_progress = Color(0.9, 0, 0, 1)
[node name="DamageUpdateTimer" type="Timer" parent="."]
[connection signal="value_changed" from="." to="." method="_on_value_changed"]
[connection signal="timeout" from="DamageUpdateTimer" to="." method="_on_damage_update_timer_timeout"]

View File

@ -1,6 +1,13 @@
class_name ShotHUD extends Control class_name ShotHUD extends Control
## HUD for main gameplay loop ## HUD for main gameplay loop
## Scale factor for the life bar rumble intensity on taking damage
const LIFE_BAR_DAMAGE_RUMBLE_SCALE := 0.2
## Time it takes to dampen the life bar rumble on taking damage, in seconds
const LIFE_BAR_DAMAGE_RUMBLE_TIME := 0.2
var _life_signal: Signal
@onready var power_bar: TextureProgressBar = %PowerBar @onready var power_bar: TextureProgressBar = %PowerBar
@onready var curve_bar: ProgressBar = %CurveBar @onready var curve_bar: ProgressBar = %CurveBar
@onready var life_bar: TextureProgressBar = %LifeBar @onready var life_bar: TextureProgressBar = %LifeBar
@ -17,6 +24,8 @@ class_name ShotHUD extends Control
@onready var _player_name: Label = %PlayerName @onready var _player_name: Label = %PlayerName
@onready var _life_bar_rumbler: Rumbler = %LifeBarRumbler
@onready var _state: AnimationNodeStateMachinePlayback = hud_state_machine["parameters/playback"] @onready var _state: AnimationNodeStateMachinePlayback = hud_state_machine["parameters/playback"]
@ -28,6 +37,14 @@ func set_state_for_player(player: WorldPlayer) -> void:
# TODO animate on life loss? # TODO animate on life loss?
life_bar.value = player.life life_bar.value = player.life
life_bar.tint_progress = player.color life_bar.tint_progress = player.color
# TODO this is soooooo wack...
# TODO we should just revert to having distinct ShotHUDs for each player
if _life_signal and _life_signal.is_connected(set_life_value):
_life_signal.disconnect(set_life_value)
_life_signal = player.on_life_changed
_life_signal.connect(set_life_value)
# TODO special equipment # TODO special equipment
# TODO abilities # TODO abilities
@ -70,3 +87,24 @@ func play_nice_animation() -> void:
func play_wasted_animation() -> void: func play_wasted_animation() -> void:
_wasted_animation.play("display") _wasted_animation.play("display")
## Set the value of the life bar, potentially playing some kind of effect in response.
##
## To set the life bar without triggering an effect, set it directly with `life_bar.value`
func set_life_value(new_value: float) -> void:
var difference := new_value - life_bar.value
if difference < 0:
# Taking damage
_life_bar_rumbler.intensity = LIFE_BAR_DAMAGE_RUMBLE_SCALE * abs(difference)
var tween := get_tree().create_tween()
(
tween
. tween_property(_life_bar_rumbler, "intensity", 0, LIFE_BAR_DAMAGE_RUMBLE_TIME)
. set_trans(Tween.TRANS_CUBIC)
)
elif difference > 0:
# Restoring health
# TODO: something for this?
pass
life_bar.value = new_value

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=34 format=3 uid="uid://c4ifdiohng830"] [gd_scene load_steps=33 format=3 uid="uid://c4ifdiohng830"]
[ext_resource type="Script" path="res://src/ui/shot_hud/shot_hud.gd" id="1_x5b4c"] [ext_resource type="Script" path="res://src/ui/shot_hud/shot_hud.gd" id="1_x5b4c"]
[ext_resource type="Shader" path="res://src/shaders/canvas_retro.gdshader" id="1_ybxxp"] [ext_resource type="Shader" path="res://src/shaders/canvas_retro.gdshader" id="1_ybxxp"]
@ -8,8 +8,7 @@
[ext_resource type="Texture2D" uid="uid://76fjx2ukavqe" path="res://assets/ui/power_gauge_fill.png" id="5_3i1yq"] [ext_resource type="Texture2D" uid="uid://76fjx2ukavqe" path="res://assets/ui/power_gauge_fill.png" id="5_3i1yq"]
[ext_resource type="Texture2D" uid="uid://4a8tvjgwegv3" path="res://assets/ui/power_gauge_tab.png" id="6_sw48q"] [ext_resource type="Texture2D" uid="uid://4a8tvjgwegv3" path="res://assets/ui/power_gauge_tab.png" id="6_sw48q"]
[ext_resource type="FontFile" uid="uid://dsa0oh7c0h4pu" path="res://assets/fonts/Racing_Sans_One/RacingSansOne-Regular.ttf" id="8_bejx4"] [ext_resource type="FontFile" uid="uid://dsa0oh7c0h4pu" path="res://assets/fonts/Racing_Sans_One/RacingSansOne-Regular.ttf" id="8_bejx4"]
[ext_resource type="Texture2D" uid="uid://bvwh0yunmvirp" path="res://assets/ui/lifebar_patch.png" id="9_4f1d7"] [ext_resource type="PackedScene" uid="uid://dmciuk3pbjsae" path="res://src/ui/shot_hud/life_bar/life_bar.tscn" id="9_w1fiw"]
[ext_resource type="Texture2D" uid="uid://dtdqninlnu10o" path="res://assets/ui/lifebar_fill_grey.png" id="10_130v7"]
[sub_resource type="Animation" id="Animation_3xds6"] [sub_resource type="Animation" id="Animation_3xds6"]
resource_name = "RESET" resource_name = "RESET"
@ -276,7 +275,7 @@ _data = {
[sub_resource type="ShaderMaterial" id="ShaderMaterial_afsun"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_afsun"]
shader = ExtResource("1_ybxxp") shader = ExtResource("1_ybxxp")
shader_parameter/change_color_depth = true shader_parameter/change_color_depth = true
shader_parameter/target_color_depth = 3 shader_parameter/target_color_depth = 4
shader_parameter/dithering = true shader_parameter/dithering = true
shader_parameter/scale_resolution = true shader_parameter/scale_resolution = true
shader_parameter/target_resolution_scale = 3 shader_parameter/target_resolution_scale = 3
@ -698,16 +697,15 @@ theme_override_fonts/font = ExtResource("8_bejx4")
theme_override_font_sizes/font_size = 32 theme_override_font_sizes/font_size = 32
text = "PLAYER NAME" text = "PLAYER NAME"
[node name="LifeBar" type="TextureProgressBar" parent="SouthWest/VBoxContainer"] [node name="MarginContainer" type="MarginContainer" parent="SouthWest/VBoxContainer"]
layout_mode = 2
[node name="LifeBarRumbler" type="Control" parent="SouthWest/VBoxContainer/MarginContainer"]
unique_name_in_owner = true unique_name_in_owner = true
custom_minimum_size = Vector2(0, 48) custom_minimum_size = Vector2(0, 48)
layout_mode = 2 layout_mode = 2
min_value = -4.0 script = ExtResource("3_6groq")
step = 0.01
nine_patch_stretch = true [node name="LifeBar" parent="SouthWest/VBoxContainer/MarginContainer/LifeBarRumbler" instance=ExtResource("9_w1fiw")]
stretch_margin_left = 32 unique_name_in_owner = true
stretch_margin_top = 16 layout_mode = 1
stretch_margin_right = 32
stretch_margin_bottom = 16
texture_under = ExtResource("9_4f1d7")
texture_progress = ExtResource("10_130v7")