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:
@@ -5,8 +5,20 @@ 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
|
||||
@@ -28,8 +40,19 @@ func _on__ball_body_entered(ball: Node) -> void:
|
||||
if not Globals.multiplayer_data.can_do_request_server_only():
|
||||
return
|
||||
|
||||
if ball.name == "pool_table": 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(
|
||||
|
||||
@@ -20,6 +20,7 @@ class_name BallsBase extends Node3D
|
||||
|
||||
var balls_moving: bool = false
|
||||
|
||||
|
||||
func _set_ball_physics(ball: RigidBody3D) -> void:
|
||||
var phy_mat = PhysicsMaterial.new()
|
||||
|
||||
@@ -29,11 +30,16 @@ func _set_ball_physics(ball: RigidBody3D) -> void:
|
||||
|
||||
ball.set_physics_material_override(phy_mat)
|
||||
|
||||
ball.axis_lock_linear_y = true
|
||||
ball.axis_lock_linear_y = true
|
||||
ball.set_mass(ball_mass)
|
||||
ball.set_linear_damp(2.04)
|
||||
ball.set_angular_damp(1.44)
|
||||
|
||||
ball.set_use_continuous_collision_detection(true)
|
||||
ball.contact_monitor = true
|
||||
# NOTE: How many balls can surround a single ball,
|
||||
# therefor worst case is 6 collisions. (think start of game)
|
||||
ball.max_contacts_reported = 6
|
||||
|
||||
ball.body_entered.connect(_on__ball_body_entered)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user