|
@@ -3,9 +3,15 @@ extends Node2D
|
|
|
@onready var health_bar: HealthBar = $HealthBar
|
|
|
@onready var overlay: CanvasLayer = $Overlay
|
|
|
@onready var transition: Transition = $Overlay/Transition
|
|
|
+@onready var player_spawn: PlayerSpawnZone = $PlayerSpawnZone
|
|
|
@onready var spawn_timer: Timer = $Timer
|
|
|
@onready var ui_root: Control = $UI/Root
|
|
|
@onready var wave_label: Label = $UI/Root/WaveLabel
|
|
|
+@onready var phase_label: Label = $UI/Root/PhaseLabel
|
|
|
+@onready var next_phase_button: Button = $UI/Root/NextPhaseButton
|
|
|
+
|
|
|
+@onready var combat_start_sound: AudioStreamPlayer = $Sounds/CombatStartSound
|
|
|
+@onready var combat_end_sound: AudioStreamPlayer = $Sounds/CombatEndSound
|
|
|
|
|
|
@onready var main_menu: PackedScene = load("res://screens/main_menu.tscn")
|
|
|
@onready var bot_scene: PackedScene = load("res://assets/scenes/bot.tscn")
|
|
@@ -23,7 +29,17 @@ enum Phase {
|
|
|
PHASE_LOOT,
|
|
|
}
|
|
|
|
|
|
-var phase: Phase = Phase.PHASE_SETUP
|
|
|
+var phase: Phase = Phase.PHASE_SETUP:
|
|
|
+ set(new_value):
|
|
|
+ phase = new_value
|
|
|
+ match new_value:
|
|
|
+ Phase.PHASE_SETUP:
|
|
|
+ phase_label.text = "PHASE: SETUP"
|
|
|
+ Phase.PHASE_COMBAT:
|
|
|
+ phase_label.text = "PHASE: COMBAT"
|
|
|
+ Phase.PHASE_LOOT:
|
|
|
+ phase_label.text = "PHASE: LOOT"
|
|
|
+
|
|
|
var waves_completed: int = 0:
|
|
|
set(new_value):
|
|
|
waves_completed = new_value
|
|
@@ -31,15 +47,18 @@ var waves_completed: int = 0:
|
|
|
|
|
|
func _ready() -> void:
|
|
|
waves_completed = 0
|
|
|
+ phase = Phase.PHASE_SETUP
|
|
|
overlay.visible = true
|
|
|
transition.slide_out()
|
|
|
await transition.game_fully_visible
|
|
|
- spawn_bot()
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
|
if Input.is_action_pressed("ui_cancel"):
|
|
|
go_to_main_menu()
|
|
|
-
|
|
|
+ if phase == Phase.PHASE_COMBAT:
|
|
|
+ if get_foes().is_empty():
|
|
|
+ end_combat()
|
|
|
+
|
|
|
func go_to_main_menu() -> void:
|
|
|
var tree = get_tree()
|
|
|
transition.text = ""
|
|
@@ -48,15 +67,44 @@ func go_to_main_menu() -> void:
|
|
|
await transition.game_fully_hidden
|
|
|
tree.change_scene_to_packed(main_menu)
|
|
|
tree.paused = false
|
|
|
-
|
|
|
-func spawn_bot() -> void:
|
|
|
- var spawn = spawn_points.pick_random()
|
|
|
- var bot = bot_scene.instantiate()
|
|
|
+
|
|
|
+func spawn_bot(spawn: Marker2D) -> void:
|
|
|
+ var bot: Bot = bot_scene.instantiate()
|
|
|
bot.global_position = spawn.global_position
|
|
|
+ bot.visible = false
|
|
|
add_child(bot)
|
|
|
|
|
|
+func get_foes() -> Array[Area2D]:
|
|
|
+ var foes: Array[Area2D] = []
|
|
|
+ foes.assign(get_tree().get_nodes_in_group("foe"))
|
|
|
+ return foes
|
|
|
+
|
|
|
+func get_survivors() -> Array[Area2D]:
|
|
|
+ var survivors: Array[Area2D] = []
|
|
|
+ survivors.assign(get_tree().get_nodes_in_group("survivor"))
|
|
|
+ return survivors
|
|
|
+
|
|
|
+func get_waiting_foes() -> Array[Area2D]:
|
|
|
+ return get_foes().filter(func (foe): return not foe.visible)
|
|
|
+
|
|
|
+func get_active_foes() -> Array[Area2D]:
|
|
|
+ return get_foes().filter(func (foe): return foe.visible)
|
|
|
+
|
|
|
+func activate_foe() -> void:
|
|
|
+ var foes = get_waiting_foes()
|
|
|
+ if not foes.is_empty():
|
|
|
+ foes.pick_random().visible = true
|
|
|
+
|
|
|
+func reset_survivors() -> void:
|
|
|
+ var survivors = get_survivors()
|
|
|
+ for survivor in survivors:
|
|
|
+ survivor.reparent(self)
|
|
|
+ for survivor in survivors:
|
|
|
+ player_spawn.drop(survivor)
|
|
|
+ survivor.position = Vector2.ZERO
|
|
|
+
|
|
|
func _on_timer_timeout() -> void:
|
|
|
- spawn_bot()
|
|
|
+ activate_foe()
|
|
|
|
|
|
func base_hit() -> void:
|
|
|
health_bar.health -= 1
|
|
@@ -79,3 +127,36 @@ func game_over() -> void:
|
|
|
func _on_base_area_entered(area: Area2D) -> void:
|
|
|
if area.is_in_group("foe") || area.is_in_group("foe_weapons"):
|
|
|
base_hit()
|
|
|
+
|
|
|
+func start_combat() -> void:
|
|
|
+ for n in (waves_completed + 1):
|
|
|
+ var spawner = spawn_points.pick_random()
|
|
|
+ spawn_bot(spawner)
|
|
|
+ spawn_timer.wait_time = 3.5
|
|
|
+ spawn_timer.start()
|
|
|
+ combat_start_sound.play()
|
|
|
+ activate_foe()
|
|
|
+
|
|
|
+func end_combat() -> void:
|
|
|
+ phase = Phase.PHASE_LOOT
|
|
|
+ next_phase_button.disabled = false
|
|
|
+ next_phase_button.text = "ACCEPT"
|
|
|
+ spawn_timer.stop()
|
|
|
+ combat_end_sound.play()
|
|
|
+
|
|
|
+func _on_next_phase_button_pressed() -> void:
|
|
|
+ match phase:
|
|
|
+ Phase.PHASE_SETUP:
|
|
|
+ phase = Phase.PHASE_COMBAT
|
|
|
+ next_phase_button.disabled = true
|
|
|
+ start_combat()
|
|
|
+ Phase.PHASE_COMBAT:
|
|
|
+ pass # this should not happen
|
|
|
+ Phase.PHASE_LOOT:
|
|
|
+ var next_wave = waves_completed + 2
|
|
|
+ transition.transition("WAVE %d" % next_wave, func ():
|
|
|
+ self.waves_completed += 1
|
|
|
+ self.phase = Phase.PHASE_SETUP
|
|
|
+ self.next_phase_button.text = "NEXT PHASE"
|
|
|
+ self.reset_survivors()
|
|
|
+ )
|