Example damage label

This commit is contained in:
2026-01-11 20:08:44 -06:00
parent 561ab5a983
commit 7defac68c4
11 changed files with 109 additions and 25 deletions

View File

@@ -36,13 +36,13 @@ var luck:int
# Equipment
# Signals
signal healthChanged(difference:int)
signal healthChanged(difference:int, crit:bool)
signal mpChanged(difference:int)
signal statusChanged(oldStatus:Status, newStatus:Status)
func _init(params:Dictionary) -> void:
self.maxHealth = params.get('max_health', 100)
self.maxMp = params.get('max_mp', 50)
self.maxHealth = params.get('maxHealth', 100)
self.maxMp = params.get('maxMp', 50)
self.attack = params.get('attack', 10)
self.defense = params.get('defense', 5)
self.speed = params.get('speed', 5)
@@ -54,12 +54,12 @@ func _init(params:Dictionary) -> void:
self.health = self.maxHealth
self.mp = self.maxMp
func damage(amount:int) -> void:
func damage(amount:int, crit:bool) -> void:
assert(amount > 0)
if status == Status.DEAD:
return
health = max(health - amount, 0)
healthChanged.emit(-amount)
healthChanged.emit(-amount, crit)
if health == 0:
var oldStatus = status
status = Status.DEAD
@@ -70,7 +70,7 @@ func heal(amount:int) -> void:
if status == Status.DEAD:
return
health = min(health + amount, maxHealth)
healthChanged.emit(amount)
healthChanged.emit(amount, false)
func revive(health:int) -> void:
assert(health > 0)

View File

@@ -1,18 +1,25 @@
class_name BattleFighterScene extends Node3D
@export var battlePosition:BattleSingleton.BattlePosition = BattleSingleton.BattlePosition.LEFT_MIDDLE_FRONT
@export var damageLabels:Node3D
@export var damageLabelPreset:PackedScene
var currentFighter:BattleFighter = null
func _getFighter() -> BattleFighter:
return BATTLE.getFighterAtPosition(self.battlePosition)
func _updateFighter() -> void:
var fighter = _getFighter()
if currentFighter != null:
currentFighter.healthChanged.disconnect(onDamageTaken)
if fighter == null:
currentFighter = _getFighter()
if currentFighter == null:
self.visible = false
return
# Set up the visual representation of the fighter here
currentFighter.healthChanged.connect(onDamageTaken)
self.visible = true
func _enter_tree() -> void:
@@ -24,3 +31,7 @@ func _exit_tree() -> void:
func onFightersChanged() -> void:
_updateFighter()
func onDamageTaken(amount:int, crit:bool) -> void:
var damageLabel = damageLabelPreset.instantiate() as Label3D
damageLabel.showDamage(damageLabels, amount, crit)

View File

@@ -1,15 +1,18 @@
[gd_scene load_steps=5 format=3 uid="uid://d1xyb0hdf1yeh"]
[gd_scene load_steps=6 format=3 uid="uid://d1xyb0hdf1yeh"]
[ext_resource type="Script" uid="uid://bgycdhsouwhwt" path="res://battle/fighter/BattleFighterScene.gd" id="1_veb1i"]
[ext_resource type="SpriteFrames" uid="uid://cqqkm34a46ri6" path="res://battle/fighter/idk/green_dragon_frames.tres" id="2_e55p4"]
[ext_resource type="PackedScene" uid="uid://baxswkivvo5rs" path="res://battle/ui/DamageLabel.tscn" id="2_lciku"]
[sub_resource type="BoxMesh" id="BoxMesh_veb1i"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_e55p4"]
shading_mode = 0
[node name="BattleFighterScene" type="Node3D"]
[node name="BattleFighterScene" type="Node3D" node_paths=PackedStringArray("damageLabels")]
script = ExtResource("1_veb1i")
damageLabels = NodePath("Labels")
damageLabelPreset = ExtResource("2_lciku")
metadata/_custom_type_script = "uid://bgycdhsouwhwt"
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
@@ -18,6 +21,9 @@ mesh = SubResource("BoxMesh_veb1i")
surface_material_override/0 = SubResource("StandardMaterial3D_e55p4")
[node name="AnimatedSprite3D" type="AnimatedSprite3D" parent="."]
billboard = 2
sprite_frames = ExtResource("2_e55p4")
animation = &"idle"
frame_progress = 0.746159
[node name="Labels" type="Node3D" parent="."]

View File

@@ -4,4 +4,4 @@
[resource]
atlas = ExtResource("1_s00hx")
region = Rect2(16, 45.6621, 66, 83.3379)
region = Rect2(16, 45, 66, 83)

View File

@@ -4,7 +4,10 @@
[resource]
animations = [{
"frames": [],
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_vtgsa")
}],
"loop": true,
"name": &"attack",
"speed": 5.0