1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-06-08 04:37:13 +08:00

feat: 更新UI组件,添加能量条和颜色条,优化能量管理逻辑

This commit is contained in:
2025-08-27 20:27:01 +08:00
parent b4d11ee98a
commit 54a4113394
10 changed files with 107 additions and 36 deletions
+2 -2
View File
@@ -4,8 +4,8 @@ class_name BossBar
@onready var nameLabel: Label = $"%name"
@onready var valueLabel: Label = $"%value"
func _process(delta):
super._process(delta)
func _physics_process(delta):
super._physics_process(delta)
if is_instance_valid(entity):
nameLabel.text = entity.displayName
valueLabel.text = "%.2f" % (entity.health / entity.fields[FieldStore.Entity.MAX_HEALTH] * 100)
+7 -9
View File
@@ -86,13 +86,11 @@ static func generate(
var instances = []
for i in range(count):
var instance: BulletBase = bullet.instantiate()
if launchBy.energy < instance.needEnergy:
continue
launchBy.energy -= instance.needEnergy
instance.launcher = launchBy
instance.position = spawnPosition
instance.rotation = spawnRotation + deg_to_rad(randf_range(-launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT), launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT)))
if addToWorld:
WorldManager.rootNode.add_child(instance)
instances.append(instance)
if launchBy.useEnergy(instance.needEnergy):
instance.launcher = launchBy
instance.position = spawnPosition
instance.rotation = spawnRotation + deg_to_rad(randf_range(-launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT), launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT)))
if addToWorld:
WorldManager.rootNode.add_child(instance)
instances.append(instance)
return len(instances)
+8 -8
View File
@@ -5,10 +5,10 @@ class_name ColorBar
@export var minValue: float = 0
@export var maxValue: float = 100
@export var currentValue: float = 50
@export var backColor: Color
@export var middleColor: Color
@export var frontColor: Color
@export var speed1: float = 0.9
@export var backBox: StyleBox
@export var middleBox: StyleBox
@export var frontBox: StyleBox
@export var speed1: float = 0.8
@export var speed2: float = 0.01
var middleValue = 0
@@ -25,10 +25,10 @@ func _ready():
middleValue = currentValue
frontValue = currentValue
func _draw():
draw_rect(Rect2(0, 0, size.x, size.y), backColor)
draw_rect(Rect2(0, 0, size.x * getPercent(middleValue), size.y), middleColor)
draw_rect(Rect2(0, 0, size.x * getPercent(frontValue), size.y), frontColor)
func _process(_delta: float) -> void:
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(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)
frontValue = lerpf(frontValue, currentValue, speed1 if forwardDirection < 0 else speed2)
queue_redraw()
+8 -2
View File
@@ -18,7 +18,8 @@ var fields = {
FieldStore.Entity.EXTRA_BULLET_COUNT: 0,
FieldStore.Entity.DROP_APPLE_RATE: 0,
FieldStore.Entity.FEED_COUNT_SHOW: 3,
FieldStore.Entity.FEED_COUNT_CAN_MADE: 1
FieldStore.Entity.FEED_COUNT_CAN_MADE: 1,
FieldStore.Entity.MAX_ENERGY: 200,
}
var inventory = {
ItemStore.ItemType.BASEBALL: 100,
@@ -70,7 +71,7 @@ func _ready():
currentFocusedBoss = get_tree().get_nodes_in_group("players")[0]
func _process(_delta):
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH))
energy = clamp(energy, 0, INF)
energy = clamp(energy, 0, fields.get(FieldStore.Entity.MAX_ENERGY))
for i in inventory:
inventory[i] = clamp(inventory[i], 0, inventoryMax[i])
func _physics_process(_delta: float) -> void:
@@ -117,6 +118,11 @@ func takeDamage(bullet: BulletBase, crit: bool):
tryDie(bullet)
func storeEnergy(value: float):
energy += value * fields.get(FieldStore.Entity.ENERGY_MULTIPILER)
func useEnergy(value: float):
var state = energy >= value
if state:
energy -= value
return state
func isCooldowned():
return Time.get_ticks_msec() - lastAttack >= cooldownUnit / fields.get(FieldStore.Entity.ATTACK_SPEED)
func startCooldown():
+1 -1
View File
@@ -5,7 +5,7 @@ class_name EntityStateBar
@onready var healthBar: ColorBar = $"%health"
func _process(_delta):
func _physics_process(_delta):
if is_instance_valid(entity):
healthBar.maxValue = entity.fields.get(FieldStore.Entity.MAX_HEALTH)
healthBar.setCurrent(entity.health)
+3
View File
@@ -6,6 +6,7 @@ class_name UIState
@onready var apple = $"%apple"
@onready var items = $"%items"
@onready var energy = $"%energy"
@onready var energyPercent: ColorBar = $"%percent"
static var player: EntityBase = null
static var bossbar: EntityStateBar
@@ -20,6 +21,8 @@ func _process(_delta):
func _physics_process(_delta):
if is_instance_valid(player):
energy.text = "%.1f"%player.energy
energyPercent.maxValue = player.fields.get(FieldStore.Entity.MAX_ENERGY)
energyPercent.setCurrent(player.energy)
for i in items.get_children():
var item = i as ItemShow
item.count = player.inventory.get(item.type)