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:
@@ -117,4 +117,3 @@ text = "100.0"
|
|||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
custom_minimum_size = Vector2(0, 5)
|
custom_minimum_size = Vector2(0, 5)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
speed1 = 0.9
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=5 format=3 uid="uid://d1ulrvupa76ap"]
|
[gd_scene load_steps=6 format=3 uid="uid://d1ulrvupa76ap"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/Statemachine/ColorBar.gd" id="1_a106p"]
|
[ext_resource type="Script" path="res://scripts/Statemachine/ColorBar.gd" id="1_a106p"]
|
||||||
|
|
||||||
@@ -9,13 +9,20 @@ corner_radius_top_right = 5
|
|||||||
corner_radius_bottom_right = 5
|
corner_radius_bottom_right = 5
|
||||||
corner_radius_bottom_left = 5
|
corner_radius_bottom_left = 5
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_gkydp"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_sh754"]
|
||||||
bg_color = Color(1, 0, 0, 0.5)
|
bg_color = Color(1, 0, 0, 0.5)
|
||||||
corner_radius_top_left = 5
|
corner_radius_top_left = 5
|
||||||
corner_radius_top_right = 5
|
corner_radius_top_right = 5
|
||||||
corner_radius_bottom_right = 5
|
corner_radius_bottom_right = 5
|
||||||
corner_radius_bottom_left = 5
|
corner_radius_bottom_left = 5
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8n8i8"]
|
||||||
|
bg_color = Color(0, 1, 0, 0.5)
|
||||||
|
corner_radius_top_left = 5
|
||||||
|
corner_radius_top_right = 5
|
||||||
|
corner_radius_bottom_right = 5
|
||||||
|
corner_radius_bottom_left = 5
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_x7p33"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_x7p33"]
|
||||||
bg_color = Color(1, 1, 1, 1)
|
bg_color = Color(1, 1, 1, 1)
|
||||||
corner_radius_top_left = 5
|
corner_radius_top_left = 5
|
||||||
@@ -30,7 +37,8 @@ offset_right = 100.0
|
|||||||
offset_bottom = 10.0
|
offset_bottom = 10.0
|
||||||
script = ExtResource("1_a106p")
|
script = ExtResource("1_a106p")
|
||||||
backBox = SubResource("StyleBoxFlat_kf2fc")
|
backBox = SubResource("StyleBoxFlat_kf2fc")
|
||||||
middleBox = SubResource("StyleBoxFlat_gkydp")
|
middleBox1 = SubResource("StyleBoxFlat_sh754")
|
||||||
|
middleBox2 = SubResource("StyleBoxFlat_8n8i8")
|
||||||
frontBox = SubResource("StyleBoxFlat_x7p33")
|
frontBox = SubResource("StyleBoxFlat_x7p33")
|
||||||
speed1 = 0.9
|
speed1 = 0.9
|
||||||
speed2 = 0.05
|
speed2 = 0.05
|
||||||
|
|||||||
@@ -35,3 +35,4 @@ func sprint():
|
|||||||
func heal(count: float):
|
func heal(count: float):
|
||||||
health += count
|
health += count
|
||||||
DamageLabel.create(-count, false, damageAnchor.global_position + MathTool.randv2_range(GameRule.damageLabelSpawnOffset))
|
DamageLabel.create(-count, false, damageAnchor.global_position + MathTool.randv2_range(GameRule.damageLabelSpawnOffset))
|
||||||
|
return count
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ class_name BossBar
|
|||||||
@onready var nameLabel: Label = $"%name"
|
@onready var nameLabel: Label = $"%name"
|
||||||
@onready var valueLabel: Label = $"%value"
|
@onready var valueLabel: Label = $"%value"
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(_delta):
|
||||||
super._physics_process(delta)
|
|
||||||
if is_instance_valid(entity):
|
if is_instance_valid(entity):
|
||||||
nameLabel.text = entity.displayName
|
nameLabel.text = entity.displayName
|
||||||
valueLabel.text = "%.2f" % (entity.health / entity.fields[FieldStore.Entity.MAX_HEALTH] * 100)
|
valueLabel.text = "%.2f" % (entity.health / entity.fields[FieldStore.Entity.MAX_HEALTH] * 100)
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ class_name ColorBar
|
|||||||
@export var maxValue: float = 100
|
@export var maxValue: float = 100
|
||||||
@export var currentValue: float = 50
|
@export var currentValue: float = 50
|
||||||
@export var backBox: StyleBox
|
@export var backBox: StyleBox
|
||||||
@export var middleBox: StyleBox
|
@export var middleBox1: StyleBox
|
||||||
|
@export var middleBox2: StyleBox
|
||||||
@export var frontBox: StyleBox
|
@export var frontBox: StyleBox
|
||||||
@export var speed1: float = 0.8
|
@export var speed1: float = 0.8
|
||||||
@export var speed2: float = 0.01
|
@export var speed2: float = 0.01
|
||||||
@@ -18,6 +19,8 @@ var forwardDirection = -1
|
|||||||
func getPercent(value: float):
|
func getPercent(value: float):
|
||||||
return (value - minValue) / (maxValue - minValue)
|
return (value - minValue) / (maxValue - minValue)
|
||||||
func setCurrent(value: float):
|
func setCurrent(value: float):
|
||||||
|
if value == currentValue:
|
||||||
|
return
|
||||||
forwardDirection = sign(value - currentValue)
|
forwardDirection = sign(value - currentValue)
|
||||||
currentValue = value
|
currentValue = value
|
||||||
|
|
||||||
@@ -26,7 +29,7 @@ func _ready():
|
|||||||
frontValue = currentValue
|
frontValue = currentValue
|
||||||
func _draw():
|
func _draw():
|
||||||
draw_style_box(backBox, Rect2(0, 0, size.x, size.y))
|
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))
|
draw_style_box(frontBox, Rect2(0, 0, size.x * getPercent(frontValue), size.y))
|
||||||
func _physics_process(_delta: float) -> void:
|
func _physics_process(_delta: float) -> void:
|
||||||
middleValue = lerpf(middleValue, currentValue, speed1 if forwardDirection > 0 else speed2)
|
middleValue = lerpf(middleValue, currentValue, speed1 if forwardDirection > 0 else speed2)
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
class_name EntityBase # 这是个抽象类
|
class_name EntityBase # 这是个抽象类
|
||||||
|
|
||||||
|
signal hit(damage: float, bullet: BulletBase, crit: bool)
|
||||||
|
signal healed(amount: float)
|
||||||
|
signal healthChanged(health: float)
|
||||||
|
|
||||||
var fields = {
|
var fields = {
|
||||||
FieldStore.Entity.MAX_HEALTH: 100,
|
FieldStore.Entity.MAX_HEALTH: 100,
|
||||||
FieldStore.Entity.DAMAGE_MULTIPILER: 1,
|
FieldStore.Entity.DAMAGE_MULTIPILER: 1,
|
||||||
@@ -69,6 +73,7 @@ func _ready():
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
currentFocusedBoss = get_tree().get_nodes_in_group("players")[0]
|
currentFocusedBoss = get_tree().get_nodes_in_group("players")[0]
|
||||||
|
healthChanged.emit(health)
|
||||||
func _process(_delta):
|
func _process(_delta):
|
||||||
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH))
|
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH))
|
||||||
energy = clamp(energy, 0, fields.get(FieldStore.Entity.MAX_ENERGY))
|
energy = clamp(energy, 0, fields.get(FieldStore.Entity.MAX_ENERGY))
|
||||||
@@ -107,6 +112,8 @@ func takeDamage(bullet: BulletBase, crit: bool):
|
|||||||
playSound("hurt")
|
playSound("hurt")
|
||||||
bullet.launcher.storeEnergy(damage * 0.05)
|
bullet.launcher.storeEnergy(damage * 0.05)
|
||||||
storeEnergy(damage * -0.1)
|
storeEnergy(damage * -0.1)
|
||||||
|
hit.emit(damage, bullet, crit)
|
||||||
|
healthChanged.emit(health)
|
||||||
health -= damage
|
health -= damage
|
||||||
DamageLabel.create(damage, crit, damageAnchor.global_position + MathTool.randv2_range(GameRule.damageLabelSpawnOffset))
|
DamageLabel.create(damage, crit, damageAnchor.global_position + MathTool.randv2_range(GameRule.damageLabelSpawnOffset))
|
||||||
if isBoss and bullet.launcher.isPlayer():
|
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):
|
if inventory[ItemStore.ItemType.APPLE] > 0 and health < fields.get(FieldStore.Entity.MAX_HEALTH):
|
||||||
inventory[ItemStore.ItemType.APPLE] -= 1
|
inventory[ItemStore.ItemType.APPLE] -= 1
|
||||||
playSound("heal")
|
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):
|
func findWeaponAnchor(weaponName: String):
|
||||||
var anchor = $"%weapons".get_node(weaponName)
|
var anchor = $"%weapons".get_node(weaponName)
|
||||||
if anchor is Node2D:
|
if anchor is Node2D:
|
||||||
@@ -187,8 +195,9 @@ func die():
|
|||||||
queue_free()
|
queue_free()
|
||||||
func sprint():
|
func sprint():
|
||||||
pass
|
pass
|
||||||
func heal(_count: float):
|
func heal(count: float):
|
||||||
pass
|
health += count
|
||||||
|
return count
|
||||||
|
|
||||||
static func generate(
|
static func generate(
|
||||||
entity: PackedScene,
|
entity: PackedScene,
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ class_name EntityStateBar
|
|||||||
|
|
||||||
@onready var healthBar: ColorBar = $"%health"
|
@onready var healthBar: ColorBar = $"%health"
|
||||||
|
|
||||||
func _physics_process(_delta):
|
func _ready():
|
||||||
if is_instance_valid(entity):
|
if is_instance_valid(entity):
|
||||||
healthBar.maxValue = entity.fields.get(FieldStore.Entity.MAX_HEALTH)
|
entity.healthChanged.connect(
|
||||||
healthBar.setCurrent(entity.health)
|
func(health) -> void:
|
||||||
|
healthBar.maxValue = entity.fields.get(FieldStore.Entity.MAX_HEALTH)
|
||||||
|
healthBar.setCurrent(health)
|
||||||
|
)
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ class_name UIState
|
|||||||
@onready var basketball = $"%basketball"
|
@onready var basketball = $"%basketball"
|
||||||
@onready var apple = $"%apple"
|
@onready var apple = $"%apple"
|
||||||
@onready var items = $"%items"
|
@onready var items = $"%items"
|
||||||
@onready var energy = $"%energy"
|
@onready var energyLabel: Label = $"%energy"
|
||||||
|
@onready var energyMaxLabel: Label = $"%energyMax"
|
||||||
@onready var energyPercent: ColorBar = $"%percent"
|
@onready var energyPercent: ColorBar = $"%percent"
|
||||||
|
|
||||||
static var player: EntityBase = null
|
static var player: EntityBase = null
|
||||||
@@ -20,7 +21,8 @@ func _process(_delta):
|
|||||||
bossbar.visible = !!bossbar.entity
|
bossbar.visible = !!bossbar.entity
|
||||||
func _physics_process(_delta):
|
func _physics_process(_delta):
|
||||||
if is_instance_valid(player):
|
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.maxValue = player.fields.get(FieldStore.Entity.MAX_ENERGY)
|
||||||
energyPercent.setCurrent(player.energy)
|
energyPercent.setCurrent(player.energy)
|
||||||
for i in items.get_children():
|
for i in items.get_children():
|
||||||
|
|||||||
Reference in New Issue
Block a user