🐛 fix health display

This commit is contained in:
anyreso 2024-05-11 15:44:35 -04:00
parent 81c4212c2e
commit c26b281b96
5 changed files with 13 additions and 12 deletions

View file

@ -17,7 +17,7 @@ class_name ExplosiveDamageComponent extends Area3D
## Emitted when the scale tween is finished
signal finished
@export var damage : int = 35
@export var damage : float = .35
@export var impulse_force : int = 1000
var damage_dealer : MatchParticipantComponent

View file

@ -14,8 +14,8 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
class_name HealthComponent extends Area3D
@export var max_health : float = 100.0
@export var health : float = 100.0:
@export var max_health : float = 1.
@export var health : float = 1.:
set(value):
health = value
health_changed.emit(value)

View file

@ -38,7 +38,7 @@ func _physics_process(delta : float) -> void:
if collider is Player:
if is_multiplayer_authority():
assert(shooter)
collider.health_component.damage.rpc(18, shooter.player_id, shooter.team_id)
collider.health_component.damage.rpc(.1, shooter.player_id, shooter.team_id)
queue_free()
## This method is a parameterized constructor for the [ChainGunProjectile] scene of the [ChainGun]

View file

@ -25,8 +25,8 @@ class_name HUD extends CanvasLayer
@export var _energy_bar : ProgressBar
func _ready() -> void:
_update_health_bar(100.)
_update_energy_bar(100.)
_update_health_bar(1.)
_update_energy_bar(1.)
func _update_energy_bar(energy : float) -> void:
_energy_bar.value = energy
@ -146,7 +146,8 @@ layout_mode = 2
mouse_filter = 2
theme_override_styles/background = ExtResource("1_gmv44")
theme_override_styles/fill = ExtResource("2_6ejsl")
value = 60.0
max_value = 1.0
value = 1.0
show_percentage = false
[node name="EnergyBar" type="ProgressBar" parent="MarginContainer/HBoxContainer/VBoxContainer"]

View file

@ -15,7 +15,7 @@
extends GutTest
var _subject : HealthComponent
const TEST_MAX_HEALTH : float = 100.0
const TEST_MAX_HEALTH : float = 1.
const TEST_PLAYER_ID : int = 1
const TEST_TEAM_ID : int = 1
@ -36,17 +36,17 @@ func test_that_it_has_max_health_when_ready() -> void:
assert_eq(_subject.health, _subject.max_health)
func test_that_it_takes_damage_from_opponent_team() -> void:
var damage_amount : float = 10.0
var damage_amount : float = .1
_subject.damage(damage_amount, -1, -1)
assert_eq(_subject.health, TEST_MAX_HEALTH - damage_amount)
func test_that_it_takes_no_damage_from_same_team() -> void:
var damage_amount : float = 10.0
var damage_amount : float = .1
_subject.damage(damage_amount, -1, TEST_TEAM_ID)
assert_eq(_subject.health, TEST_MAX_HEALTH)
func test_that_it_can_self_damage() -> void:
var damage_amount : float = 10.0
var damage_amount : float = .1
_subject.damage(damage_amount, TEST_PLAYER_ID, TEST_TEAM_ID)
assert_eq(_subject.health, TEST_MAX_HEALTH - damage_amount)
@ -59,7 +59,7 @@ func test_that_it_emits_health_zeroed() -> void:
assert_signal_emitted_with_parameters(_subject, 'health_zeroed', [-1])
func test_that_it_heals_fully() -> void:
_subject.health = 10
_subject.health = .1
_subject.heal_full()
assert_eq(_subject.health, TEST_MAX_HEALTH)