feat: Implement a new lobby system with configurable match duration, game over screen, and core game state management.
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
extends Node
|
||||
|
||||
# GoalsCycleManager - Handles 60-second goal cycles, scoring, and goal regeneration
|
||||
# Also handles global match timer that ends the game
|
||||
|
||||
const CYCLE_DURATION: float = 30.0
|
||||
const BASE_SCORE: int = 100
|
||||
const TIME_BONUS_MULTIPLIER: float = 2.0
|
||||
|
||||
# Timer state
|
||||
# Cycle timer state (30-second cycles)
|
||||
var current_cycle_timer: float = 0.0
|
||||
var is_cycle_active: bool = false
|
||||
|
||||
# Global match timer state
|
||||
var global_match_timer: float = 0.0
|
||||
var match_duration: float = 180.0 # Default 3 minutes
|
||||
var is_match_active: bool = false
|
||||
|
||||
# Score tracking: peer_id -> score
|
||||
var player_scores: Dictionary = {}
|
||||
|
||||
@@ -22,6 +28,11 @@ signal timer_updated(time_remaining: float)
|
||||
signal score_updated(peer_id: int, new_score: int)
|
||||
signal leaderboard_updated(sorted_scores: Array)
|
||||
|
||||
# Global match signals
|
||||
signal match_started()
|
||||
signal match_ended()
|
||||
signal global_timer_updated(time_remaining: float)
|
||||
|
||||
func _ready():
|
||||
set_process(false)
|
||||
|
||||
@@ -29,6 +40,21 @@ func initialize(main: Node):
|
||||
main_scene = main
|
||||
|
||||
func _process(delta):
|
||||
# Update global match timer if active
|
||||
if is_match_active:
|
||||
global_match_timer -= delta
|
||||
|
||||
if global_match_timer <= 0:
|
||||
global_match_timer = 0
|
||||
_on_match_end()
|
||||
else:
|
||||
emit_signal("global_timer_updated", global_match_timer)
|
||||
|
||||
# Server broadcasts global timer sync every second
|
||||
if multiplayer.is_server() and int(global_match_timer) != int(global_match_timer + delta):
|
||||
rpc("sync_global_timer", global_match_timer)
|
||||
|
||||
# Update cycle timer if cycle is active
|
||||
if not is_cycle_active:
|
||||
return
|
||||
|
||||
@@ -44,6 +70,57 @@ func _process(delta):
|
||||
if multiplayer.is_server() and int(current_cycle_timer) != int(current_cycle_timer + delta):
|
||||
rpc("sync_timer", current_cycle_timer)
|
||||
|
||||
# =============================================================================
|
||||
# Global Match Control
|
||||
# =============================================================================
|
||||
|
||||
func start_match(duration_seconds: float):
|
||||
"""Start the global match timer. Called by server when game starts."""
|
||||
match_duration = duration_seconds
|
||||
global_match_timer = duration_seconds
|
||||
is_match_active = true
|
||||
set_process(true)
|
||||
emit_signal("match_started")
|
||||
|
||||
if multiplayer.is_server():
|
||||
rpc("sync_match_start", duration_seconds)
|
||||
# Also start the first cycle
|
||||
start_cycle()
|
||||
|
||||
func _on_match_end():
|
||||
"""Called when global match timer reaches zero - game over!"""
|
||||
is_match_active = false
|
||||
is_cycle_active = false
|
||||
emit_signal("match_ended")
|
||||
|
||||
if multiplayer.is_server():
|
||||
rpc("sync_match_end")
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func sync_match_start(duration_seconds: float):
|
||||
match_duration = duration_seconds
|
||||
global_match_timer = duration_seconds
|
||||
is_match_active = true
|
||||
set_process(true)
|
||||
emit_signal("match_started")
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func sync_match_end():
|
||||
is_match_active = false
|
||||
is_cycle_active = false
|
||||
emit_signal("match_ended")
|
||||
|
||||
@rpc("authority", "call_local", "unreliable")
|
||||
func sync_global_timer(time_remaining: float):
|
||||
global_match_timer = time_remaining
|
||||
emit_signal("global_timer_updated", time_remaining)
|
||||
|
||||
func get_global_time_remaining() -> float:
|
||||
return global_match_timer
|
||||
|
||||
func is_match_running() -> bool:
|
||||
return is_match_active
|
||||
|
||||
# =============================================================================
|
||||
# Cycle Control
|
||||
# =============================================================================
|
||||
@@ -82,7 +159,6 @@ func sync_timer(time_remaining: float):
|
||||
|
||||
func _on_cycle_end():
|
||||
is_cycle_active = false
|
||||
set_process(false)
|
||||
emit_signal("cycle_ended")
|
||||
|
||||
if multiplayer.is_server():
|
||||
@@ -90,14 +166,15 @@ func _on_cycle_end():
|
||||
_process_cycle_end_for_all_players()
|
||||
rpc("sync_cycle_end")
|
||||
|
||||
# Start new cycle after a brief delay
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
start_cycle()
|
||||
# Only start new cycle if match is still active
|
||||
if is_match_active:
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
if is_match_active: # Check again in case match ended during delay
|
||||
start_cycle()
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func sync_cycle_end():
|
||||
is_cycle_active = false
|
||||
set_process(false)
|
||||
emit_signal("cycle_ended")
|
||||
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user