game: add simple damage-numbers scene
This commit is contained in:
25
scenes/damage_numbers.gd
Normal file
25
scenes/damage_numbers.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends Node2D
|
||||
|
||||
@export var damage_taken: float
|
||||
@export var player_damage: bool = true
|
||||
@export var critical_damage: bool = false
|
||||
|
||||
@onready var animation_player: AnimationPlayer = $Control/AnimationPlayer
|
||||
@onready var label: Label = $Control/Label
|
||||
|
||||
const COLOR_CRIT = Color.GOLD
|
||||
const COLOR_REGULAR = Color.WHITE
|
||||
const COLOR_PLAYER = Color.CRIMSON
|
||||
|
||||
func _ready() -> void:
|
||||
if !player_damage:
|
||||
label.add_theme_color_override("font_color", COLOR_PLAYER)
|
||||
if critical_damage:
|
||||
label.add_theme_color_override("font_color", COLOR_CRIT)
|
||||
label.add_theme_font_size_override("font_size", 8)
|
||||
label.text = "%0.0f" % damage_taken
|
||||
animation_player.play("normal_damage")
|
||||
animation_player.animation_finished.connect(_on_animation_finished)
|
||||
|
||||
func _on_animation_finished(_name: String):
|
||||
queue_free()
|
1
scenes/damage_numbers.gd.uid
Normal file
1
scenes/damage_numbers.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dri8n7vfnarub
|
72
scenes/damage_numbers.tscn
Normal file
72
scenes/damage_numbers.tscn
Normal file
@@ -0,0 +1,72 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://p7ih16elqja4"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dri8n7vfnarub" path="res://scenes/damage_numbers.gd" id="1_bhj6t"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_ngvhj"]
|
||||
resource_name = "normal_damage"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Control/Label:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 1),
|
||||
"transitions": PackedFloat32Array(0.148651, 0.148651),
|
||||
"update": 0,
|
||||
"values": [Vector2(-9.5, -11.5), Vector2(-9, -82)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_bhj6t"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Control/Label:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, -248)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_0otjp"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_bhj6t"),
|
||||
&"normal_damage": SubResource("Animation_ngvhj")
|
||||
}
|
||||
|
||||
[node name="DamageNumbers" type="Node2D"]
|
||||
script = ExtResource("1_bhj6t")
|
||||
|
||||
[node name="Control" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="Label" type="Label" parent="Control"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -29.5
|
||||
offset_top = -31.5
|
||||
offset_right = -10.5
|
||||
offset_bottom = -8.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 4
|
||||
text = "50"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="Control"]
|
||||
root_node = NodePath("../..")
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_0otjp")
|
||||
}
|
Reference in New Issue
Block a user