1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-29 23:41: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
+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