feat(game): add free ball mode and improve ball state handling

* add Free Ball game mode and lobby selection
* refactor base mode ball state tracking for reaped/sunk balls
* add player ownership tracking and colored-ball support
* add initial 9-ball mode implementation
* update 8-ball and snooker modes to use base ball handling
* replicate ball linear velocity for multiplayer synchronization
* improve ball collision sound propagation and physics settings
* reenable game music and initialize game signals
* improve lobby input focus and mode selection behavior
* adjust cue impulse origin and default game mode
This commit is contained in:
2026-08-10 21:22:52 -05:00
parent 26dcfe0d1b
commit e3bdb21cd2
19 changed files with 234 additions and 62 deletions

View File

@@ -2,24 +2,22 @@ class_name Ball8 extends BaseMode
func reap_ball(ball: Node3D) -> void:
balls_reaped.append(ball.name)
super(ball)
if ball.name == "08_ball":
# TODO: 8 ball must not be be destroyed. Handle rule...
pass
ball_state[ball.name] = not ball_state[ball.name]
func process_ball(ball: Node3D) -> void:
balls_sunk.append(ball.name)
super(ball)
if ball.name == "08_ball":
# TODO: 8 ball must be sunk last. Handle rule...
pass
ball_state[ball.name] = not ball_state[ball.name]
func handle_switch_user() -> void:
push_warning("Balls reaped: ", balls_reaped.size())
push_warning("Balls sunk: ", balls_sunk.size())
push_warning("Balls reaped: ", balls_reaped.size() )
push_warning("Balls sunk: ", balls_sunk.size() )
if not balls_reaped.is_empty():
# TODO: Handle points, etc

View File

@@ -1 +1,33 @@
class_name Ball9 extends BaseMode
func reap_ball(ball: Node3D) -> void:
super(ball)
if ball.name == "09_ball":
# TODO: 9 ball must not be be destroyed. Handle rule...
pass
func process_ball(ball: Node3D) -> void:
super(ball)
if ball.name == "09_ball":
# TODO: 9 ball must be sunk last. Handle rule...
pass
func handle_switch_user() -> void:
push_warning("Balls reaped: ", balls_reaped.size() )
push_warning("Balls sunk: ", balls_sunk.size() )
if not balls_reaped.is_empty():
# TODO: Handle points, etc
balls_reaped.clear()
if balls_sunk.is_empty():
Globals.game_state.switch_active_player()
return
# TODO: Handle points, etc
# Globals.multiplayer_data.current_turn_player_id
balls_sunk.clear()

View File

@@ -4,26 +4,56 @@ class_name BaseMode extends Node
# these signals to handle game related rules regarding ball sinks.
var player_1_points: int = 0
var player_2_points: int = 0
var ball_state := generate_ball_state()
var balls_sunk := []
var balls_reaped := []
var STATE: Dictionary = {
"sunk": false
"sunk": false,
"reaped": false,
"player": ""
}
var COLORED_BALLS: Array = [
"yellow_ball", "green_ball", "brown_ball",
"blue_ball", "pink_ball", "black_ball"
]
func generate_ball_state() -> Dictionary:
var state := {}
for i in range(1, 16):
state["%02d_ball" % i] = STATE
for ball_name: String in COLORED_BALLS:
state[ball_name] = STATE.duplicate_deep()
for i: int in range(1, 16):
state["%02d_ball" % i] = STATE.duplicate_deep()
return state
func reap_ball(_ball: Node3D) -> void:
assert(false, "This method needs to be overridden...")
func is_colored_ball(ball_name: String) -> bool:
return ball_name in COLORED_BALLS
func process_ball(_ball: Node3D) -> void:
assert(false, "This method needs to be overridden...")
func which_player() -> String:
return \
"Player 1" \
if \
Globals.game_data.client1 == Globals.multiplayer_data.current_turn_player_id \
else \
"Player 2"
func reap_ball(ball: Node3D) -> void:
balls_reaped.append(ball.name)
ball_state[ball.name]["reaped"] = not ball_state[ball.name]["reaped"]
ball_state[ball.name]["player"] = which_player()
func process_ball(ball: Node3D) -> void:
balls_sunk.append(ball.name)
ball_state[ball.name]["sunk"] = not ball_state[ball.name]["sunk"]
ball_state[ball.name]["player"] = which_player()
func handle_switch_user() -> void:
assert(false, "This method needs to be overridden...")

View File

@@ -0,0 +1,25 @@
class_name FreeBall extends BaseMode
func reap_ball(ball: Node3D) -> void:
super(ball)
func process_ball(ball: Node3D) -> void:
super(ball)
func handle_switch_user() -> void:
push_warning("Balls reaped: ", balls_reaped.size() )
push_warning("Balls sunk: ", balls_sunk.size() )
if not balls_reaped.is_empty():
# TODO: Handle points, etc
balls_reaped.clear()
if balls_sunk.is_empty():
Globals.game_state.switch_active_player()
return
# TODO: Handle points, etc
# Globals.multiplayer_data.current_turn_player_id
balls_sunk.clear()

View File

@@ -0,0 +1 @@
uid://d3lmdgym2didk

View File

@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://c5jdawgemyqu8"]
[ext_resource type="Script" uid="uid://cnjaupry2q5aj" path="res://controllers/game/modes/snooker.gd" id="1_3fw5q"]
[node name="free_ball" type="Node"]
script = ExtResource("1_3fw5q")

View File

@@ -7,8 +7,17 @@ func _ready() -> void:
func setup_signals() -> void:
Globals.game_state.balls_stopped_moving.connect(_balls_stopped_moving)
Globals.game_state.process_ball.connect(_process_ball)
Globals.game_state.reap_ball.connect(_reap_ball)
Globals.game_state.process_ball.connect(_process_ball)
func _reap_ball(ball: Node3D) -> void:
if ball.name == "white_ball":
Globals.game_state.white_ball_needs_hard_reset.emit()
return
mode.reap_ball(ball)
rpc("reap_ball", str(ball.get_path()))
func _process_ball(ball: Node3D) -> void:
if ball.name == "white_ball":
@@ -18,11 +27,3 @@ func _process_ball(ball: Node3D) -> void:
mode.process_ball(ball)
rpc("reap_ball", str(ball.get_path()))
func _reap_ball(ball: Node3D) -> void:
if ball.name == "white_ball":
Globals.game_state.white_ball_needs_hard_reset.emit()
return
mode.reap_ball(ball)
rpc("reap_ball", str(ball.get_path()))

View File

@@ -1,25 +1,29 @@
class_name Snooker extends BaseMode
func reap_ball(ball: Node3D) -> void:
balls_reaped.append(ball.name)
if ball.name == "08_ball":
# TODO: 8 ball must not be be destroyed. Handle rule...
pass
# NOTE: The game is sometimes played with fewer red balls- commonly 6 or 10.
# Normally, 15 red balls (1 point) and 6 balls of different colors:
# yellow (2 points), green (3), brown (4), blue (5), pink (6), black (7).
ball_state[ball.name] = not ball_state[ball.name]
func reap_ball(ball: Node3D) -> void:
super(ball)
if is_colored_ball(ball.name):
# TODO: Colored ball must not be be destroyed. Handle rule...
pass
func process_ball(ball: Node3D) -> void:
balls_sunk.append(ball.name)
if ball.name == "08_ball":
# TODO: 8 ball must be sunk last. Handle rule...
super(ball)
if is_colored_ball(ball.name):
# TODO: Colored ball must not be be processed before red ball sunk.
# Handle rule...
pass
ball_state[ball.name] = not ball_state[ball.name]
func handle_switch_user() -> void:
push_warning("Balls reaped: ", balls_reaped.size())
push_warning("Balls sunk: ", balls_sunk.size())
push_warning("Balls reaped: ", balls_reaped.size() )
push_warning("Balls sunk: ", balls_sunk.size() )
if not balls_reaped.is_empty():
# TODO: Handle points, etc