* 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
138 lines
3.6 KiB
GDScript
138 lines
3.6 KiB
GDScript
class_name Billiards extends Node
|
|
|
|
|
|
@onready var game_server: GameServer = $game_server
|
|
@onready var game_client: GameClient = $game_client
|
|
|
|
|
|
#
|
|
#
|
|
# Editor -> Debug > Customize run instance
|
|
#
|
|
# -- client host_snooker bobs_game
|
|
#
|
|
# -- client join bobs_game
|
|
#
|
|
#
|
|
# CLI
|
|
#
|
|
# If going straight to game server:
|
|
# ./billiards.sh -- server_5001 game snooker
|
|
# ./billiards.sh -- join_server 127.0.0.1 5001
|
|
#
|
|
# If going through lobby server:
|
|
# ./billiards.sh -- client host_snooker bobs_game
|
|
# ./billiards.sh -- client join bobs_game
|
|
#
|
|
#
|
|
|
|
|
|
func _ready() -> void:
|
|
add_child(Globals.multiplayer_data.multiplayer_synchronizer)
|
|
move_child(Globals.multiplayer_data.multiplayer_synchronizer, 0)
|
|
|
|
Globals.game_state.set_game_scene(
|
|
"res://scenes/screens/start_screen/start.tscn"
|
|
)
|
|
|
|
_parse_args()
|
|
|
|
func _parse_args() -> void:
|
|
for arg in OS.get_cmdline_user_args():
|
|
if "server_" in arg:
|
|
server_(arg)
|
|
elif "host_" in arg:
|
|
host_(arg)
|
|
|
|
match arg:
|
|
"join_server":
|
|
join_server(arg)
|
|
"client":
|
|
client(arg)
|
|
"game":
|
|
game(arg)
|
|
"join":
|
|
join(arg)
|
|
_:
|
|
pass
|
|
|
|
func _set_game_mode(mode: String) -> void:
|
|
match mode:
|
|
"8ball":
|
|
Globals.game_data.game_mode = "8ball"
|
|
Globals.game_data.SelectedGameMode = \
|
|
Globals.game_data.GameModeType.BALL_8
|
|
"9ball":
|
|
Globals.game_data.game_mode = "9ball"
|
|
Globals.game_data.SelectedGameMode = \
|
|
Globals.game_data.GameModeType.BALL_9
|
|
"snooker":
|
|
Globals.game_data.game_mode = "snooker"
|
|
Globals.game_data.SelectedGameMode = \
|
|
Globals.game_data.GameModeType.SNOOKER
|
|
"freeball":
|
|
Globals.game_data.game_mode = "freeball"
|
|
Globals.game_data.SelectedGameMode = \
|
|
Globals.game_data.GameModeType.FREE_BALL
|
|
_:
|
|
Globals.game_data.game_mode = "freeball"
|
|
Globals.game_data.SelectedGameMode = \
|
|
Globals.game_data.GameModeType.FREE_BALL
|
|
|
|
|
|
func server_(arg: String) -> void:
|
|
var server_port = arg.split("_")[1]
|
|
|
|
game_server.start_server("0.0.0.0", int(server_port))
|
|
|
|
func host_(arg: String) -> void:
|
|
var game_mode = arg.split("_")[1]
|
|
var match_name = OS.get_cmdline_user_args()[-1]
|
|
|
|
while not $scene/lobby_screen.client.lobby_fully_connected:
|
|
await get_tree().process_frame
|
|
|
|
$scene/lobby_screen.find_child(game_mode, true, false).emit_signal("pressed")
|
|
$scene/lobby_screen.find_child("new_match_name_input", true, false).text = match_name
|
|
$scene/lobby_screen.find_child("match_create_bttn", true, false).emit_signal("pressed")
|
|
|
|
func join_server(_arg: String) -> void:
|
|
var server_address = OS.get_cmdline_user_args()[1]
|
|
var server_port = OS.get_cmdline_user_args()[2]
|
|
|
|
Globals.multiplayer_data.set_multiplayer_active()
|
|
|
|
# TODO: Need to check if true still...
|
|
# NOTE: Need to load lobby in order for signals to get bound
|
|
# which then game server calls on its load to do handoff
|
|
Globals.game_state.set_game_scene(
|
|
"res://scenes/screens/lobby_screen/lobby.tscn"
|
|
)
|
|
|
|
game_client.start_client(server_address, int(server_port))
|
|
|
|
func client(_arg: String) -> void:
|
|
Globals.game_state.set_game_scene(
|
|
"res://scenes/screens/lobby_screen/lobby.tscn"
|
|
)
|
|
|
|
$scene/lobby_screen.find_child("host_connect_bttn", true, false).emit_signal("pressed")
|
|
|
|
func game(_arg: String) -> void:
|
|
var game_mode = OS.get_cmdline_user_args()[-1]
|
|
|
|
_set_game_mode(game_mode)
|
|
|
|
Globals.multiplayer_data.set_multiplayer_active()
|
|
Globals.game_state.set_game_scene( "res://scenes/game.tscn" )
|
|
|
|
func join(_arg: String) -> void:
|
|
var _match_id = OS.get_cmdline_user_args()[-1]
|
|
|
|
var button = $scene/lobby_screen.find_child("join_bttn", true, false)
|
|
while not button:
|
|
await get_tree().process_frame
|
|
button = $scene/lobby_screen.find_child("join_bttn", true, false)
|
|
|
|
button.emit_signal("pressed")
|