Pews now pew in multiplayer. Game ends but also crashes over network.

This commit is contained in:
Dustin 2025-04-20 16:36:36 -07:00
parent 6dc98d7993
commit 33a9848524
3 changed files with 30 additions and 14 deletions

View File

@ -64,6 +64,7 @@ func _server_disconnected():
end_game()
# Callback from SceneTree, only for clients (not server).
func _connected_fail():
get_tree().set_network_peer(null) # Remove peer
@ -83,14 +84,17 @@ func unregister_player(id):
emit_signal("player_list_changed")
func instance_on_peer_players(_scene :Resource, _node_path :NodePath, _global_position :Vector2 , _as_toplevel = true):
print ("Scene Path: ", _scene.resource_path,
" Instance At: ", _node_path,
" Position : ", _global_position)
# print ("Scene Path: ", _scene.resource_path,
# " Instance At: ", _node_path,
# " Position : ", _global_position)
## was going to create local instance here but, lets see if I don't have to.
## makes me thing that node name and path must be very important for multiplayer
rpc("load_scene_on_all_clients", _scene.resource_path, _node_path, _global_position, _as_toplevel)
remotesync func load_scene_on_all_clients(_scene :String, _node_path :NodePath, _global_position :Vector2 , _as_toplevel = true):
## remote means only runs on peers, remotesync goes both here and in peers
## because I want the node I load in two steps
remote func load_scene_on_all_clients(_scene :String, _node_path :NodePath, _global_position :Vector2 , _as_toplevel = true):
print ( "-- Remote Scene Call -- \n",
" Scene Path: ", _scene,
" Instance At: ", _node_path,
@ -216,8 +220,10 @@ func begin_game():
pre_start_game(spawn_points)
func end_game():
rpc("end_clients_game")
remotesync func end_clients_game():
get_tree().call_group("world","queue_free")
# if has_node("/root/Main/ViewportContainer/Viewport/World"): # Game is in progress.
# # End it

View File

@ -10,23 +10,32 @@ extends Area2D
export var velocity_pps :float = 1
export var lifespan :float = -1
var direction_normal := Vector2(0,0)
puppet var puppet_direction_normal :Vector2
puppet var puppet_position
var time_alive :float = 0.0
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
puppet_direction_normal = direction_normal
puppet_position = global_position
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if is_network_master():
position += direction_normal * velocity_pps * delta
rset("puppet_position", global_position)
else:
global_position = puppet_position
if lifespan != -1:
time_alive += delta
if time_alive > lifespan:
queue_free()
rotate(delta * 10)
position += direction_normal * velocity_pps * delta
##TODO: Haven't determined if I want to create a receiver for projectiles or just inherit from an
## interactable for projectiles.
func _on_body_entered(body):
var colliding_node = body
if colliding_node.has_node("Projectile_Receiver"):

View File

@ -48,23 +48,24 @@ func shoot(direction = 1):
# position.x = position.x * direction #shifting position before fire was unreliable
if not timer.is_stopped():
return false
#var bullet = loaded_scene.instance()
var bullet = NetworkManager.instance_on_peer_players(loaded_scene, self.get_path(), global_position , true)
var bullet = loaded_scene.instance()
# if (direction > 0):
# bullet.global_position = global_position
# else:
# bullet.global_position = global_position - Vector2(position.x * 2, 0)
if bullet is Projectile:
print ("i'm a projectile")
# bullet.global_position = global_position
bullet.global_position = global_position
bullet.direction_normal = normal_vector
#bullet.linear_velocity = Vector2(direction * BULLET_VELOCITY, 0)
#bullet.set_as_toplevel(true)
# add_child(bullet)
bullet.set_as_toplevel(true)
add_child(bullet)
# sound_shoot.play()
timer.start()
NetworkManager.instance_on_peer_players(loaded_scene, self.get_path(), global_position , true)
return true
#var bomb_name = String(get_name()) + str(bomb_index)