* 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
67 lines
1.8 KiB
GDScript
67 lines
1.8 KiB
GDScript
class_name Balls extends BallsMultiplayer
|
|
|
|
|
|
func _ready() -> void:
|
|
for ball in bodies.get_children():
|
|
_set_ball_physics(ball)
|
|
|
|
setup_signals()
|
|
setup_multiplayer()
|
|
|
|
func setup_signals() -> void:
|
|
# TODO: Need to refactor to not need server signal collision to
|
|
# then play sounds. Maybe 2nd collider on ball that triggers?
|
|
# Will that work since with clients we:
|
|
# set_deferred("freeze", true)
|
|
# set_physics_process(false)
|
|
#
|
|
# Gods forgive me for my sins....
|
|
MessageBus.subscribe("balls_collide_signal", _on_balls_collide_signal)
|
|
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
if not Globals.multiplayer_data.can_do_request_server_only():
|
|
return
|
|
|
|
if not balls_moving:
|
|
if white_ball.linear_velocity.length() == 0.0:
|
|
return
|
|
|
|
balls_moving = false
|
|
for ball in bodies.get_children():
|
|
if ball.linear_velocity.length() == 0.0: continue
|
|
balls_moving = true
|
|
break
|
|
|
|
if not balls_moving:
|
|
Globals.game_state.balls_stopped_moving.emit()
|
|
|
|
func _on__ball_body_entered(ball: Node) -> void:
|
|
if not Globals.multiplayer_data.can_do_request_server_only():
|
|
return
|
|
|
|
if ball.name == "pool_table":
|
|
# TODO: Get/generate some type of sound/noise like corse texture of table
|
|
return
|
|
|
|
_play_collide_sound(ball)
|
|
MessageBus.emit_propagation_clients_only.rpc(
|
|
"balls_collide_signal", str( ball.get_path() )
|
|
)
|
|
|
|
func _on_balls_collide_signal(ball: String) -> void:
|
|
_play_collide_sound( get_node(ball) )
|
|
|
|
func _play_collide_sound(ball: Node) -> void:
|
|
var speed = ball.linear_velocity.length()
|
|
var speed_norm = clamp(speed / max_speed, 0.0, 1.0)
|
|
var volume = remap(
|
|
speed,
|
|
min_speed, max_speed,
|
|
min_volume_db, max_volume_db
|
|
)
|
|
|
|
ball_sounds.pitch_scale = lerp(min_pitch, max_pitch, pow(speed_norm, 0.5))
|
|
ball_sounds.volume_db = clamp(volume, min_volume_db, max_volume_db)
|
|
ball_sounds.play()
|