1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-06-09 05:07:12 +08:00

feat: 添加能量属性到角色,更新攻击逻辑以消耗能量

This commit is contained in:
2025-08-27 12:46:20 +08:00
parent 23bc9b3e20
commit f764f0b3c9
9 changed files with 28 additions and 18 deletions
+10 -4
View File
@@ -10,6 +10,7 @@ class_name BulletBase
@export var lifeTime: float = -1 # -1表示无限时间
@export var indisDamage: bool = false # 是否无差别伤害(不区分敌我)
@export var canDamageSelf: bool = false # 是否可以伤害发射者
@export var needEnergy: float = 4.0 # 发射时需要消耗的能量
var launcher: EntityBase = null
var spawnInWhen: float = 0
@@ -37,12 +38,14 @@ func hit(target: Node):
if !indisDamage && !GameRule.allowFriendlyFire:
if entity.isPlayer() == launcher.isPlayer(): return
entity.takeDamage(self, MathTool.rate(launcher.fields.get(FieldStore.Entity.CRIT_RATE)))
if !MathTool.rate(fullPenerate(entity)):
if MathTool.rate(fullPenerate()):
fields[FieldStore.Bullet.PENERATE] -= entity.fields[FieldStore.Entity.PENARATION_RESISTANCE]
else:
destroy()
func forward(direction: Vector2):
position += direction.normalized() * fields.get(FieldStore.Bullet.SPEED) * GameRule.bulletSpeedMultiplier
func fullPenerate(target: EntityBase):
return fields.get(FieldStore.Bullet.PENERATE) * (1 + launcher.fields.get(FieldStore.Entity.PENERATE)) - target.fields.get(FieldStore.Entity.PENARATION_RESISTANCE)
func fullPenerate():
return fields.get(FieldStore.Bullet.PENERATE) + launcher.fields.get(FieldStore.Entity.PENERATE)
func ai():
pass
@@ -61,10 +64,13 @@ static func generate(
var instances = []
for i in range(count):
var instance: BulletBase = bullet.instantiate()
if launchBy.energy < instance.needEnergy:
continue
launchBy.energy -= instance.needEnergy
instance.launcher = launchBy
instance.position = spawnPosition
instance.rotation = spawnRotation + deg_to_rad(randf_range(-launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT), launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT)))
if addToWorld:
WorldManager.rootNode.add_child(instance)
instances.append(instance)
return instances
return len(instances)
+7 -6
View File
@@ -46,7 +46,7 @@ var inventoryMax = {
@onready var damageAnchor: Node2D = $"%damageAnchor"
var health: float = 0
var energy: float = 0
@export var energy: float = 0
var sprinting: bool = false
var lastDirection: int = 1
@@ -68,10 +68,10 @@ func _ready():
currentFocusedBoss = get_tree().get_nodes_in_group("players")[0]
func _process(_delta):
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH))
animatree.set("parameters/blend_position", lerpf(animatree.get("parameters/blend_position"), lastDirection, 0.1))
for i in inventory:
inventory[i] = clamp(inventory[i], 0, inventoryMax[i])
func _physics_process(_delta: float) -> void:
animatree.set("parameters/blend_position", lerpf(animatree.get("parameters/blend_position"), lastDirection, 0.1))
if sprinting:
velocity *= 0.9
if velocity.length() <= 100:
@@ -81,6 +81,7 @@ func _physics_process(_delta: float) -> void:
if isPlayer() or is_instance_valid(currentFocusedBoss):
ai()
move_and_slide()
storeEnergy(0.05)
# 通用方法
func displace(direction: Vector2, isSprinting: bool = false):
@@ -96,11 +97,11 @@ func takeDamage(bullet: BulletBase, crit: bool):
var damage = baseDamage + baseDamage * int(crit) * fields.get(FieldStore.Entity.CRIT_DAMAGE)
if sprinting:
playSound("miss")
storeEnergy(damage * 0.5)
storeEnergy(damage * 1.5)
damage = 0
else:
playSound("hurt")
bullet.launcher.storeEnergy(damage * 0.25)
bullet.launcher.storeEnergy(damage * 0.5)
health -= damage
DamageLabel.create(damage, crit, damageAnchor.global_position + MathTool.randv2_range(GameRule.damageLabelSpawnOffset))
if isBoss and bullet.launcher.isPlayer():
@@ -122,8 +123,8 @@ func startCooldown():
func tryAttack(type: int):
var state = startCooldown()
if state:
playSound("attack" + str(type))
attack(type)
if attack(type):
playSound("attack" + str(type))
return state
func trySprint():
playSound("sprint")