mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +08:00
refactor(武器系统): 重构武器冷却和攻击逻辑
- 将CooldownTimer的startCooldown方法重命名为更简洁的start - 为EntityBase添加weaponStore节点管理武器 - 修改武器攻击逻辑,现在由Weapon类自身处理冷却和攻击 - 调整武器卡片的UI布局和描述居中显示 - 为Rooster角色添加预设武器
This commit is contained in:
@@ -258,6 +258,9 @@ alpha_curve = SubResource("CurveTexture_vvfxd")
|
||||
[node name="EntityBase" type="CharacterBody2D"]
|
||||
script = ExtResource("1_mvol6")
|
||||
|
||||
[node name="weaponStore" type="Node2D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="sounds" type="Node2D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ corner_radius_bottom_right = 5
|
||||
corner_radius_bottom_left = 5
|
||||
|
||||
[node name="WeaponCard" type="PanelContainer"]
|
||||
offset_right = 300.0
|
||||
offset_right = 350.0
|
||||
offset_bottom = 304.0
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_n2ewr")
|
||||
script = ExtResource("1_g802t")
|
||||
@@ -32,6 +32,7 @@ metadata/_edit_lock_ = true
|
||||
[node name="container" type="VBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 10
|
||||
alignment = 1
|
||||
|
||||
[node name="selectBtn" type="Button" parent="container"]
|
||||
unique_name_in_owner = true
|
||||
@@ -80,7 +81,6 @@ quality = 1
|
||||
[node name="description" type="RichTextLabel" parent="container"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 0
|
||||
bbcode_enabled = true
|
||||
text = "造成[color=cyan]10.0[/color]点伤害。"
|
||||
fit_content = true
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
[gd_scene load_steps=13 format=3 uid="uid://bm7ymrri6pykb"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://bm7ymrri6pykb"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cvogxi7mktumf" path="res://components/Abstracts/EntityBase.tscn" id="1_e5pl8"]
|
||||
[ext_resource type="Script" path="res://scripts/Contents/Characters/Rooster.gd" id="2_oqdqd"]
|
||||
[ext_resource type="Texture2D" uid="uid://fn8qx72clh38" path="res://resources/characters/cock/rooster-a.svg" id="2_q0j6j"]
|
||||
[ext_resource type="AudioStream" uid="uid://dclinyhu256xi" path="res://resources/sounds/effect/Low Whoosh.mp3" id="3_4syso"]
|
||||
[ext_resource type="Texture2D" uid="uid://ci2ik43ce82uy" path="res://resources/characters/cock/rooster-b.svg" id="3_b0fgx"]
|
||||
[ext_resource type="PackedScene" uid="uid://c0n3igy4hucrg" path="res://components/Weapons/PurpleCrystal.tscn" id="3_ms5sq"]
|
||||
[ext_resource type="AudioStream" uid="uid://cdrevrq7n6yqa" path="res://resources/sounds/effect/Boing.mp3" id="4_66s6c"]
|
||||
[ext_resource type="PackedScene" uid="uid://cxabqjo7skxev" path="res://components/Weapons/BigLaser.tscn" id="4_0862n"]
|
||||
[ext_resource type="AudioStream" uid="uid://benyec5bqni0b" path="res://resources/sounds/effect/Chomp.wav" id="4_k0yme"]
|
||||
[ext_resource type="AudioStream" uid="uid://dmxh3bpk8vyy5" path="res://resources/sounds/effect/Coin.mp3" id="5_xnbhq"]
|
||||
[ext_resource type="AudioStream" uid="uid://4wuuf1osk0yv" path="res://resources/sounds/effect/Low Boing.wav" id="6_m5px1"]
|
||||
@@ -38,8 +40,13 @@ radius = 41.0122
|
||||
|
||||
[node name="Rooster" instance=ExtResource("1_e5pl8")]
|
||||
script = ExtResource("2_oqdqd")
|
||||
cooldownUnit = 200.0
|
||||
energy = 50.0
|
||||
|
||||
[node name="weaponStore" parent="." index="0"]
|
||||
process_mode = 4
|
||||
|
||||
[node name="PurpleCrystal" parent="weaponStore" index="0" instance=ExtResource("3_ms5sq")]
|
||||
|
||||
[node name="BigLaser" parent="weaponStore" index="1" instance=ExtResource("4_0862n")]
|
||||
|
||||
[node name="sprint" parent="sounds" index="0"]
|
||||
stream = ExtResource("4_66s6c")
|
||||
@@ -53,13 +60,13 @@ stream = ExtResource("5_xnbhq")
|
||||
[node name="hurt" parent="sounds" index="3"]
|
||||
stream = ExtResource("6_m5px1")
|
||||
|
||||
[node name="attack0" parent="sounds" index="4"]
|
||||
stream = ExtResource("3_4syso")
|
||||
|
||||
[node name="attack1" type="AudioStreamPlayer2D" parent="sounds" index="5"]
|
||||
stream = ExtResource("8_7dhim")
|
||||
|
||||
[node name="texture" parent="." index="1"]
|
||||
[node name="attack0" parent="sounds" index="6"]
|
||||
stream = ExtResource("3_4syso")
|
||||
|
||||
[node name="texture" parent="." index="2"]
|
||||
position = Vector2(0, -70)
|
||||
sprite_frames = SubResource("SpriteFrames_4v2ol")
|
||||
animation = &"walk"
|
||||
@@ -71,6 +78,6 @@ shape = SubResource("CircleShape2D_h1v0q")
|
||||
[node name="normal" type="Node2D" parent="texture/weapons" index="0"]
|
||||
position = Vector2(54, -45)
|
||||
|
||||
[node name="statebar" parent="." index="2" node_paths=PackedStringArray("entity")]
|
||||
[node name="statebar" parent="." index="3" node_paths=PackedStringArray("entity")]
|
||||
position = Vector2(0, -151)
|
||||
entity = NodePath("..")
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://c0n3igy4hucrg"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://c0n3igy4hucrg"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://ckq2cq6m23hq3" path="res://components/Abstracts/WeaponCardBase.tscn" id="1_hyubh"]
|
||||
[ext_resource type="Script" path="res://scripts/Contents/Weapons/PurpleCrystal.gd" id="2_0xgcv"]
|
||||
[ext_resource type="Texture2D" uid="uid://16yhngg3jpun" path="res://resources/weapons/purple-crystal.svg" id="2_wgtcw"]
|
||||
|
||||
[node name="PurpleCrystal" instance=ExtResource("1_hyubh")]
|
||||
offset_right = 208.0
|
||||
offset_bottom = 280.0
|
||||
offset_bottom = 282.0
|
||||
script = ExtResource("2_0xgcv")
|
||||
avatarTexture = ExtResource("2_wgtcw")
|
||||
displayName = "紫水晶簇"
|
||||
costs = Array[int]([0, 1])
|
||||
costCounts = Array[int]([50, 10])
|
||||
descriptionTemplate = "撞击造成$atk点伤害。"
|
||||
cooldown = 200.0
|
||||
|
||||
[node name="avatar" parent="container/info" index="0"]
|
||||
texture = ExtResource("2_wgtcw")
|
||||
|
||||
@@ -7,3 +7,5 @@ func update(to: int, origin: Dictionary, _entity: EntityBase):
|
||||
func attack(entity: EntityBase):
|
||||
var weaponPos = entity.findWeaponAnchor("normal")
|
||||
BulletBase.generate(preload("res://components/Bullets/PurpleCrystal.tscn"), entity, weaponPos, (get_global_mouse_position() - weaponPos).angle())
|
||||
print("test2")
|
||||
return true
|
||||
|
||||
@@ -5,7 +5,7 @@ var lastStart: int = 0
|
||||
|
||||
func isCooldowned():
|
||||
return WorldManager.getTime() - lastStart >= cooldown
|
||||
func startCooldown():
|
||||
func start():
|
||||
var state = isCooldowned()
|
||||
if state:
|
||||
lastStart = WorldManager.getTime()
|
||||
|
||||
@@ -64,7 +64,6 @@ var inventoryMax = {
|
||||
@export var dropCounts: Array[Vector2] = []
|
||||
@export var appleCount: Vector2i = Vector2(0, 2) # 死亡后掉落的苹果数量
|
||||
@export var level: int = 1
|
||||
@export var weapons: Array[Weapon] = []
|
||||
|
||||
@onready var animatree: AnimationTree = $"%animatree"
|
||||
@onready var texture: AnimatedSprite2D = $"%texture"
|
||||
@@ -73,6 +72,7 @@ var inventoryMax = {
|
||||
@onready var hurtAnimator: AnimationPlayer = $"%hurtAnimator"
|
||||
@onready var damageAnchor: Node2D = $"%damageAnchor"
|
||||
@onready var trailParticle: GPUParticles2D = $"%trailParticle"
|
||||
@onready var weaponStore = $"%weaponStore"
|
||||
var statebar: EntityStateBar
|
||||
|
||||
var health: float = 0
|
||||
@@ -84,6 +84,7 @@ var lastDirection: int = 1
|
||||
var currentFocusedBoss: EntityBase = null
|
||||
var charginup: bool = false
|
||||
var cooldownTimer = CooldownTimer.new()
|
||||
var weapons: Array[Weapon] = []
|
||||
|
||||
func _ready():
|
||||
register()
|
||||
@@ -94,6 +95,9 @@ func _ready():
|
||||
statebar = selfStatebar
|
||||
statebar.entity = self
|
||||
if isPlayer():
|
||||
for i in weaponStore.get_children():
|
||||
i.hide()
|
||||
weapons.append(i)
|
||||
statebar.levelLabels.hide()
|
||||
UIState.player = self
|
||||
energyChanged.connect(
|
||||
@@ -190,16 +194,27 @@ func useEnergy(value: float):
|
||||
energyChanged.emit(energy)
|
||||
return state
|
||||
func tryAttack(type: int, needChargeUp: bool = false):
|
||||
var weapon: Weapon
|
||||
if isPlayer():
|
||||
weapon = weapons[type]
|
||||
var state
|
||||
if !isPlayer():
|
||||
if isPlayer():
|
||||
state = weapon.cooldownTimer.start()
|
||||
else:
|
||||
cooldownTimer.cooldown = attackCooldownMap.get(type, defaultCooldownUnit)
|
||||
state = cooldownTimer.startCooldown()
|
||||
state = cooldownTimer.start()
|
||||
if state:
|
||||
if needChargeUp:
|
||||
charginup = true
|
||||
await EffectController.create(preload("res://components/Effects/AttackStar.tscn"), damageAnchor.global_position).shot()
|
||||
charginup = false
|
||||
if attack(type):
|
||||
var done
|
||||
if isPlayer():
|
||||
done = weapon.attack(self)
|
||||
print("test", done, weapon.name)
|
||||
else:
|
||||
done = attack(type)
|
||||
if done:
|
||||
playSound("attack" + str(type))
|
||||
return state
|
||||
func trySprint():
|
||||
|
||||
@@ -24,11 +24,14 @@ signal selected(applied: bool)
|
||||
@onready var costsBox: GridContainer = $"%costs"
|
||||
@onready var selectButton: Button = $"%selectBtn"
|
||||
|
||||
var cooldownTimer = CooldownTimer.new()
|
||||
|
||||
func _ready():
|
||||
selectButton.pressed.connect(
|
||||
func():
|
||||
apply(UIState.player)
|
||||
)
|
||||
cooldownTimer.cooldown = cooldown
|
||||
rebuildInfo()
|
||||
func _physics_process(_delta: float):
|
||||
descriptionLabel.text = buildDescription()
|
||||
@@ -76,7 +79,7 @@ func buildDescription():
|
||||
var result = descriptionTemplate
|
||||
for key in store.keys():
|
||||
result = result.replace("$" + key, "[color=cyan]%.1f[/color]" % readStore(key))
|
||||
return result
|
||||
return "[center]%s[/center]" % result
|
||||
func readStore(key: String, default: Variant = null):
|
||||
return store.get(key, default)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user