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:17:38 +08:00
parent 363aeaf445
commit 61a4cabf15
4 changed files with 108 additions and 13 deletions
+85 -7
View File
@@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=3 uid="uid://cvogxi7mktumf"]
[gd_scene load_steps=13 format=3 uid="uid://cvogxi7mktumf"]
[ext_resource type="Script" path="res://scripts/Statemachine/EntityBase.gd" id="1_mvol6"]
[ext_resource type="PackedScene" uid="uid://dcjqjqere8ets" path="res://components/UI/EntityStateBar.tscn" id="2_uje1g"]
@@ -6,7 +6,72 @@
[sub_resource type="SpriteFrames" id="SpriteFrames_wcqpm"]
[sub_resource type="CircleShape2D" id="CircleShape2D_buhm1"]
radius = 43.2897
radius = 40.0
[sub_resource type="Animation" id="Animation_3wcjn"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(1, 1)]
}
[sub_resource type="Animation" id="Animation_4veur"]
resource_name = "left"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(-1, 1)]
}
[sub_resource type="Animation" id="Animation_fgeas"]
resource_name = "left"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(1, 1)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_kbmff"]
_data = {
"RESET": SubResource("Animation_3wcjn"),
"left": SubResource("Animation_4veur"),
"right": SubResource("Animation_fgeas")
}
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_ao5k4"]
animation = &"left"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_611yr"]
animation = &"right"
[sub_resource type="AnimationNodeBlendSpace1D" id="AnimationNodeBlendSpace1D_51ube"]
blend_point_0/node = SubResource("AnimationNodeAnimation_ao5k4")
blend_point_0/pos = -1.0
blend_point_1/node = SubResource("AnimationNodeAnimation_611yr")
blend_point_1/pos = 1.0
snap = 1.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ce3to"]
size = Vector2(64, 14)
@@ -15,17 +80,30 @@ size = Vector2(64, 14)
script = ExtResource("1_mvol6")
[node name="texture" type="AnimatedSprite2D" parent="."]
unique_name_in_owner = true
position = Vector2(0, -50)
sprite_frames = SubResource("SpriteFrames_wcqpm")
[node name="statebar" parent="texture" instance=ExtResource("2_uje1g")]
position = Vector2(0, -51)
[node name="hurtbox" type="Area2D" parent="texture"]
unique_name_in_owner = true
[node name="hitbox" type="CollisionShape2D" parent="texture/hurtbox"]
position = Vector2(7, 12)
shape = SubResource("CircleShape2D_buhm1")
[node name="animator" type="AnimationPlayer" parent="texture"]
libraries = {
"": SubResource("AnimationLibrary_kbmff")
}
[node name="animatree" type="AnimationTree" parent="texture/animator"]
unique_name_in_owner = true
root_node = NodePath("%animatree/../..")
tree_root = SubResource("AnimationNodeBlendSpace1D_51ube")
anim_player = NodePath("..")
parameters/blend_position = 1.0
[node name="movebox" type="CollisionShape2D" parent="."]
position = Vector2(16, 69)
shape = SubResource("RectangleShape2D_ce3to")
[node name="statebar" parent="." instance=ExtResource("2_uje1g")]
position = Vector2(0, -100)
+11 -4
View File
@@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=3 uid="uid://bm7ymrri6pykb"]
[gd_scene load_steps=7 format=3 uid="uid://bm7ymrri6pykb"]
[ext_resource type="PackedScene" uid="uid://cvogxi7mktumf" path="res://components/Abstracts/EntityBase.tscn" id="1_e5pl8"]
[ext_resource type="Script" path="res://scripts/Contents/Characters/Rooster.gd" id="2_oqdqd"]
@@ -19,12 +19,19 @@ animations = [{
"speed": 5.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_h1v0q"]
radius = 41.0122
[node name="Rooster" instance=ExtResource("1_e5pl8")]
script = ExtResource("2_oqdqd")
[node name="texture" parent="." index="0"]
position = Vector2(0, -70)
sprite_frames = SubResource("SpriteFrames_4v2ol")
[node name="statebar" parent="texture" index="0" node_paths=PackedStringArray("entity")]
position = Vector2(0, -83)
entity = NodePath("../..")
[node name="hitbox" parent="texture/hurtbox" index="0"]
position = Vector2(12, 16)
shape = SubResource("CircleShape2D_h1v0q")
[node name="statebar" parent="." index="2"]
position = Vector2(0, -151)
+2 -2
View File
@@ -2,8 +2,8 @@ extends EntityBase
class_name Rooster
func ai():
var vector = Vector2(
var direction = Vector2(
Input.get_axis("m_left", "m_right"),
Input.get_axis("m_up", "m_down")
)
move(vector)
move(direction)
+10
View File
@@ -4,12 +4,19 @@ class_name EntityBase # 这是个抽象类
@export var maxHealth: float = 100
@export var movementSpeed: float = 100
@onready var animatree = $"%animatree"
@onready var texture = $"%texture"
@onready var hurtbox = $"%hurtbox"
var health: float = 0
var lastDirection: int = 1
func _ready():
health = maxHealth
func _process(_delta):
health = clamp(health, 0, maxHealth)
animatree.set("parameters/blend_position", lerpf(animatree.get("parameters/blend_position"), lastDirection, 0.1))
func _physics_process(_delta: float) -> void:
velocity = Vector2.ZERO
ai()
@@ -18,6 +25,9 @@ func _physics_process(_delta: float) -> void:
# 通用方法
func move(direction: Vector2):
velocity = direction.normalized() * movementSpeed
var currentDirection = sign(direction.x)
if currentDirection != 0:
lastDirection = currentDirection
# 抽象方法
func ai():