1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 15:01:53 +08:00
Files
Dog-Lynx-And-HCN/scripts/Statemachine/ItemDropped.gd
T
fallingshrimp d4501ae45d feat: 添加新武器彩虹旗和紫水晶簇,调整饲料属性和数值
refactor: 重构子弹生成逻辑,支持分裂和折射效果

fix: 修复掉落物拾取范围和碰撞检测问题

style: 优化UI显示,添加武器品质和类型标签

docs: 更新字段描述,调整部分饲料名称和分类

perf: 优化数学工具函数,添加随机数处理工具

test: 调整波次生成逻辑,添加新敌人类型

build: 添加新资源文件和相关导入配置
2025-09-05 22:23:41 +08:00

60 lines
1.9 KiB
GDScript

extends RigidBody2D
class_name ItemDropped
var item: ItemStore.ItemType = ItemStore.ItemType.BASEBALL
var stackCount: int = 1
var targetPlayer: EntityBase = null
var collecting: bool = false
@onready var texture: Sprite2D = $"%texture"
@onready var animator: AnimationPlayer = $"%animator"
func _ready():
await TickTool.millseconds(100)
body_entered.connect(
func(body):
if body is ItemDropped and !body.collecting:
if body.item == item:
body.stackCount += stackCount
collect()
)
func _process(_delta):
texture.texture = ItemStore.getTexture(item)
func _physics_process(_delta):
if !is_instance_valid(targetPlayer):
targetPlayer = EntityTool.findClosetPlayer(position, WorldManager.tree)
if is_instance_valid(targetPlayer):
if collecting:
linear_velocity = Vector2.ZERO
else:
var direction = (targetPlayer.position - position).normalized()
var speed = 10000.0 / ((targetPlayer.position - position).length() ** (1 / 3.0))
apply_central_force(direction * speed)
angular_velocity = linear_velocity.length() ** (1.0 / 2.25) # 角速度=线速度的2.25次根号
if position.distance_to(targetPlayer.position) < targetPlayer.fields.get(FieldStore.Entity.DROPPED_ITEM_COLLECT_RADIUS):
if targetPlayer.sprinting:
apply_central_force((position - targetPlayer.texture.global_position).normalized() * targetPlayer.velocity.length() * 10)
else:
targetPlayer.collectItem(item, stackCount)
collect()
func collect():
collecting = true
animator.play("collect")
await animator.animation_finished
queue_free()
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