1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-29 23:41:54 +08:00
This commit is contained in:
2025-08-26 09:24:09 +08:00
commit 363aeaf445
25 changed files with 700 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
extends EntityBase
class_name Rooster
func ai():
var vector = Vector2(
Input.get_axis("m_left", "m_right"),
Input.get_axis("m_up", "m_down")
)
move(vector)
+33
View File
@@ -0,0 +1,33 @@
@tool
extends Control
@export var minValue: float = 0
@export var maxValue: float = 100
@export var currentValue: float = 50
@export var backColor: Color
@export var middleColor: Color
@export var frontColor: Color
@export var speed1: float = 0.9
@export var speed2: float = 0.01
var middleValue = 0
var frontValue = 0
var forwardDirection = -1
func getPercent(value: float):
return (value - minValue) / (maxValue - minValue)
func setCurrent(value: float):
forwardDirection = sign(value - currentValue)
currentValue = value
func _ready():
middleValue = currentValue
frontValue = currentValue
func _draw():
draw_rect(Rect2(0, 0, size.x, size.y), backColor)
draw_rect(Rect2(0, 0, size.x * getPercent(middleValue), size.y), middleColor)
draw_rect(Rect2(0, 0, size.x * getPercent(frontValue), size.y), frontColor)
func _process(_delta: float) -> void:
middleValue = lerpf(middleValue, currentValue, speed1 if forwardDirection > 0 else speed2)
frontValue = lerpf(frontValue, currentValue, speed1 if forwardDirection < 0 else speed2)
queue_redraw()
+26
View File
@@ -0,0 +1,26 @@
extends CharacterBody2D
class_name EntityBase # 这是个抽象类
@export var maxHealth: float = 100
@export var movementSpeed: float = 100
var health: float = 0
func _ready():
health = maxHealth
func _process(_delta):
health = clamp(health, 0, maxHealth)
func _physics_process(_delta: float) -> void:
velocity = Vector2.ZERO
ai()
move_and_slide()
# 通用方法
func move(direction: Vector2):
velocity = direction.normalized() * movementSpeed
# 抽象方法
func ai():
pass
func attack(_type: int):
pass
+10
View File
@@ -0,0 +1,10 @@
extends Node2D
@export var entity: EntityBase
@onready var healthBar = $"%health"
func _process(_delta):
if entity:
healthBar.maxValue = entity.maxHealth
healthBar.setCurrent(entity.health)