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:
@@ -7,7 +7,7 @@ var player_id: String = ""
|
||||
|
||||
var game_address: String = "0.0.0.0"
|
||||
var game_port: int = 8080
|
||||
var game_mode: String = "snooker"
|
||||
var game_mode: String = "freeball"
|
||||
|
||||
enum PlayerType {
|
||||
Player1,
|
||||
@@ -17,22 +17,25 @@ enum PlayerType {
|
||||
enum GameModeType {
|
||||
BALL_8,
|
||||
BALL_9,
|
||||
SNOOKER
|
||||
SNOOKER,
|
||||
FREE_BALL
|
||||
}
|
||||
|
||||
const MATCH_TYPES: Dictionary = {
|
||||
"8ball": GameModeType.BALL_8,
|
||||
"9ball": GameModeType.BALL_9,
|
||||
"snooker": GameModeType.SNOOKER
|
||||
"snooker": GameModeType.SNOOKER,
|
||||
"freeball": GameModeType.FREE_BALL
|
||||
}
|
||||
|
||||
var GameMode: Dictionary = {
|
||||
GameModeType.BALL_8: Ball8,
|
||||
GameModeType.BALL_9: Ball9,
|
||||
GameModeType.SNOOKER: Snooker
|
||||
GameModeType.SNOOKER: Snooker,
|
||||
GameModeType.FREE_BALL: FreeBall
|
||||
}
|
||||
|
||||
var SelectedGameMode: GameModeType = GameModeType.SNOOKER
|
||||
var SelectedGameMode: GameModeType = GameModeType.FREE_BALL
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
|
||||
@@ -104,11 +104,13 @@ func set_tracking_of_cue(path: String) -> void:
|
||||
func set_tracking_of_ball(path: String) -> void:
|
||||
path = str(path).trim_prefix(str(multiplayer_synchronizer.root_path) + "/")
|
||||
|
||||
var position_pth = NodePath( path + ":position" )
|
||||
var rotation_pth = NodePath( path + ":rotation" )
|
||||
var position_pth = NodePath( path + ":position" )
|
||||
var rotation_pth = NodePath( path + ":rotation" )
|
||||
var linear_velocity_pth = NodePath( path + ":linear_velocity" )
|
||||
|
||||
synchronizer_config.add_property(position_pth)
|
||||
synchronizer_config.add_property(rotation_pth)
|
||||
synchronizer_config.add_property(linear_velocity_pth)
|
||||
|
||||
synchronizer_config.property_set_replication_mode(
|
||||
position_pth, SceneReplicationConfig.REPLICATION_MODE_ON_CHANGE
|
||||
@@ -116,14 +118,20 @@ func set_tracking_of_ball(path: String) -> void:
|
||||
synchronizer_config.property_set_replication_mode(
|
||||
rotation_pth, SceneReplicationConfig.REPLICATION_MODE_ON_CHANGE
|
||||
)
|
||||
synchronizer_config.property_set_replication_mode(
|
||||
linear_velocity_pth, SceneReplicationConfig.REPLICATION_MODE_ON_CHANGE
|
||||
)
|
||||
|
||||
func remove_tracking_of_ball(path: String) -> void:
|
||||
path = str(path).trim_prefix(str(multiplayer_synchronizer.root_path) + "/")
|
||||
|
||||
var position_pth = NodePath(path + ":position")
|
||||
var rotation_pth = NodePath(path + ":rotation")
|
||||
var position_pth = NodePath( path + ":position" )
|
||||
var rotation_pth = NodePath( path + ":rotation" )
|
||||
var linear_velocity_pth = NodePath( path + ":linear_velocity" )
|
||||
|
||||
if synchronizer_config.has_property(position_pth):
|
||||
synchronizer_config.remove_property(position_pth)
|
||||
if synchronizer_config.has_property(rotation_pth):
|
||||
synchronizer_config.remove_property(rotation_pth)
|
||||
if synchronizer_config.has_property(linear_velocity_pth):
|
||||
synchronizer_config.remove_property(linear_velocity_pth)
|
||||
|
||||
@@ -6,12 +6,12 @@ class_name Game extends Node3D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# TODO: Uncomment
|
||||
#base_environment.game_music.stream = load("res://sounds/music/Lobo Loco - 04 (Mountain Bells22).mp3")
|
||||
#base_environment.game_music.stream.loop = true
|
||||
#base_environment.game_music.play()
|
||||
base_environment.game_music.stream = load("res://sounds/music/Lobo Loco - 04 (Mountain Bells22).mp3")
|
||||
base_environment.game_music.stream.loop = true
|
||||
base_environment.game_music.play()
|
||||
|
||||
game_manager.set_mode(Globals.game_data.SelectedGameMode)
|
||||
|
||||
setup_signals()
|
||||
setup_multiplayer()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ func _on_body_entered(body: Node) -> void:
|
||||
|
||||
body.apply_impulse(
|
||||
impulse,
|
||||
global_position - body.global_position
|
||||
body.global_position - $shape.global_position
|
||||
)
|
||||
|
||||
#body.apply_central_impulse(impulse)
|
||||
|
||||
@@ -4,6 +4,8 @@ class_name Lobby extends LobbyBase
|
||||
func _ready() -> void:
|
||||
setup_signals()
|
||||
|
||||
host_address_input.grab_focus()
|
||||
|
||||
func _exit_tree() -> void:
|
||||
# TODO: Maybe no longer needed...
|
||||
if Globals.multiplayer_data.is_multiplayer_active: return
|
||||
@@ -38,6 +40,7 @@ func _on_receive_match_list(matches_list: Array) -> void:
|
||||
_create_match_entry(match_entry)
|
||||
|
||||
client.lobby_fully_connected = true
|
||||
new_match_name_input.grab_focus()
|
||||
|
||||
func _on_match_list_entry_activated(match_id: String) -> void:
|
||||
for match_entry in match_list.get_children():
|
||||
@@ -48,6 +51,8 @@ func _on_match_list_entry_activated(match_id: String) -> void:
|
||||
match_entry.join_bttn.text = "Delete"
|
||||
match_entry.join_bttn.visible = true
|
||||
match_create_vbox.visible = false
|
||||
match_search_input.visible = false
|
||||
match_search_bttn.visible = false
|
||||
|
||||
match_entry.join_bttn.pressed.disconnect(_join_match)
|
||||
match_entry.join_bttn.pressed.connect(
|
||||
@@ -62,8 +67,11 @@ func _on_match_list_entry_removed(match_id: String) -> void:
|
||||
push_warning("Client: Removed Match List Entry...", match_id)
|
||||
|
||||
if active_match && (match_id == active_match.match_id):
|
||||
active_match = null
|
||||
match_create_vbox.visible = true
|
||||
active_match = null
|
||||
match_create_vbox.visible = true
|
||||
match_search_input.visible = true
|
||||
match_search_bttn.visible = false
|
||||
new_match_name_input.grab_focus()
|
||||
|
||||
for match_entry in match_list.get_children():
|
||||
if not active_match:
|
||||
|
||||
@@ -10,6 +10,23 @@ script = ExtResource("1_hhiik")
|
||||
|
||||
[node name="ui" parent="." instance=ExtResource("2_lqt48")]
|
||||
|
||||
[node name="host_address_input" parent="ui/body/left_body/server_host_hbox" index="1"]
|
||||
context_menu_enabled = false
|
||||
select_all_on_focus = true
|
||||
|
||||
[node name="host_port_range" parent="ui/body/left_body/server_host_hbox" index="2"]
|
||||
select_all_on_focus = true
|
||||
|
||||
[node name="match_search_input" parent="ui/body/left_body/search_vbox/search_hbox" index="0"]
|
||||
context_menu_enabled = false
|
||||
|
||||
[node name="right_body" parent="ui/body" index="1"]
|
||||
visible = false
|
||||
|
||||
[node name="new_match_name_input" parent="ui/body/right_body/create_match_hbox" index="0"]
|
||||
context_menu_enabled = false
|
||||
select_all_on_focus = true
|
||||
|
||||
[node name="rpc_signals" type="Node" parent="."]
|
||||
script = ExtResource("3_rurl6")
|
||||
|
||||
@@ -24,5 +41,6 @@ script = ExtResource("4_glu7g")
|
||||
[connection signal="pressed" from="ui/body/right_body/vbox/8ball" to="." method="_on_mode_bttn_pressed" flags=18]
|
||||
[connection signal="pressed" from="ui/body/right_body/vbox/9ball" to="." method="_on_mode_bttn_pressed" flags=18]
|
||||
[connection signal="pressed" from="ui/body/right_body/vbox/snooker" to="." method="_on_mode_bttn_pressed" flags=18]
|
||||
[connection signal="pressed" from="ui/body/right_body/vbox/free_ball" to="." method="_on_mode_bttn_pressed" flags=18]
|
||||
|
||||
[editable path="ui"]
|
||||
|
||||
@@ -10,6 +10,7 @@ const MATCH_ENTRY = preload("res://scenes/screens/lobb
|
||||
|
||||
@onready var search_vbox: VBoxContainer = $ui/body/left_body/search_vbox
|
||||
@onready var match_search_input: LineEdit = $ui/body/left_body/search_vbox/search_hbox/match_search_input
|
||||
@onready var match_search_bttn: Button = $ui/body/left_body/search_vbox/search_hbox/match_search_bttn
|
||||
@onready var match_list: VBoxContainer = $ui/body/left_body/search_vbox/scroll_container/match_list
|
||||
|
||||
@onready var match_create_vbox: VBoxContainer = $ui/body/right_body
|
||||
@@ -18,7 +19,7 @@ const MATCH_ENTRY = preload("res://scenes/screens/lobb
|
||||
@onready var rpc_signals: Node = $rpc_signals
|
||||
@onready var client: LobbyClient = $client
|
||||
|
||||
var active_mode: String = "snooker"
|
||||
var active_mode: String = "freeball"
|
||||
var active_match: HBoxContainer = null
|
||||
|
||||
|
||||
@@ -56,8 +57,7 @@ func _on_match_create_bttn_pressed() -> void:
|
||||
"type": active_mode
|
||||
}
|
||||
|
||||
#MessageBus.emit_request.rpc_id(1, "match_list_add_entry", match_entry)
|
||||
MessageBus.emit_request.rpc("match_list_add_entry", match_entry)
|
||||
|
||||
func _on_mode_bttn_pressed(button: Button) -> void:
|
||||
active_mode = button.text.remove_chars("-").to_lower()
|
||||
active_mode = button.name.remove_chars("_").to_lower()
|
||||
|
||||
@@ -115,7 +115,6 @@ size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="right_body" type="VBoxContainer" parent="body"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
@@ -156,4 +155,10 @@ text = "9-Ball"
|
||||
[node name="snooker" type="Button" parent="body/right_body/vbox"]
|
||||
layout_mode = 2
|
||||
mouse_default_cursor_shape = 2
|
||||
disabled = true
|
||||
text = "Snooker"
|
||||
|
||||
[node name="free_ball" type="Button" parent="body/right_body/vbox"]
|
||||
layout_mode = 2
|
||||
mouse_default_cursor_shape = 2
|
||||
text = "Free Ball"
|
||||
|
||||
Reference in New Issue
Block a user