Pews now pew in multiplayer. Game ends but also crashes over network.
This commit is contained in:
parent
6dc98d7993
commit
33a9848524
|
|
@ -64,6 +64,7 @@ func _server_disconnected():
|
||||||
end_game()
|
end_game()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Callback from SceneTree, only for clients (not server).
|
# Callback from SceneTree, only for clients (not server).
|
||||||
func _connected_fail():
|
func _connected_fail():
|
||||||
get_tree().set_network_peer(null) # Remove peer
|
get_tree().set_network_peer(null) # Remove peer
|
||||||
|
|
@ -83,14 +84,17 @@ func unregister_player(id):
|
||||||
emit_signal("player_list_changed")
|
emit_signal("player_list_changed")
|
||||||
|
|
||||||
func instance_on_peer_players(_scene :Resource, _node_path :NodePath, _global_position :Vector2 , _as_toplevel = true):
|
func instance_on_peer_players(_scene :Resource, _node_path :NodePath, _global_position :Vector2 , _as_toplevel = true):
|
||||||
print ("Scene Path: ", _scene.resource_path,
|
# print ("Scene Path: ", _scene.resource_path,
|
||||||
" Instance At: ", _node_path,
|
# " Instance At: ", _node_path,
|
||||||
" Position : ", _global_position)
|
# " 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)
|
rpc("load_scene_on_all_clients", _scene.resource_path, _node_path, _global_position, _as_toplevel)
|
||||||
|
|
||||||
|
## remote means only runs on peers, remotesync goes both here and in peers
|
||||||
remotesync func load_scene_on_all_clients(_scene :String, _node_path :NodePath, _global_position :Vector2 , _as_toplevel = true):
|
## 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",
|
print ( "-- Remote Scene Call -- \n",
|
||||||
" Scene Path: ", _scene,
|
" Scene Path: ", _scene,
|
||||||
" Instance At: ", _node_path,
|
" Instance At: ", _node_path,
|
||||||
|
|
@ -216,8 +220,10 @@ func begin_game():
|
||||||
|
|
||||||
pre_start_game(spawn_points)
|
pre_start_game(spawn_points)
|
||||||
|
|
||||||
|
|
||||||
func end_game():
|
func end_game():
|
||||||
|
rpc("end_clients_game")
|
||||||
|
|
||||||
|
remotesync func end_clients_game():
|
||||||
get_tree().call_group("world","queue_free")
|
get_tree().call_group("world","queue_free")
|
||||||
# if has_node("/root/Main/ViewportContainer/Viewport/World"): # Game is in progress.
|
# if has_node("/root/Main/ViewportContainer/Viewport/World"): # Game is in progress.
|
||||||
# # End it
|
# # End it
|
||||||
|
|
|
||||||
|
|
@ -10,23 +10,32 @@ extends Area2D
|
||||||
export var velocity_pps :float = 1
|
export var velocity_pps :float = 1
|
||||||
export var lifespan :float = -1
|
export var lifespan :float = -1
|
||||||
var direction_normal := Vector2(0,0)
|
var direction_normal := Vector2(0,0)
|
||||||
|
puppet var puppet_direction_normal :Vector2
|
||||||
|
puppet var puppet_position
|
||||||
|
|
||||||
var time_alive :float = 0.0
|
var time_alive :float = 0.0
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
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.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta):
|
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:
|
if lifespan != -1:
|
||||||
time_alive += delta
|
time_alive += delta
|
||||||
if time_alive > lifespan:
|
if time_alive > lifespan:
|
||||||
queue_free()
|
queue_free()
|
||||||
rotate(delta * 10)
|
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):
|
func _on_body_entered(body):
|
||||||
var colliding_node = body
|
var colliding_node = body
|
||||||
if colliding_node.has_node("Projectile_Receiver"):
|
if colliding_node.has_node("Projectile_Receiver"):
|
||||||
|
|
|
||||||
|
|
@ -48,23 +48,24 @@ func shoot(direction = 1):
|
||||||
# position.x = position.x * direction #shifting position before fire was unreliable
|
# position.x = position.x * direction #shifting position before fire was unreliable
|
||||||
if not timer.is_stopped():
|
if not timer.is_stopped():
|
||||||
return false
|
return false
|
||||||
#var bullet = loaded_scene.instance()
|
var bullet = loaded_scene.instance()
|
||||||
var bullet = NetworkManager.instance_on_peer_players(loaded_scene, self.get_path(), global_position , true)
|
|
||||||
# if (direction > 0):
|
# if (direction > 0):
|
||||||
# bullet.global_position = global_position
|
# bullet.global_position = global_position
|
||||||
# else:
|
# else:
|
||||||
# bullet.global_position = global_position - Vector2(position.x * 2, 0)
|
# bullet.global_position = global_position - Vector2(position.x * 2, 0)
|
||||||
if bullet is Projectile:
|
if bullet is Projectile:
|
||||||
print ("i'm a projectile")
|
print ("i'm a projectile")
|
||||||
# bullet.global_position = global_position
|
bullet.global_position = global_position
|
||||||
bullet.direction_normal = normal_vector
|
bullet.direction_normal = normal_vector
|
||||||
|
|
||||||
#bullet.linear_velocity = Vector2(direction * BULLET_VELOCITY, 0)
|
#bullet.linear_velocity = Vector2(direction * BULLET_VELOCITY, 0)
|
||||||
|
|
||||||
#bullet.set_as_toplevel(true)
|
bullet.set_as_toplevel(true)
|
||||||
# add_child(bullet)
|
add_child(bullet)
|
||||||
# sound_shoot.play()
|
# sound_shoot.play()
|
||||||
timer.start()
|
timer.start()
|
||||||
|
|
||||||
|
NetworkManager.instance_on_peer_players(loaded_scene, self.get_path(), global_position , true)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
#var bomb_name = String(get_name()) + str(bomb_index)
|
#var bomb_name = String(get_name()) + str(bomb_index)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user