mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +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]
|
||||
|
||||
@@ -13,7 +13,14 @@ class_name Feed
|
||||
@onready var nameLabel: RichTextLabel = $"%name"
|
||||
@onready var fieldsBox: VBoxContainer = $"%fields"
|
||||
@onready var costsBox: GridContainer = $"%costs"
|
||||
@onready var selectButton: Button = $"%selectBtn"
|
||||
|
||||
func _ready():
|
||||
selectButton.pressed.connect(
|
||||
func():
|
||||
apply(UIState.player)
|
||||
queue_free()
|
||||
)
|
||||
func _process(_delta):
|
||||
avatarRect.texture = avatarTexture
|
||||
nameLabel.text = "[b]" + displayName + "[/b]"
|
||||
@@ -39,6 +46,7 @@ func _process(_delta):
|
||||
costShow.type = cost
|
||||
costShow.count = count
|
||||
costsBox.add_child(costShow)
|
||||
|
||||
func apply(entity: EntityBase):
|
||||
var allHave = true
|
||||
for i in range(min(costs.size(), costCounts.size())):
|
||||
|
||||
@@ -3,4 +3,5 @@ class_name GameRule
|
||||
static var allowFriendlyFire: bool = false # 是否允许友军伤害
|
||||
static var bulletSpeedMultiplier: float = 1 # 子弹速度倍率
|
||||
static var damageOffset: float = 0.2 # 伤害随机浮动比例,默认20%,即10的基础伤害会应用为8~12
|
||||
static var damageLabelSpawnOffset: float = 10 # 伤害标签生成位置的随机偏移
|
||||
static var damageLabelSpawnOffset: float = 10 # 伤害标签生成位置的随机偏移
|
||||
static var itemDroppedSpawnOffset: float = 10 # 掉落物生成位置的随机偏移
|
||||
|
||||
@@ -12,4 +12,6 @@ static var nameMap = {
|
||||
static var idMap = {
|
||||
ItemType.BASEBALL: "baseball",
|
||||
ItemType.BASKETBALL: "basketball"
|
||||
}
|
||||
}
|
||||
static func getTexture(type: ItemType) -> Texture2D:
|
||||
return load("res://resources/items/%s.svg" % idMap[type])
|
||||
Reference in New Issue
Block a user