From 73e34e07d2b92a1c4f460522f2a9b116bdc86f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Sat, 6 Sep 2025 16:51:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=8A=B6=E6=80=81=E6=9D=A1):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=A1=80=E9=87=8F=E5=8F=98=E5=8C=96=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E5=92=8C=E5=BC=BA=E5=88=B6=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在ColorBar中添加lastChangeTime记录最后变化时间,配合GameRule.detainTime实现血量变化延迟动画 - 新增forceSync方法用于强制同步状态条显示 - 调整EntityBase初始化顺序,确保状态条正确初始化 - 在GameRule中添加detainTime配置项控制动画延迟时间 --- scripts/Statemachine/ColorBar.gd | 12 +++++++++--- scripts/Statemachine/EntityBase.gd | 5 +++-- scripts/Statemachine/EntityStateBar.gd | 5 +++++ scripts/Tools/GameRule.gd | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/Statemachine/ColorBar.gd b/scripts/Statemachine/ColorBar.gd index 3c51ac6..4f0e5a4 100644 --- a/scripts/Statemachine/ColorBar.gd +++ b/scripts/Statemachine/ColorBar.gd @@ -15,6 +15,7 @@ class_name ColorBar var middleValue = 0 var frontValue = 0 var forwardDirection = -1 +var lastChangeTime = 0 func getPercent(value: float): return (value - minValue) / (maxValue - minValue) @@ -23,13 +24,18 @@ func setCurrent(value: float): return forwardDirection = sign(value - currentValue) currentValue = clamp(value, minValue, maxValue) - -func _ready(): + lastChangeTime = WorldManager.getTime() +func forceSync(): middleValue = currentValue frontValue = currentValue + +func _ready(): + forceSync() + lastChangeTime = WorldManager.getTime() func _draw(): draw_style_box(backBox, Rect2(0, 0, size.x, size.y)) - draw_style_box(middleBox2 if forwardDirection > 0 else middleBox1, Rect2(0, 0, size.x * getPercent(middleValue), size.y)) + if WorldManager.getTime() - lastChangeTime > GameRule.detainTime: + draw_style_box(middleBox2 if forwardDirection > 0 else middleBox1, Rect2(0, 0, size.x * getPercent(middleValue), size.y)) draw_style_box(frontBox, Rect2(0, 0, size.x * getPercent(frontValue), size.y)) func _physics_process(_delta: float) -> void: middleValue = lerpf(middleValue, currentValue, speed1 if forwardDirection > 0 else speed2) diff --git a/scripts/Statemachine/EntityBase.gd b/scripts/Statemachine/EntityBase.gd index 5eea79f..1225bf9 100644 --- a/scripts/Statemachine/EntityBase.gd +++ b/scripts/Statemachine/EntityBase.gd @@ -90,6 +90,8 @@ var cooldownTimer = CooldownTimer.new() var weapons: Array[Weapon] = [] func _ready(): + health = fields.get(FieldStore.Entity.MAX_HEALTH) + energy = fields.get(FieldStore.Entity.MAX_ENERGY) register() var selfStatebar: EntityStateBar = $"%statebar" if isBoss: @@ -97,6 +99,7 @@ func _ready(): else: statebar = selfStatebar statebar.entity = self + statebar.forceSync() if isPlayer(): for i in weaponStore.get_children(): i.hide() @@ -118,8 +121,6 @@ func _ready(): else: currentFocusedBoss = get_tree().get_nodes_in_group("players")[0] applyLevel() - health = fields.get(FieldStore.Entity.MAX_HEALTH) - energy = fields.get(FieldStore.Entity.MAX_ENERGY) healthChanged.connect( func(newHealth): if is_instance_valid(statebar): diff --git a/scripts/Statemachine/EntityStateBar.gd b/scripts/Statemachine/EntityStateBar.gd index 8182381..7cdc609 100644 --- a/scripts/Statemachine/EntityStateBar.gd +++ b/scripts/Statemachine/EntityStateBar.gd @@ -6,3 +6,8 @@ class_name EntityStateBar @onready var healthBar: ColorBar = $"%health" @onready var levelLabel: Label = $"%level" @onready var levelLabels: HBoxContainer = $"%levelLabel" + +func forceSync(): + healthBar.maxValue = entity.fields[FieldStore.Entity.MAX_HEALTH] + healthBar.currentValue = entity.health + healthBar.forceSync() diff --git a/scripts/Tools/GameRule.gd b/scripts/Tools/GameRule.gd index a63b4c2..bbbae3e 100644 --- a/scripts/Tools/GameRule.gd +++ b/scripts/Tools/GameRule.gd @@ -26,3 +26,4 @@ static var entityLevelOffsetByWave: float = MathTool.percent(30) # 每波敌人 static var appleDropRateInfluenceByLuckValue: float = MathTool.percent(2) # 幸运值对苹果掉率的影响 static var critRateInfluenceByLuckValue: float = MathTool.percent(2.5) # 幸运值对暴击率的影响 static var penerateRateInfluenceByLuckValue: float = MathTool.percent(3) # 幸运值对穿透率的影响 +static var detainTime: float = 1000 # 血量如果在这个时间内没有改变才会开始播放降低动画 \ No newline at end of file