Files
CosmicClash/Game/scripts/match_mode.gd
T

49 lines
1.5 KiB
GDScript

extends GameMode
# Timed match: two teams, score tracking, kickoff resets after each goal.
# The opponent ship is currently inert (base ShipController, zero action) —
# it becomes the AI opponent once an AIShipController exists (see TODO.md),
# and additional player ships once multiplayer lands.
signal timer_updated(minutes: int, seconds: int)
signal score_changed(score: Dictionary)
@export var match_length_seconds := 150.0
var score := {0: 0, 1: 0}
var match_timer: Timer
func _start() -> void:
spawn_ball()
var player_ship := spawn_ship(0, 0, PlayerShipController.new())
spawn_camera_rig(player_ship)
spawn_ship(1, 0, ShipController.new()) # inert placeholder opponent
match_timer = Timer.new()
match_timer.one_shot = true
match_timer.wait_time = match_length_seconds
match_timer.timeout.connect(_on_match_timer_timeout)
add_child(match_timer)
match_timer.start()
func _process(_delta):
if match_timer and match_timer.time_left > 0:
var remaining := ceili(match_timer.time_left)
timer_updated.emit(floori(remaining / 60.0), remaining % 60)
func _on_goal_scored(conceding_team: int) -> void:
var scoring_team := 1 - conceding_team
score[scoring_team] += 1
score_changed.emit(score.duplicate())
print("Goal for team %d! Score: %d - %d" % [scoring_team, score[0], score[1]])
reset_ball()
reset_ships()
func _on_match_timer_timeout() -> void:
print("Full time! Final score: %d - %d" % [score[0], score[1]])
get_tree().change_scene_to_file(MAIN_MENU_SCENE_PATH)