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
+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():