mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-06-24 12:32:29 +08:00
更新EntityBase和Rooster类,添加动画支持并修复变量命名
This commit is contained in:
@@ -4,6 +4,17 @@
|
|||||||
[ext_resource type="PackedScene" uid="uid://dcjqjqere8ets" path="res://components/UI/EntityStateBar.tscn" id="2_uje1g"]
|
[ext_resource type="PackedScene" uid="uid://dcjqjqere8ets" path="res://components/UI/EntityStateBar.tscn" id="2_uje1g"]
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id="SpriteFrames_wcqpm"]
|
[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"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_buhm1"]
|
||||||
radius = 40.0
|
radius = 40.0
|
||||||
@@ -83,6 +94,7 @@ script = ExtResource("1_mvol6")
|
|||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
position = Vector2(0, -50)
|
position = Vector2(0, -50)
|
||||||
sprite_frames = SubResource("SpriteFrames_wcqpm")
|
sprite_frames = SubResource("SpriteFrames_wcqpm")
|
||||||
|
animation = &"idle"
|
||||||
|
|
||||||
[node name="hurtbox" type="Area2D" parent="texture"]
|
[node name="hurtbox" type="Area2D" parent="texture"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
|||||||
@@ -10,12 +10,20 @@ animations = [{
|
|||||||
"frames": [{
|
"frames": [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": ExtResource("2_q0j6j")
|
"texture": ExtResource("2_q0j6j")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"idle",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("2_q0j6j")
|
||||||
}, {
|
}, {
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": ExtResource("3_b0fgx")
|
"texture": ExtResource("3_b0fgx")
|
||||||
}],
|
}],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": &"default",
|
"name": &"walk",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
}]
|
}]
|
||||||
|
|
||||||
@@ -33,5 +41,6 @@ sprite_frames = SubResource("SpriteFrames_4v2ol")
|
|||||||
position = Vector2(12, 16)
|
position = Vector2(12, 16)
|
||||||
shape = SubResource("CircleShape2D_h1v0q")
|
shape = SubResource("CircleShape2D_h1v0q")
|
||||||
|
|
||||||
[node name="statebar" parent="." index="2"]
|
[node name="statebar" parent="." index="2" node_paths=PackedStringArray("entity")]
|
||||||
position = Vector2(0, -151)
|
position = Vector2(0, -151)
|
||||||
|
entity = NodePath("..")
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ extends EntityBase
|
|||||||
class_name Rooster
|
class_name Rooster
|
||||||
|
|
||||||
func ai():
|
func ai():
|
||||||
|
texture.play("walk")
|
||||||
var direction = Vector2(
|
var direction = Vector2(
|
||||||
Input.get_axis("m_left", "m_right"),
|
Input.get_axis("m_left", "m_right"),
|
||||||
Input.get_axis("m_up", "m_down")
|
Input.get_axis("m_up", "m_down")
|
||||||
)
|
)
|
||||||
move(direction)
|
move(direction)
|
||||||
|
if direction.length() == 0:
|
||||||
|
texture.play("idle")
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ extends CharacterBody2D
|
|||||||
class_name EntityBase # 这是个抽象类
|
class_name EntityBase # 这是个抽象类
|
||||||
|
|
||||||
@export var maxHealth: float = 100
|
@export var maxHealth: float = 100
|
||||||
@export var movementSpeed: float = 100
|
@export var movementSpeed: float = 1
|
||||||
|
|
||||||
@onready var animatree = $"%animatree"
|
@onready var animatree: AnimationTree = $"%animatree"
|
||||||
@onready var texture = $"%texture"
|
@onready var texture: AnimatedSprite2D = $"%texture"
|
||||||
@onready var hurtbox = $"%hurtbox"
|
@onready var hurtbox: Area2D = $"%hurtbox"
|
||||||
|
|
||||||
var health: float = 0
|
var health: float = 0
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ func _physics_process(_delta: float) -> void:
|
|||||||
|
|
||||||
# 通用方法
|
# 通用方法
|
||||||
func move(direction: Vector2):
|
func move(direction: Vector2):
|
||||||
velocity = direction.normalized() * movementSpeed
|
velocity = direction.normalized() * movementSpeed * 150 * 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
|
||||||
|
|||||||
Reference in New Issue
Block a user