Compare commits
No commits in common. "33a9848524dc4177b57e5d29413ac8bdb7321d7b" and "67b228e60f870ef7bb25c832ea57943ea94029ed" have entirely different histories.
33a9848524
...
67b228e60f
|
|
@ -64,7 +64,6 @@ 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,24 +82,10 @@ func unregister_player(id):
|
|||
players.erase(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)
|
||||
remote func load_scene_on_all_clients(_scene :PackedScene, _node_path :NodePath, _global_position :Vector2 , _as_toplevel = true):
|
||||
print("did I not get called others: ", players.size())
|
||||
|
||||
## 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)
|
||||
|
||||
## 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,
|
||||
" Position : ", _global_position)
|
||||
|
||||
var new_scene = load(_scene).instance()
|
||||
var new_scene = _scene.instance()
|
||||
var _caller_id = get_tree().get_rpc_sender_id()
|
||||
|
||||
new_scene.set_network_master(_caller_id)
|
||||
|
|
@ -109,13 +94,13 @@ remote func load_scene_on_all_clients(_scene :String, _node_path :NodePath, _glo
|
|||
|
||||
get_node(_node_path).add_child(new_scene)
|
||||
|
||||
# for _player in players:
|
||||
# rpc_id(_player, "load_scene_on_all_clients", _scene, _node_path, _global_position, _as_toplevel )
|
||||
for _player in players:
|
||||
rpc_id(_player, "load_scene_on_all_clients", _scene, _node_path, _global_position, _as_toplevel )
|
||||
|
||||
# if new_scene.get_network_master() == _caller_id:
|
||||
# return new_scene
|
||||
# else:
|
||||
# return null
|
||||
if new_scene.get_network_master() == _caller_id:
|
||||
return new_scene
|
||||
else:
|
||||
return null
|
||||
|
||||
remote func pre_start_game(spawn_points):
|
||||
# Change scene.
|
||||
|
|
@ -220,10 +205,8 @@ func begin_game():
|
|||
|
||||
pre_start_game(spawn_points)
|
||||
|
||||
func end_game():
|
||||
rpc("end_clients_game")
|
||||
|
||||
remotesync func end_clients_game():
|
||||
func end_game():
|
||||
get_tree().call_group("world","queue_free")
|
||||
# if has_node("/root/Main/ViewportContainer/Viewport/World"): # Game is in progress.
|
||||
# # End it
|
||||
|
|
|
|||
|
|
@ -10,32 +10,23 @@ 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():
|
||||
puppet_direction_normal = direction_normal
|
||||
puppet_position = global_position
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# 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"):
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ extends Position2D
|
|||
## Represents a weapon that spawns and shoots bullets.
|
||||
## The Cooldown timer controls the cooldown duration between shots.
|
||||
|
||||
export var scene_path :Resource
|
||||
export var scene_path :PackedScene
|
||||
export var pew_cooldown_time :float = 1.0
|
||||
|
||||
const BULLET_VELOCITY = 350
|
||||
|
|
@ -48,35 +48,22 @@ 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 = loaded_scene.instance()
|
||||
var bullet = NetworkManager.load_scene_on_all_clients(loaded_scene, self.get_path(), global_position , true)
|
||||
# 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)
|
||||
# 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)
|
||||
#var bomb_pos = position
|
||||
#rpc("setup_bomb", bomb_name, bomb_pos, get_tree().get_network_unique_id())
|
||||
|
||||
remotesync func setup_bomb(bomb_name, pos, by_who):
|
||||
var bomb = loaded_scene.instance()
|
||||
bomb.set_name(bomb_name) # Ensure unique name for the bomb
|
||||
bomb.position = pos
|
||||
bomb.from_player = by_who
|
||||
# No need to set network master to bomb, will be owned by server by default
|
||||
get_node("../..").add_child(bomb)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user