mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-06-02 01:11:54 +08:00
refactor(CameraManager): 重构相机震动系统并添加强度参数
- 移除shaking布尔变量,改用shakeIntensity控制震动强度 - 修改shake方法接受强度参数,支持叠加震动效果 - 简化震动逻辑,移除调试打印语句 feat(ItemDropped): 添加物品自动收集功能 - 当物品与玩家距离小于60时自动收集并销毁 - 调用玩家collectItem方法处理收集逻辑 refactor(EntityBase): 重构物品收集逻辑 - 将物品收集逻辑从信号回调移至collectItem方法 - 移除itemCollected信号及相关UI更新代码 - 简化hurtbox连接逻辑 style(World): 调整动画资源顺序 - 交换两个动画资源的定义顺序
This commit is contained in:
@@ -2,7 +2,7 @@ extends BulletBase
|
||||
class_name BigLaser
|
||||
|
||||
func spawn():
|
||||
CameraManager.shake(5000)
|
||||
CameraManager.shake(5000, 100)
|
||||
CameraManager.playAnimation("bigLaser")
|
||||
func ai():
|
||||
rotation = lerp_angle(rotation, ((get_global_mouse_position() - position).angle()), 0.1)
|
||||
|
||||
@@ -7,8 +7,6 @@ signal healthChanged(health: float)
|
||||
|
||||
signal energyChanged(energy: float)
|
||||
|
||||
signal itemCollected(itemType: ItemStore.ItemType, amount: int)
|
||||
|
||||
var fields = {
|
||||
FieldStore.Entity.MAX_HEALTH: 100,
|
||||
FieldStore.Entity.DAMAGE_MULTIPILER: 1,
|
||||
@@ -76,24 +74,11 @@ func _ready():
|
||||
if isPlayer():
|
||||
statebar.levelLabels.hide()
|
||||
UIState.player = self
|
||||
hurtbox.body_entered.connect(
|
||||
func(body):
|
||||
if body is ItemDropped:
|
||||
inventory[body.item] += body.stackCount
|
||||
playSound("collect")
|
||||
itemCollected.emit(body.item, body.stackCount)
|
||||
body.queue_free()
|
||||
)
|
||||
energyChanged.connect(
|
||||
func(newEnergy):
|
||||
UIState.energyPercent.maxValue = fields.get(FieldStore.Entity.MAX_ENERGY)
|
||||
UIState.energyPercent.setCurrent(newEnergy)
|
||||
)
|
||||
itemCollected.connect(
|
||||
func(itemType, amount):
|
||||
if MathTool.rate(GameRule.tipSpawnRateWhenGetDroppedItem):
|
||||
UIState.itemCollect.add_child(ItemShow.generate(itemType, amount, true))
|
||||
)
|
||||
else:
|
||||
currentFocusedBoss = get_tree().get_nodes_in_group("players")[0]
|
||||
applyLevel()
|
||||
@@ -166,6 +151,9 @@ func takeDamage(bullet: BulletBase, crit: bool):
|
||||
bullet.launcher.storeEnergy(energy * 0.35)
|
||||
bullet.launcher.setBoss(null)
|
||||
tryDie(bullet)
|
||||
func collectItem(itemType: ItemStore.ItemType, amount: int):
|
||||
inventory[itemType] += amount
|
||||
playSound("collect")
|
||||
func storeEnergy(value: float):
|
||||
energy += value * fields.get(FieldStore.Entity.ENERGY_MULTIPILER)
|
||||
energyChanged.emit(energy)
|
||||
|
||||
@@ -16,6 +16,9 @@ func _physics_process(_delta):
|
||||
targetPlayer = findPlayer()
|
||||
if is_instance_valid(targetPlayer):
|
||||
apply_central_force((targetPlayer.position - position).normalized() * 1000)
|
||||
if position.distance_to(targetPlayer.position) < 60:
|
||||
targetPlayer.collectItem(item, stackCount)
|
||||
queue_free()
|
||||
|
||||
func findPlayer() -> EntityBase:
|
||||
var result = null
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
extends Camera2D
|
||||
class_name CameraManager
|
||||
|
||||
@export var shakeOffset: float = 100
|
||||
|
||||
@onready var animator: AnimationPlayer = $"%animator"
|
||||
|
||||
var shaking: bool = false
|
||||
var shakeIntensity: float = 0
|
||||
|
||||
static var instance: CameraManager = null
|
||||
|
||||
@@ -15,14 +13,11 @@ func _ready():
|
||||
func _physics_process(_delta):
|
||||
if is_instance_valid(UIState.player):
|
||||
position = UIState.player.position
|
||||
if shaking:
|
||||
position += MathTool.randv2_range(shakeOffset)
|
||||
position += MathTool.randv2_range(shakeIntensity)
|
||||
|
||||
static func shake(millseconds: int = 1000):
|
||||
print("shake start")
|
||||
instance.shaking = true
|
||||
static func shake(millseconds: int, intensity: float = 10):
|
||||
instance.shakeIntensity += intensity
|
||||
await TickTool.millseconds(millseconds)
|
||||
instance.shaking = false
|
||||
print("shake end")
|
||||
instance.shakeIntensity -= intensity
|
||||
static func playAnimation(animation: String):
|
||||
instance.animator.play(animation)
|
||||
|
||||
Reference in New Issue
Block a user