mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-31 08:21:54 +08:00
feat(状态条): 添加血量变化延迟动画和强制同步功能
- 在ColorBar中添加lastChangeTime记录最后变化时间,配合GameRule.detainTime实现血量变化延迟动画 - 新增forceSync方法用于强制同步状态条显示 - 调整EntityBase初始化顺序,确保状态条正确初始化 - 在GameRule中添加detainTime配置项控制动画延迟时间
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 # 血量如果在这个时间内没有改变才会开始播放降低动画
|
||||
Reference in New Issue
Block a user