feat(game): improve mode state handling and active player UI

* Rename and consolidate ball state tracking across game modes
* Add ball finalization and win-condition hooks
* Track foul points by negating reaped ball points
* Update turn switching and ball processing flow
* Add active-player indicator to the camera controller UI
* Refresh active-player label when the turn changes
This commit is contained in:
2026-08-12 21:38:49 -05:00
parent 09369d3dd4
commit b931ef5a01
9 changed files with 160 additions and 65 deletions

View File

@@ -18,23 +18,23 @@ var COLORED_BALLS_POINTS: Array[int] = [
func _init() -> void:
pass
func generate_ball_state() -> Dictionary:
func generate_ball_states() -> Dictionary:
var state: Dictionary = {}
for i in COLORED_BALLS.size():
var ball_name = COLORED_BALLS[i]
var points = COLORED_BALLS_POINTS[i]
state[ball_name] = BALL_STATE.duplicate_deep()
state[ball_name] = ball_states.duplicate_deep()
state[ball_name]["points"] = points
# NOTE: Red balls
for i: int in range(1, 16):
var ball_name = "%02d_ball" % i
state[ball_name] = BALL_STATE.duplicate_deep()
state[ball_name] = ball_states.duplicate_deep()
state[ball_name]["points"] = 1
ball_state = state
ball_states = state
return state
func is_colored_ball(ball_name: String) -> bool:
@@ -45,7 +45,7 @@ func reap_ball(ball: Node3D) -> void:
if is_colored_ball(ball.name):
# TODO: Colored ball must not be be destroyed. Handle rule...
ball_state[ball.name]["valid_end"] = false
ball_states[ball.name]["valid_end"] = false
pass
func process_ball(ball: Node3D) -> void:
@@ -62,18 +62,29 @@ func process_ball(ball: Node3D) -> void:
func handle_switch_user() -> void:
push_warning("Balls reaped: ", balls_reaped.size() )
push_warning("Balls sunk: ", balls_sunk.size() )
var switch_player: bool = true
if not balls_reaped.is_empty():
# TODO: Handle points, etc
for ball_name in balls_reaped:
ball_states[ball_name]["points"] = -ball_states[ball_name]["points"]
balls_reaped.clear()
if balls_sunk.is_empty():
Globals.game_state.switch_active_player()
turn_count += 1
if not balls_sunk.is_empty():
# TODO: Handle points, etc, insure color ball not sunk before red ball
switch_player = true
balls_sunk.clear()
if ball_states_finalized():
process_win_condition()
return
# TODO: Handle points, etc
# Globals.multiplayer_data.current_turn_player_id
if switch_player:
Globals.game_state.switch_active_player()
turn_count += 1
else:
turn_count += 1
balls_sunk.clear()
turn_count += 1
func process_win_condition() -> void:
pass