18 lines
576 B
GDScript
18 lines
576 B
GDScript
extends StaticBody2D
|
|
|
|
const DAMAGE_POPUP_SCENE := preload("res://scenes/game/damage_popup.tscn")
|
|
|
|
var total_damage_received := 0.0
|
|
|
|
func take_damage(amount: float) -> void:
|
|
total_damage_received += amount
|
|
var popup := DAMAGE_POPUP_SCENE.instantiate() as Label
|
|
popup.text = "-%s DMG" % _format_damage(amount)
|
|
popup.global_position = global_position + Vector2(randf_range(-18.0, 18.0), -34.0)
|
|
get_parent().add_child(popup)
|
|
|
|
func _format_damage(amount: float) -> String:
|
|
if is_equal_approx(amount, roundf(amount)):
|
|
return str(int(roundf(amount)))
|
|
return "%.1f" % amount
|