feat: 添加升级面板到arena,添加全局事件监听升级选择

This commit is contained in:
luke358
2026-05-21 16:32:12 +08:00
parent 1796d9e47d
commit 1cf4eeecc6
9 changed files with 46 additions and 9 deletions
+2
View File
@@ -3,6 +3,8 @@ extends Node
signal on_create_block_text(unit: Node2D)
signal on_create_damage_text(unit: Node2D, hitbox: HitboxComponent)
signal on_upgrade_selected
const FLASH_MATERIAL = preload("uid://cwtrdmkrsmw23")
const FLOATING_TEXT_SCENE = preload("uid://qkwyrg22h3gi")
+1 -1
View File
@@ -28,7 +28,7 @@ metadata/_custom_type_script = "uid://rw3gxqh858sr"
script = ExtResource("1_cx7cn")
from = 1
to = 5
wave_time = 25.0
wave_time = 5.0
units = Array[ExtResource("2_78wao")]([SubResource("Resource_3lh5k"), SubResource("Resource_aei4b"), SubResource("Resource_w8f67")])
spawn_type = 0
fixed_spawn_time = 0.5
+21
View File
@@ -11,12 +11,16 @@ class_name Arena
@onready var wave_index_label: Label = %WaveIndexLabel
@onready var wave_time_label: Label = %WaveTimeLabel
@onready var spawner: Spawner = $Spawner
@onready var upgrade_panel: UpgradePanel = $GameUI/UpgradePanel
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Global.player = player
Global.on_create_block_text.connect(_on_create_block_text)
Global.on_create_damage_text.connect(_on_create_damage_text)
Global.on_upgrade_selected.connect(_on_upgrade_selected)
spawner.start_wave()
func _process(delta: float) -> void:
if Global.game_paused:
@@ -33,6 +37,15 @@ func crteat_floating_text(unit: Node2D) -> FloatingText:
return instace
func show_upgrades() -> void:
upgrade_panel.show()
func start_new_wave() -> void:
Global.game_paused = false
Global.player.update_player_new_weave()
spawner.wave_index += 1
spawner.start_wave()
func _on_create_block_text(unit: Node2D) -> void:
var text := crteat_floating_text(unit)
text.setup("Blocked!", bloacked_color)
@@ -45,3 +58,11 @@ func _on_create_damage_text(unit: Node2D, hitbox: HitboxComponent) -> void:
text.setup(str(hitbox.damage), color)
func _on_upgrade_selected() -> void:
upgrade_panel.hide()
start_new_wave()
func _on_spawner_on_wave_completed() -> void:
if not Global.player: return
await get_tree().create_timer(1.0).timeout
show_upgrades()
+4 -2
View File
@@ -5,7 +5,7 @@
[ext_resource type="Texture2D" uid="uid://ov4fmsbglo55" path="res://assets/sprites/Map.png" id="2_5tue2"]
[ext_resource type="PackedScene" uid="uid://cgljr7wcstmyp" path="res://scenes/unit/players/player_well_rounded.tscn" id="3_5tue2"]
[ext_resource type="Script" uid="uid://cegcsi6n6r4gv" path="res://scenes/arena/camera_2d.gd" id="4_aj7ud"]
[ext_resource type="PackedScene" uid="uid://cp1haphh1gj8t" path="res://scenes/ui/stats_container/stats_container.tscn" id="9_6w4xk"]
[ext_resource type="PackedScene" uid="uid://dufaahmv0ednv" path="res://scenes/ui/upgrade_panel/upgrade_panel.tscn" id="10_2ml6w"]
[ext_resource type="Script" uid="uid://bd5bscq0u8wld" path="res://scenes/arena/spawner.gd" id="17_rhjlh"]
[ext_resource type="Script" uid="uid://dqhoumuppl4bx" path="res://resources/waves/wave_data.gd" id="18_8kk48"]
[ext_resource type="Resource" uid="uid://cer6rdmxrnenh" path="res://resources/waves/data/wave_1_to_5.tres" id="18_tp84n"]
@@ -75,7 +75,9 @@ grow_horizontal = 2
text = "10"
label_settings = SubResource("LabelSettings_wqbss")
[node name="StatsContainer" parent="GameUI" unique_id=827713059 instance=ExtResource("9_6w4xk")]
[node name="UpgradePanel" parent="GameUI" unique_id=35283646 instance=ExtResource("10_2ml6w")]
visible = false
[connection signal="on_wave_completed" from="Spawner" to="." method="_on_spawner_on_wave_completed"]
[connection signal="timeout" from="Spawner/SpawnTimer" to="Spawner" method="_on_spawn_timer_timeout"]
[connection signal="timeout" from="Spawner/WaveTimer" to="Spawner" method="_on_wave_timer_timeout"]
+3 -6
View File
@@ -1,6 +1,8 @@
extends Node2D
class_name Spawner
signal on_wave_completed
@export var spawn_area_size := Vector2(1000, 500)
@export var waves_data: Array[WaveData]
@export var enemy_collection: Array[UnitStats]
@@ -12,12 +14,6 @@ var wave_index := 1
var current_wave_data: WaveData
var spawned_enemies: Array[Enemy] = []
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
start_wave()
func find_wave_data() -> WaveData:
for wave in waves_data:
if wave and wave.is_vaild_index(wave_index):
@@ -96,6 +92,7 @@ func _on_spawn_timer_timeout() -> void:
func _on_wave_timer_timeout() -> void:
Global.game_paused = true
on_wave_completed.emit()
spawn_timer.stop()
clear_enemies()
update_enemies_new_wave()
+7
View File
@@ -14,3 +14,10 @@ func _set_data(value: ItemUpgrade) -> void:
item_name.text = item_data.item_name
item_description.text = item_data.descriptin
func _on_custom_button_pressed() -> void:
if item_data and is_instance_valid(Global.player):
item_data.apply_upgrade()
Global.on_upgrade_selected.emit()
+2
View File
@@ -69,3 +69,5 @@ layout_mode = 1
offset_left = -130.0
offset_top = -58.0
offset_right = 130.0
[connection signal="pressed" from="MarginContainer/Control/CustomButton" to="." method="_on_custom_button_pressed"]
@@ -17,6 +17,7 @@
font_size = 120
[node name="UpgradePanel" type="Panel" unique_id=35283646]
self_modulate = Color(0.34509805, 0.34509805, 0.34509805, 1)
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
+5
View File
@@ -96,6 +96,11 @@ func can_dash() -> bool:
func is_facing_right() -> bool:
return visuals.scale.x == -0.5
func update_player_new_weave() -> void:
stats.health += stats.health_increase_per_wave
health_component.setup(stats)
func _on_dash_timer_timeout() -> void:
is_dashing = false
visuals.modulate.a = 1.0