Files
Billiards/controllers/game/modes/base_mode.gd
itdominator e3bdb21cd2 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
2026-08-10 21:22:52 -05:00

60 lines
1.8 KiB
GDScript

class_name BaseMode extends Node
# NOTE: The ball's queue_free is called higher up and after game mode handles
# the ball. Never call it in a given game mode. A game mode should handle
# 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,
"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 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 is_colored_ball(ball_name: String) -> bool:
return ball_name in COLORED_BALLS
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...")