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

更新EntityBase和Rooster类,添加动画支持并修复变量命名

This commit is contained in:
2025-08-26 10:55:39 +08:00
parent aae36b740e
commit df3abdb852
4 changed files with 31 additions and 7 deletions
+12
View File
@@ -4,6 +4,17 @@
[ext_resource type="PackedScene" uid="uid://dcjqjqere8ets" path="res://components/UI/EntityStateBar.tscn" id="2_uje1g"]
[sub_resource type="SpriteFrames" id="SpriteFrames_wcqpm"]
animations = [{
"frames": [],
"loop": true,
"name": &"idle",
"speed": 5.0
}, {
"frames": [],
"loop": true,
"name": &"walk",
"speed": 5.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_buhm1"]
radius = 40.0
@@ -83,6 +94,7 @@ script = ExtResource("1_mvol6")
unique_name_in_owner = true
position = Vector2(0, -50)
sprite_frames = SubResource("SpriteFrames_wcqpm")
animation = &"idle"
[node name="hurtbox" type="Area2D" parent="texture"]
unique_name_in_owner = true
+11 -2
View File
@@ -10,12 +10,20 @@ animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("2_q0j6j")
}],
"loop": true,
"name": &"idle",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("2_q0j6j")
}, {
"duration": 1.0,
"texture": ExtResource("3_b0fgx")
}],
"loop": true,
"name": &"default",
"name": &"walk",
"speed": 5.0
}]
@@ -33,5 +41,6 @@ sprite_frames = SubResource("SpriteFrames_4v2ol")
position = Vector2(12, 16)
shape = SubResource("CircleShape2D_h1v0q")
[node name="statebar" parent="." index="2"]
[node name="statebar" parent="." index="2" node_paths=PackedStringArray("entity")]
position = Vector2(0, -151)
entity = NodePath("..")
+3
View File
@@ -2,8 +2,11 @@ extends EntityBase
class_name Rooster
func ai():
texture.play("walk")
var direction = Vector2(
Input.get_axis("m_left", "m_right"),
Input.get_axis("m_up", "m_down")
)
move(direction)
if direction.length() == 0:
texture.play("idle")
+5 -5
View File
@@ -2,11 +2,11 @@ extends CharacterBody2D
class_name EntityBase # 这是个抽象类
@export var maxHealth: float = 100
@export var movementSpeed: float = 100
@export var movementSpeed: float = 1
@onready var animatree = $"%animatree"
@onready var texture = $"%texture"
@onready var hurtbox = $"%hurtbox"
@onready var animatree: AnimationTree = $"%animatree"
@onready var texture: AnimatedSprite2D = $"%texture"
@onready var hurtbox: Area2D = $"%hurtbox"
var health: float = 0
@@ -24,7 +24,7 @@ func _physics_process(_delta: float) -> void:
# 通用方法
func move(direction: Vector2):
velocity = direction.normalized() * movementSpeed
velocity = direction.normalized() * movementSpeed * 150 * abs(animatree.get("parameters/blend_position"))
var currentDirection = sign(direction.x)
if currentDirection != 0:
lastDirection = currentDirection