feat: 添加浮动文字,展示伤害和躲避
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
signal on_create_block_text(unit: Node2D)
|
||||||
|
signal on_create_damage_text(unit: Node2D, hitbox: HitboxComponent)
|
||||||
|
|
||||||
const FLASH_MATERIAL = preload("uid://cwtrdmkrsmw23")
|
const FLASH_MATERIAL = preload("uid://cwtrdmkrsmw23")
|
||||||
|
const FLOATING_TEXT_SCENE = preload("uid://qkwyrg22h3gi")
|
||||||
|
|
||||||
var player: Player
|
var player: Player
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ health_increase_per_wave = 0.0
|
|||||||
damage = 3
|
damage = 3
|
||||||
damage_increase_per_wave = 0.0
|
damage_increase_per_wave = 0.0
|
||||||
luck = 5.0
|
luck = 5.0
|
||||||
block_chance = 1.0
|
block_chance = 50.0
|
||||||
gold_drop = 0
|
gold_drop = 0
|
||||||
metadata/_custom_type_script = "uid://dgjdpmaiufhs6"
|
metadata/_custom_type_script = "uid://dgjdpmaiufhs6"
|
||||||
|
|||||||
+27
-3
@@ -3,11 +3,35 @@ class_name Arena
|
|||||||
|
|
||||||
@export var player: Player
|
@export var player: Player
|
||||||
|
|
||||||
|
@export var normal_color: Color
|
||||||
|
@export var bloacked_color: Color
|
||||||
|
@export var critical_color: Color
|
||||||
|
@export var hp_color: Color
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
Global.player = player
|
Global.player = player
|
||||||
|
Global.on_create_block_text.connect(_on_create_block_text)
|
||||||
|
Global.on_create_damage_text.connect(_on_create_damage_text)
|
||||||
|
|
||||||
|
func crteat_floating_text(unit: Node2D) -> FloatingText:
|
||||||
|
var instace := Global.FLOATING_TEXT_SCENE.instantiate() as FloatingText
|
||||||
|
get_tree().root.add_child(instace)
|
||||||
|
var random_pos := randf_range(0, TAU) * 35
|
||||||
|
var spawn_pos := unit.global_position + Vector2.RIGHT.rotated(random_pos)
|
||||||
|
instace.global_position = spawn_pos
|
||||||
|
|
||||||
|
return instace
|
||||||
|
|
||||||
|
func _on_create_block_text(unit: Node2D) -> void:
|
||||||
|
var text := crteat_floating_text(unit)
|
||||||
|
text.setup("Blocked!", bloacked_color)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func _on_create_damage_text(unit: Node2D, hitbox: HitboxComponent) -> void:
|
||||||
|
var text := crteat_floating_text(unit)
|
||||||
|
var color := critical_color if hitbox.critical else normal_color
|
||||||
|
text.setup(str(hitbox.damage), color)
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _process(delta: float) -> void:
|
|
||||||
pass
|
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
[node name="Arena" type="Node2D" unique_id=1021720471 node_paths=PackedStringArray("player")]
|
[node name="Arena" type="Node2D" unique_id=1021720471 node_paths=PackedStringArray("player")]
|
||||||
script = ExtResource("1_asdgj")
|
script = ExtResource("1_asdgj")
|
||||||
player = NodePath("PlayerWellRounded")
|
player = NodePath("PlayerWellRounded")
|
||||||
|
normal_color = Color(1, 1, 1, 1)
|
||||||
|
bloacked_color = Color(1, 0.2901961, 0.45490196, 1)
|
||||||
|
critical_color = Color(0.99607843, 0.78039217, 0.38039216, 1)
|
||||||
|
hp_color = Color(0, 0.627451, 0.48235294, 1)
|
||||||
|
|
||||||
[node name="BlackBG" type="Sprite2D" parent="." unique_id=29383651]
|
[node name="BlackBG" type="Sprite2D" parent="." unique_id=29383651]
|
||||||
scale = Vector2(2, 2)
|
scale = Vector2(2, 2)
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
extends Node2D
|
||||||
|
class_name FloatingText
|
||||||
|
|
||||||
|
@onready var value_label: Label = $ValueLabel
|
||||||
|
|
||||||
|
func setup(value: String, color) -> void:
|
||||||
|
value_label.text = value
|
||||||
|
modulate = color
|
||||||
|
scale = Vector2.ZERO
|
||||||
|
|
||||||
|
rotation = deg_to_rad(randf_range(-10, 10))
|
||||||
|
var random_scale := randf_range(0.8,1.6)
|
||||||
|
|
||||||
|
var tween := create_tween()
|
||||||
|
|
||||||
|
tween.parallel().tween_property(self, "scale", random_scale * Vector2.ONE, 0.4)
|
||||||
|
tween.parallel().tween_property(self, "global_position", global_position + Vector2.UP * 15, 0.4)
|
||||||
|
|
||||||
|
tween .tween_interval(0.5)
|
||||||
|
|
||||||
|
tween.parallel().tween_property(self,"scale", Vector2.ZERO, 0.4)
|
||||||
|
tween.parallel().tween_property(self, "modulate:a", 0.0, 0.4)
|
||||||
|
|
||||||
|
await tween.finished
|
||||||
|
queue_free()
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
pass
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://crydqt4saprcl
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
[gd_scene format=3 uid="uid://qkwyrg22h3gi"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://crydqt4saprcl" path="res://scenes/ui/floating_text/floating_text.gd" id="1_32222"]
|
||||||
|
|
||||||
|
[sub_resource type="LabelSettings" id="LabelSettings_dsam5"]
|
||||||
|
font_size = 32
|
||||||
|
outline_size = 10
|
||||||
|
outline_color = Color(0.029506557, 0.029506557, 0.029506557, 1)
|
||||||
|
|
||||||
|
[node name="FloatingText" type="Node2D" unique_id=176496435]
|
||||||
|
z_index = 10
|
||||||
|
rotation = 0.13613568
|
||||||
|
script = ExtResource("1_32222")
|
||||||
|
|
||||||
|
[node name="ValueLabel" type="Label" parent="." unique_id=481881550]
|
||||||
|
anchors_preset = 8
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_left = -20.0
|
||||||
|
offset_top = -19.333334
|
||||||
|
offset_right = 20.0
|
||||||
|
offset_bottom = 19.333334
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
text = "10"
|
||||||
|
label_settings = SubResource("LabelSettings_dsam5")
|
||||||
|
horizontal_alignment = 1
|
||||||
+3
-3
@@ -23,13 +23,13 @@ func _on_hurtbox_component_on_damaged(hitbox: HitboxComponent) -> void:
|
|||||||
var blocked := Global.get_chance_success(stats.block_chance / 100)
|
var blocked := Global.get_chance_success(stats.block_chance / 100)
|
||||||
|
|
||||||
if blocked:
|
if blocked:
|
||||||
print("Blocked!")
|
#print("Blocked!")
|
||||||
|
Global.on_create_block_text.emit(self)
|
||||||
return
|
return
|
||||||
|
|
||||||
set_flash_material()
|
set_flash_material()
|
||||||
|
|
||||||
health_component.take_damage(hitbox.damage)
|
health_component.take_damage(hitbox.damage)
|
||||||
print("%s: %d" % [name, health_component.current_health] )
|
Global.on_create_damage_text.emit(self, hitbox)
|
||||||
|
|
||||||
|
|
||||||
func _on_flash_timer_timeout() -> void:
|
func _on_flash_timer_timeout() -> void:
|
||||||
|
|||||||
Reference in New Issue
Block a user