Work on exports and some fixes to sound and multiplayer functions

This commit is contained in:
2026-01-09 06:53:37 -05:00
parent ec02685065
commit d5ff05ae75
11 changed files with 156 additions and 11 deletions

View File

@@ -49,14 +49,17 @@ func start_level(pawns : Dictionary[int, PawnBaseData]) -> void:
level_synced[1] = true
switch_scene(vs_man_level)
func switch_scene(packed_scene : PackedScene) -> void:
func switch_scene(packed_scene : PackedScene, spawn : bool = true) -> void:
var blinder = blinder_template.instantiate() as TextureRect
var tween = create_tween()
blinder.self_modulate.a = 0
add_child(blinder)
tween.tween_property(blinder, "self_modulate:a", 1, .15)
var spawner = get_tree().get_first_node_in_group("level_spawner") as MultiplayerSpawner
tween.tween_callback(spawner.add_child.bind(packed_scene.instantiate(),true))
if spawn:
var spawner = get_tree().get_first_node_in_group("level_spawner") as MultiplayerSpawner
tween.tween_callback(spawner.add_child.bind(packed_scene.instantiate(),true))
else:
tween.tween_callback(get_tree().change_scene_to_packed.bind(packed_scene))
tween.tween_property(blinder, "self_modulate:a", 0, .15)
tween.tween_callback(blinder.queue_free)

View File

@@ -25,11 +25,12 @@ func become_host() -> void:
multiplayer.peer_disconnected.connect(_remove_player_from_game)
func join_game(new_handle : String) -> Error:
func join_game(new_handle : String, ip : String = "") -> Error:
print("Player 2 joining.")
if ip == "":
ip = SERVER_IP
var client_peer = ENetMultiplayerPeer.new()
var error = client_peer.create_client(SERVER_IP, SERVER_PORT)
var error = client_peer.create_client(ip, SERVER_PORT)
multiplayer.multiplayer_peer = client_peer
handle = new_handle
id = multiplayer.get_unique_id()
@@ -85,3 +86,18 @@ func receive_peer_handle(peer_id, peer_handle) -> void:
@rpc("any_peer", "call_remote")
func report_handle_to_peer(peer_id : int) -> void:
rpc_id(peer_id, "receive_peer_handle", multiplayer.get_unique_id(), handle)
func get_local_ip() -> String:
var ip_address = ""
# Get all local addresses as an Array
var addresses: PackedStringArray = IP.get_local_addresses()
for address in addresses:
# Check if it is an IPv4 address and not a loopback or link-local address
if "." in address and not address.begins_with("127.") and not address.begins_with("169.254."):
# Filter for common private IP ranges (192.168.x.x, 10.x.x.x, 172.16-31.x.x)
if address.begins_with("192.168.") or address.begins_with("10.") or (address.begins_with("172.") and int(address.split(".")[1]) >= 16 and int(address.split(".")[1]) <= 31):
ip_address = address
break # Exit the loop once a valid local IP is found
return ip_address

View File

@@ -33,6 +33,7 @@ func _on_start_hosting_button_pressed() -> void:
#Set fields
%ParticipantsText.text = "[color=FFFF00]*%s (HOST)[/color]\n" % handle
%"Host Waiting".visible = true
%IPLabel.text = Multiplayer.get_local_ip()
Multiplayer.become_host()
@@ -61,7 +62,7 @@ func _on_join_button_pressed() -> void:
#Check for valid game
#If found
%Joining.visible = false
if await Multiplayer.join_game(handle):
if await Multiplayer.join_game(handle, %IPEdit.text):
%"Host Waiting".visible = true
%StartButton.visible = false

View File

@@ -2,6 +2,7 @@ extends MultiplayerSpawner
func _ready() -> void:
print(Multiplayer.get_local_ip())
if Game.net_test:
await get_tree().create_timer(0.25).timeout
Multiplayer.join_game("123")

View File

@@ -68,7 +68,7 @@ func _process(delta: float) -> void:
switch_sound.play()
switch_menu(wrapi(menu_choice + menu_dir, 0, len(menu_list)))
if Input.is_action_just_pressed("ui_accept"):
Game.switch_scene(menu_list[menu_choice].scene)
Game.switch_scene(menu_list[menu_choice].scene, false)
func switch_menu(new_choice : int) -> void: