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:
@@ -32,6 +32,7 @@ size = Vector2(19.5, 14)
|
|||||||
|
|
||||||
[node name="Chick" instance=ExtResource("1_goqmy")]
|
[node name="Chick" instance=ExtResource("1_goqmy")]
|
||||||
script = ExtResource("2_r6bub")
|
script = ExtResource("2_r6bub")
|
||||||
|
displayName = "小鸡"
|
||||||
|
|
||||||
[node name="texture" parent="." index="0"]
|
[node name="texture" parent="." index="0"]
|
||||||
position = Vector2(0, -37)
|
position = Vector2(0, -37)
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
[gd_scene load_steps=3 format=3 uid="uid://ofpg5s3j7esv"]
|
[gd_scene load_steps=5 format=3 uid="uid://ofpg5s3j7esv"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/Statemachine/EntityStateBar.gd" id="1_q4vrr"]
|
[ext_resource type="Script" path="res://scripts/Statemachine/BossBar.gd" id="1_hkj6o"]
|
||||||
[ext_resource type="PackedScene" uid="uid://d1ulrvupa76ap" path="res://components/UI/ColorBar.tscn" id="1_uxey7"]
|
[ext_resource type="PackedScene" uid="uid://d1ulrvupa76ap" path="res://components/UI/ColorBar.tscn" id="1_uxey7"]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ar00p"]
|
||||||
|
content_margin_left = 10.0
|
||||||
|
|
||||||
|
[sub_resource type="LabelSettings" id="LabelSettings_55nrw"]
|
||||||
|
font_size = 14
|
||||||
|
font_color = Color(0, 0, 0, 1)
|
||||||
|
|
||||||
[node name="BossBar" type="Control"]
|
[node name="BossBar" type="Control"]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
@@ -10,7 +17,7 @@ anchor_right = 1.0
|
|||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
script = ExtResource("1_q4vrr")
|
script = ExtResource("1_hkj6o")
|
||||||
|
|
||||||
[node name="health" parent="." instance=ExtResource("1_uxey7")]
|
[node name="health" parent="." instance=ExtResource("1_uxey7")]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
@@ -25,3 +32,32 @@ offset_right = 0.0
|
|||||||
offset_bottom = -20.0
|
offset_bottom = -20.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
|
|
||||||
|
[node name="panel" type="PanelContainer" parent="health"]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
theme_override_styles/panel = SubResource("StyleBoxEmpty_ar00p")
|
||||||
|
|
||||||
|
[node name="label" type="HBoxContainer" parent="health/panel"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="name" type="Label" parent="health/panel/label"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 2
|
||||||
|
text = "BossName"
|
||||||
|
label_settings = SubResource("LabelSettings_55nrw")
|
||||||
|
|
||||||
|
[node name="value" type="Label" parent="health/panel/label"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 2
|
||||||
|
text = "percent"
|
||||||
|
label_settings = SubResource("LabelSettings_55nrw")
|
||||||
|
|
||||||
|
[node name="percent" type="Label" parent="health/panel/label"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "%"
|
||||||
|
label_settings = SubResource("LabelSettings_55nrw")
|
||||||
|
|||||||
@@ -12,7 +12,14 @@ func ai():
|
|||||||
texture.play("idle")
|
texture.play("idle")
|
||||||
if Input.is_action_pressed("attack"):
|
if Input.is_action_pressed("attack"):
|
||||||
tryAttack(0)
|
tryAttack(0)
|
||||||
|
if Input.is_action_just_pressed("sprint"):
|
||||||
|
trySprint()
|
||||||
func attack(type):
|
func attack(type):
|
||||||
if type == 0:
|
if type == 0:
|
||||||
var weaponPos = findWeaponAnchor("normal")
|
var weaponPos = findWeaponAnchor("normal")
|
||||||
BulletBase.generate(preload("res://components/Bullets/PurpleCrystal.tscn"), self, weaponPos, (get_global_mouse_position() - weaponPos).angle())
|
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)
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -3,10 +3,18 @@ class_name DamageLabel
|
|||||||
|
|
||||||
@export var damage: float = 0
|
@export var damage: float = 0
|
||||||
@export var crit: bool = false
|
@export var crit: bool = false
|
||||||
|
|
||||||
|
@onready var label: Label = $"%label"
|
||||||
|
@onready var animator: AnimationPlayer = $"%animator"
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
$"%label".text = str(round(damage)) + ("!!!" if crit else "")
|
if damage == 0:
|
||||||
$"%animator".play("show")
|
label.text = "MISS"
|
||||||
await $"%animator".animation_finished
|
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:
|
static func create(spawnDamage: float, spawnCrit: bool, spawnPosition: Vector2, addToWorld: bool = true) -> DamageLabel:
|
||||||
var instance = preload("res://components/UI/DamageLabel.tscn").instantiate()
|
var instance = preload("res://components/UI/DamageLabel.tscn").instantiate()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ var fields = {
|
|||||||
var cooldownUnit: float = 100 # 100毫秒每次攻击
|
var cooldownUnit: float = 100 # 100毫秒每次攻击
|
||||||
|
|
||||||
@export var isBoss: bool = false
|
@export var isBoss: bool = false
|
||||||
|
@export var displayName: String = "未知实体"
|
||||||
|
|
||||||
@onready var animatree: AnimationTree = $"%animatree"
|
@onready var animatree: AnimationTree = $"%animatree"
|
||||||
@onready var texture: AnimatedSprite2D = $"%texture"
|
@onready var texture: AnimatedSprite2D = $"%texture"
|
||||||
@@ -33,19 +34,26 @@ func _process(_delta):
|
|||||||
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH))
|
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH))
|
||||||
animatree.set("parameters/blend_position", lerpf(animatree.get("parameters/blend_position"), lastDirection, 0.1))
|
animatree.set("parameters/blend_position", lerpf(animatree.get("parameters/blend_position"), lastDirection, 0.1))
|
||||||
func _physics_process(_delta: float) -> void:
|
func _physics_process(_delta: float) -> void:
|
||||||
velocity = Vector2.ZERO
|
if sprinting:
|
||||||
ai()
|
velocity *= 0.9
|
||||||
|
if velocity.length() <= 100:
|
||||||
|
sprinting = false
|
||||||
|
else:
|
||||||
|
velocity = Vector2.ZERO
|
||||||
|
ai()
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
# 通用方法
|
# 通用方法
|
||||||
func move(direction: Vector2):
|
func move(direction: Vector2, isSprinting: bool = false):
|
||||||
velocity = direction.normalized() * fields.get(FieldStore.Entity.MOVEMENT_SPEED) * 200 * abs(animatree.get("parameters/blend_position"))
|
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)
|
var currentDirection = sign(direction.x)
|
||||||
if currentDirection != 0:
|
if currentDirection != 0:
|
||||||
lastDirection = currentDirection
|
lastDirection = currentDirection
|
||||||
func takeDamage(bullet: BulletBase, crit: bool):
|
func takeDamage(bullet: BulletBase, crit: bool):
|
||||||
var baseDamage: float = bullet.fields.get(FieldStore.Bullet.DAMAGE) * randf_range(1 - GameRule.damageOffset, 1 + GameRule.damageOffset)
|
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)
|
var damage = baseDamage + baseDamage * int(crit) * fields.get(FieldStore.Entity.CRIT_DAMAGE)
|
||||||
|
if sprinting:
|
||||||
|
damage = 0
|
||||||
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:
|
if isBoss:
|
||||||
@@ -64,6 +72,9 @@ func startCooldown():
|
|||||||
func tryAttack(type: int):
|
func tryAttack(type: int):
|
||||||
if startCooldown():
|
if startCooldown():
|
||||||
attack(type)
|
attack(type)
|
||||||
|
func trySprint():
|
||||||
|
sprint()
|
||||||
|
sprinting = true
|
||||||
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:
|
||||||
@@ -86,6 +97,8 @@ func attack(_type: int):
|
|||||||
pass
|
pass
|
||||||
func die():
|
func die():
|
||||||
queue_free()
|
queue_free()
|
||||||
|
func sprint():
|
||||||
|
pass
|
||||||
|
|
||||||
static func generate(
|
static func generate(
|
||||||
entity: PackedScene,
|
entity: PackedScene,
|
||||||
|
|||||||
Reference in New Issue
Block a user