mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-29 23:41:54 +08:00
e669bf1c30
- 移除shaking布尔变量,改用shakeIntensity控制震动强度 - 修改shake方法接受强度参数,支持叠加震动效果 - 简化震动逻辑,移除调试打印语句 feat(ItemDropped): 添加物品自动收集功能 - 当物品与玩家距离小于60时自动收集并销毁 - 调用玩家collectItem方法处理收集逻辑 refactor(EntityBase): 重构物品收集逻辑 - 将物品收集逻辑从信号回调移至collectItem方法 - 移除itemCollected信号及相关UI更新代码 - 简化hurtbox连接逻辑 style(World): 调整动画资源顺序 - 交换两个动画资源的定义顺序
46 lines
1.4 KiB
GDScript
46 lines
1.4 KiB
GDScript
extends RigidBody2D
|
|
class_name ItemDropped
|
|
|
|
var item: ItemStore.ItemType = ItemStore.ItemType.BASEBALL
|
|
var stackCount: int = 1
|
|
var targetPlayer: EntityBase = null
|
|
|
|
@onready var texture: Sprite2D = $"%texture"
|
|
|
|
func _ready():
|
|
apply_force(MathTool.randv2_range(30000), MathTool.randv2_range(10))
|
|
func _process(_delta):
|
|
texture.texture = ItemStore.getTexture(item)
|
|
func _physics_process(_delta):
|
|
if !is_instance_valid(targetPlayer):
|
|
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
|
|
var lastDistance = INF
|
|
for player in get_tree().get_nodes_in_group("players"):
|
|
if player is EntityBase:
|
|
if position.distance_to(player.position) < lastDistance:
|
|
lastDistance = position.distance_to(player.position)
|
|
result = player
|
|
return result
|
|
|
|
static func generate(
|
|
itemType: ItemStore.ItemType,
|
|
count: int,
|
|
spawnPosition: Vector2,
|
|
addToWorld: bool = true
|
|
):
|
|
var instance: ItemDropped = preload("res://components/UI/ItemDropped.tscn").instantiate()
|
|
instance.item = itemType
|
|
instance.stackCount = count
|
|
instance.position = spawnPosition
|
|
if addToWorld:
|
|
WorldManager.rootNode.call_deferred("add_child", instance)
|
|
return instance
|