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

feat: 添加小鸡角色显示名称,更新Boss状态条和伤害标签逻辑,增强EntityBase类的移动和攻击功能

This commit is contained in:
2025-08-26 14:26:45 +08:00
parent 5c64d01f7c
commit 5923660195
6 changed files with 86 additions and 10 deletions
+7
View File
@@ -12,7 +12,14 @@ func ai():
texture.play("idle")
if Input.is_action_pressed("attack"):
tryAttack(0)
if Input.is_action_just_pressed("sprint"):
trySprint()
func attack(type):
if type == 0:
var weaponPos = findWeaponAnchor("normal")
BulletBase.generate(preload("res://components/Bullets/PurpleCrystal.tscn"), self, weaponPos, (get_global_mouse_position() - weaponPos).angle())
func sprint():
move(Vector2(
Input.get_axis("m_left", "m_right"),
Input.get_axis("m_up", "m_down")
) * 6, true)
+11
View File
@@ -0,0 +1,11 @@
extends EntityStateBar
class_name BossBar
@onready var nameLabel: Label = $"%name"
@onready var valueLabel: Label = $"%value"
func _process(delta):
super._process(delta)
if entity:
nameLabel.text = entity.displayName
valueLabel.text = "%.2f" % (entity.health / entity.fields[FieldStore.Entity.MAX_HEALTH] * 100)
+11 -3
View File
@@ -3,10 +3,18 @@ class_name DamageLabel
@export var damage: float = 0
@export var crit: bool = false
@onready var label: Label = $"%label"
@onready var animator: AnimationPlayer = $"%animator"
func _ready():
$"%label".text = str(round(damage)) + ("!!!" if crit else "")
$"%animator".play("show")
await $"%animator".animation_finished
if damage == 0:
label.text = "MISS"
else:
label.text = str(round(damage)) + ("!!!" if crit else "")
animator.play("show")
await animator.animation_finished
queue_free()
static func create(spawnDamage: float, spawnCrit: bool, spawnPosition: Vector2, addToWorld: bool = true) -> DamageLabel:
var instance = preload("res://components/UI/DamageLabel.tscn").instantiate()
+17 -4
View File
@@ -13,6 +13,7 @@ var fields = {
var cooldownUnit: float = 100 # 100毫秒每次攻击
@export var isBoss: bool = false
@export var displayName: String = "未知实体"
@onready var animatree: AnimationTree = $"%animatree"
@onready var texture: AnimatedSprite2D = $"%texture"
@@ -33,19 +34,26 @@ func _process(_delta):
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH))
animatree.set("parameters/blend_position", lerpf(animatree.get("parameters/blend_position"), lastDirection, 0.1))
func _physics_process(_delta: float) -> void:
velocity = Vector2.ZERO
ai()
if sprinting:
velocity *= 0.9
if velocity.length() <= 100:
sprinting = false
else:
velocity = Vector2.ZERO
ai()
move_and_slide()
# 通用方法
func move(direction: Vector2):
velocity = direction.normalized() * fields.get(FieldStore.Entity.MOVEMENT_SPEED) * 200 * abs(animatree.get("parameters/blend_position"))
func move(direction: Vector2, isSprinting: bool = false):
velocity = (direction if isSprinting else direction.normalized()) * fields.get(FieldStore.Entity.MOVEMENT_SPEED) * 200 * abs(animatree.get("parameters/blend_position"))
var currentDirection = sign(direction.x)
if currentDirection != 0:
lastDirection = currentDirection
func takeDamage(bullet: BulletBase, crit: bool):
var baseDamage: float = bullet.fields.get(FieldStore.Bullet.DAMAGE) * randf_range(1 - GameRule.damageOffset, 1 + GameRule.damageOffset)
var damage = baseDamage + baseDamage * int(crit) * fields.get(FieldStore.Entity.CRIT_DAMAGE)
if sprinting:
damage = 0
health -= damage
DamageLabel.create(damage, crit, $"%damageAnchor".global_position + MathTool.randv2_range(GameRule.damageLabelSpawnOffset))
if isBoss:
@@ -64,6 +72,9 @@ func startCooldown():
func tryAttack(type: int):
if startCooldown():
attack(type)
func trySprint():
sprint()
sprinting = true
func findWeaponAnchor(weaponName: String):
var anchor = $"%weapons".get_node(weaponName)
if anchor is Node2D:
@@ -86,6 +97,8 @@ func attack(_type: int):
pass
func die():
queue_free()
func sprint():
pass
static func generate(
entity: PackedScene,