1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 06:51:54 +08:00

feat: 更新UI和角色逻辑,优化能量条显示和状态管理

This commit is contained in:
2025-08-27 20:47:04 +08:00
parent 54a4113394
commit d6cd74729b
8 changed files with 40 additions and 16 deletions
+1
View File
@@ -35,3 +35,4 @@ func sprint():
func heal(count: float):
health += count
DamageLabel.create(-count, false, damageAnchor.global_position + MathTool.randv2_range(GameRule.damageLabelSpawnOffset))
return count
+1 -2
View File
@@ -4,8 +4,7 @@ class_name BossBar
@onready var nameLabel: Label = $"%name"
@onready var valueLabel: Label = $"%value"
func _physics_process(delta):
super._physics_process(delta)
func _physics_process(_delta):
if is_instance_valid(entity):
nameLabel.text = entity.displayName
valueLabel.text = "%.2f" % (entity.health / entity.fields[FieldStore.Entity.MAX_HEALTH] * 100)
+5 -2
View File
@@ -6,7 +6,8 @@ class_name ColorBar
@export var maxValue: float = 100
@export var currentValue: float = 50
@export var backBox: StyleBox
@export var middleBox: StyleBox
@export var middleBox1: StyleBox
@export var middleBox2: StyleBox
@export var frontBox: StyleBox
@export var speed1: float = 0.8
@export var speed2: float = 0.01
@@ -18,6 +19,8 @@ var forwardDirection = -1
func getPercent(value: float):
return (value - minValue) / (maxValue - minValue)
func setCurrent(value: float):
if value == currentValue:
return
forwardDirection = sign(value - currentValue)
currentValue = value
@@ -26,7 +29,7 @@ func _ready():
frontValue = currentValue
func _draw():
draw_style_box(backBox, Rect2(0, 0, size.x, size.y))
draw_style_box(middleBox, Rect2(0, 0, size.x * getPercent(middleValue), size.y))
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)
+12 -3
View File
@@ -1,6 +1,10 @@
extends CharacterBody2D
class_name EntityBase # 这是个抽象类
signal hit(damage: float, bullet: BulletBase, crit: bool)
signal healed(amount: float)
signal healthChanged(health: float)
var fields = {
FieldStore.Entity.MAX_HEALTH: 100,
FieldStore.Entity.DAMAGE_MULTIPILER: 1,
@@ -69,6 +73,7 @@ func _ready():
)
else:
currentFocusedBoss = get_tree().get_nodes_in_group("players")[0]
healthChanged.emit(health)
func _process(_delta):
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH))
energy = clamp(energy, 0, fields.get(FieldStore.Entity.MAX_ENERGY))
@@ -107,6 +112,8 @@ func takeDamage(bullet: BulletBase, crit: bool):
playSound("hurt")
bullet.launcher.storeEnergy(damage * 0.05)
storeEnergy(damage * -0.1)
hit.emit(damage, bullet, crit)
healthChanged.emit(health)
health -= damage
DamageLabel.create(damage, crit, damageAnchor.global_position + MathTool.randv2_range(GameRule.damageLabelSpawnOffset))
if isBoss and bullet.launcher.isPlayer():
@@ -154,7 +161,8 @@ func tryHeal(count: float):
if inventory[ItemStore.ItemType.APPLE] > 0 and health < fields.get(FieldStore.Entity.MAX_HEALTH):
inventory[ItemStore.ItemType.APPLE] -= 1
playSound("heal")
heal(count * fields.get(FieldStore.Entity.HEAL_ABILITY))
healed.emit(heal(count * fields.get(FieldStore.Entity.HEAL_ABILITY)))
healthChanged.emit(health)
func findWeaponAnchor(weaponName: String):
var anchor = $"%weapons".get_node(weaponName)
if anchor is Node2D:
@@ -187,8 +195,9 @@ func die():
queue_free()
func sprint():
pass
func heal(_count: float):
pass
func heal(count: float):
health += count
return count
static func generate(
entity: PackedScene,
+6 -3
View File
@@ -5,7 +5,10 @@ class_name EntityStateBar
@onready var healthBar: ColorBar = $"%health"
func _physics_process(_delta):
func _ready():
if is_instance_valid(entity):
healthBar.maxValue = entity.fields.get(FieldStore.Entity.MAX_HEALTH)
healthBar.setCurrent(entity.health)
entity.healthChanged.connect(
func(health) -> void:
healthBar.maxValue = entity.fields.get(FieldStore.Entity.MAX_HEALTH)
healthBar.setCurrent(health)
)
+4 -2
View File
@@ -5,7 +5,8 @@ class_name UIState
@onready var basketball = $"%basketball"
@onready var apple = $"%apple"
@onready var items = $"%items"
@onready var energy = $"%energy"
@onready var energyLabel: Label = $"%energy"
@onready var energyMaxLabel: Label = $"%energyMax"
@onready var energyPercent: ColorBar = $"%percent"
static var player: EntityBase = null
@@ -20,7 +21,8 @@ func _process(_delta):
bossbar.visible = !!bossbar.entity
func _physics_process(_delta):
if is_instance_valid(player):
energy.text = "%.1f"%player.energy
energyLabel.text = "%.1f" % player.energy
energyMaxLabel.text = "%.1f" % player.fields.get(FieldStore.Entity.MAX_ENERGY)
energyPercent.maxValue = player.fields.get(FieldStore.Entity.MAX_ENERGY)
energyPercent.setCurrent(player.energy)
for i in items.get_children():