mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-06-06 11:47:13 +08:00
feat: 添加掉落物功能,更新饲料和物品显示,重构相关UI组件
This commit is contained in:
@@ -20,6 +20,8 @@ var fields = {
|
||||
ItemStore.ItemType.BASEBALL: 0,
|
||||
ItemStore.ItemType.BASKETBALL: 0
|
||||
}
|
||||
@export var drops: Array[ItemStore.ItemType] = []
|
||||
@export var dropCounts: Array[Vector2] = []
|
||||
|
||||
@onready var animatree: AnimationTree = $"%animatree"
|
||||
@onready var texture: AnimatedSprite2D = $"%texture"
|
||||
@@ -38,7 +40,15 @@ var sprinting: bool = false
|
||||
func _ready():
|
||||
health = fields.get(FieldStore.Entity.MAX_HEALTH)
|
||||
statebar.visible = !isBoss
|
||||
if !isPlayer():
|
||||
if isPlayer():
|
||||
UIState.player = self
|
||||
hurtbox.body_entered.connect(
|
||||
func(body):
|
||||
if body is ItemDropped:
|
||||
inventory[body.item] += body.stackCount
|
||||
body.queue_free()
|
||||
)
|
||||
else:
|
||||
currentFocusedBoss = get_tree().get_nodes_in_group("players")[0]
|
||||
func _process(_delta):
|
||||
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH))
|
||||
@@ -78,7 +88,7 @@ func takeDamage(bullet: BulletBase, crit: bool):
|
||||
if health <= 0:
|
||||
if isBoss:
|
||||
bullet.launcher.setBoss(null)
|
||||
die()
|
||||
tryDie()
|
||||
func isCooldowned():
|
||||
return Time.get_ticks_msec() - lastAttack >= cooldownUnit / fields.get(FieldStore.Entity.ATTACK_SPEED)
|
||||
func startCooldown():
|
||||
@@ -96,6 +106,13 @@ func trySprint():
|
||||
playSound("sprint")
|
||||
sprint()
|
||||
sprinting = true
|
||||
func tryDie():
|
||||
for drop in range(min(len(drops), len(dropCounts))):
|
||||
var item = drops[drop]
|
||||
var count = ceil(randf_range(dropCounts[drop].x, dropCounts[drop].y))
|
||||
for i in range(count):
|
||||
ItemDropped.generate(item, count, position + MathTool.randv2_range(GameRule.itemDroppedSpawnOffset))
|
||||
die()
|
||||
func findWeaponAnchor(weaponName: String):
|
||||
var anchor = $"%weapons".get_node(weaponName)
|
||||
if anchor is Node2D:
|
||||
|
||||
@@ -8,7 +8,7 @@ class_name FieldShow
|
||||
@onready var nameLabel: Label = $"%name"
|
||||
@onready var valueLabel: Label = $"%value"
|
||||
|
||||
func _ready():
|
||||
func _physics_process(_delta):
|
||||
nameLabel.text = FieldStore.entityMap[field]
|
||||
var formattedValue: String
|
||||
var dataType = FieldStore.entityMapType[field]
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
extends Control
|
||||
@@ -0,0 +1,39 @@
|
||||
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 _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)
|
||||
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
|
||||
@@ -8,6 +8,6 @@ class_name ItemShow
|
||||
@onready var avatarTexture: TextureRect = $"%avatar"
|
||||
@onready var countLabel: Label = $"%count"
|
||||
|
||||
func _ready():
|
||||
avatarTexture.texture = load("res://resources/items/%s.svg" % ItemStore.idMap[type])
|
||||
func _physics_process(_delta: float):
|
||||
avatarTexture.texture = ItemStore.getTexture(type)
|
||||
countLabel.text = str(count)
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
extends CanvasLayer
|
||||
class_name UIState
|
||||
|
||||
@onready var baseball = $"%baseball"
|
||||
@onready var basketball = $"%basketball"
|
||||
|
||||
static var player: EntityBase = null
|
||||
static var bossbar: EntityStateBar
|
||||
|
||||
func _ready():
|
||||
bossbar = $"%bossbar"
|
||||
func _process(_delta):
|
||||
bossbar.visible = !!bossbar.entity
|
||||
func _physics_process(_delta):
|
||||
if is_instance_valid(player):
|
||||
baseball.count = player.inventory[ItemStore.ItemType.BASEBALL]
|
||||
basketball.count = player.inventory[ItemStore.ItemType.BASKETBALL]
|
||||
|
||||
Reference in New Issue
Block a user