diff --git a/networking/multiplayer_bomber/bomb.gd b/networking/multiplayer_bomber/bomb.gd index 2318d92e..e9c73869 100644 --- a/networking/multiplayer_bomber/bomb.gd +++ b/networking/multiplayer_bomber/bomb.gd @@ -3,21 +3,25 @@ extends Area2D var in_area = [] var from_player -# Called from the animation +# Called from the animation. func explode(): if not is_network_master(): - # But will call explosion only on master + # Explode only on master. return for p in in_area: if p.has_method("exploded"): - p.rpc("exploded", from_player) # Exploded has a master keyword, so it will only be received by the master + # Exploded has a master keyword, so it will only be received by the master. + p.rpc("exploded", from_player) + func done(): queue_free() + func _on_bomb_body_enter(body): if not body in in_area: in_area.append(body) + func _on_bomb_body_exit(body): in_area.erase(body) diff --git a/networking/multiplayer_bomber/bomb.tscn b/networking/multiplayer_bomber/bomb.tscn index 90c4a8fe..932f56cb 100644 --- a/networking/multiplayer_bomber/bomb.tscn +++ b/networking/multiplayer_bomber/bomb.tscn @@ -32,7 +32,7 @@ scale_curve = SubResource( 4 ) [sub_resource type="Animation" id=6] length = 4.0 tracks/0/type = "value" -tracks/0/path = NodePath("sprite:self_modulate") +tracks/0/path = NodePath("Sprite:self_modulate") tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/imported = false @@ -61,7 +61,7 @@ tracks/1/keys = { } ] } tracks/2/type = "value" -tracks/2/path = NodePath("explosion1:emitting") +tracks/2/path = NodePath("Explosion1:emitting") tracks/2/interp = 1 tracks/2/loop_wrap = true tracks/2/imported = false @@ -73,7 +73,7 @@ tracks/2/keys = { "values": [ false, true ] } tracks/3/type = "value" -tracks/3/path = NodePath("explosion2:emitting") +tracks/3/path = NodePath("Explosion2:emitting") tracks/3/interp = 1 tracks/3/loop_wrap = true tracks/3/imported = false @@ -85,22 +85,22 @@ tracks/3/keys = { "values": [ false, true ] } -[node name="bomb" type="Area2D"] +[node name="Bomb" type="Area2D"] script = ExtResource( 1 ) -[node name="sprite" type="Sprite" parent="."] +[node name="Sprite" type="Sprite" parent="."] position = Vector2( -2.92606, -2.92606 ) texture = ExtResource( 2 ) region_enabled = true region_rect = Rect2( 144, 0, 48, 48 ) -[node name="shape1" type="CollisionShape2D" parent="."] +[node name="Shape1" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) -[node name="shape2" type="CollisionShape2D" parent="."] +[node name="Shape2" type="CollisionShape2D" parent="."] shape = SubResource( 2 ) -[node name="explosion1" type="Particles2D" parent="."] +[node name="Explosion1" type="Particles2D" parent="."] emitting = false lifetime = 0.5 one_shot = true @@ -108,7 +108,7 @@ explosiveness = 0.95 process_material = SubResource( 5 ) texture = ExtResource( 3 ) -[node name="explosion2" type="Particles2D" parent="."] +[node name="Explosion2" type="Particles2D" parent="."] rotation = 1.57162 emitting = false one_shot = true @@ -116,9 +116,8 @@ explosiveness = 0.95 process_material = SubResource( 5 ) texture = ExtResource( 3 ) -[node name="anim" type="AnimationPlayer" parent="."] +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] autoplay = "anim" anims/anim = SubResource( 6 ) - [connection signal="body_entered" from="." to="." method="_on_bomb_body_enter"] [connection signal="body_exited" from="." to="." method="_on_bomb_body_exit"] diff --git a/networking/multiplayer_bomber/gamestate.gd b/networking/multiplayer_bomber/gamestate.gd index d18dc27c..c6f0ee08 100644 --- a/networking/multiplayer_bomber/gamestate.gd +++ b/networking/multiplayer_bomber/gamestate.gd @@ -1,55 +1,61 @@ extends Node -# Default game port +# Default game port. Can be any number between 1024 and 49151. const DEFAULT_PORT = 10567 -# Max number of players +# Max number of players. const MAX_PEERS = 12 -# Name for my player +# Name for my player. var player_name = "The Warrior" -# Names for remote players in id:name format +# Names for remote players in id:name format. var players = {} +var players_ready = [] -# Signals to let lobby GUI know what's going on +# Signals to let lobby GUI know what's going on. signal player_list_changed() signal connection_failed() signal connection_succeeded() signal game_ended() signal game_error(what) -# Callback from SceneTree +# Callback from SceneTree. func _player_connected(id): - # Registration of a client beings here, tell the connected player that we are here + # Registration of a client beings here, tell the connected player that we are here. rpc_id(id, "register_player", player_name) -# Callback from SceneTree + +# Callback from SceneTree. func _player_disconnected(id): - if has_node("/root/world"): # Game is in progress + if has_node("/root/World"): # Game is in progress. if get_tree().is_network_server(): emit_signal("game_error", "Player " + players[id] + " disconnected") end_game() - else: # Game is not in progress - # Unregister this player + else: # Game is not in progress. + # Unregister this player. unregister_player(id) -# Callback from SceneTree, only for clients (not server) + +# Callback from SceneTree, only for clients (not server). func _connected_ok(): # We just connected to a server emit_signal("connection_succeeded") -# Callback from SceneTree, only for clients (not server) + +# Callback from SceneTree, only for clients (not server). func _server_disconnected(): emit_signal("game_error", "Server disconnected") end_game() -# Callback from SceneTree, only for clients (not server) + +# Callback from SceneTree, only for clients (not server). func _connected_fail(): get_tree().set_network_peer(null) # Remove peer emit_signal("connection_failed") -# Lobby management functions + +# Lobby management functions. remote func register_player(new_player_name): var id = get_tree().get_rpc_sender_id() @@ -57,51 +63,53 @@ remote func register_player(new_player_name): players[id] = new_player_name emit_signal("player_list_changed") + func unregister_player(id): players.erase(id) emit_signal("player_list_changed") + remote func pre_start_game(spawn_points): - # Change scene + # Change scene. var world = load("res://world.tscn").instance() get_tree().get_root().add_child(world) - get_tree().get_root().get_node("lobby").hide() + get_tree().get_root().get_node("Lobby").hide() var player_scene = load("res://player.tscn") for p_id in spawn_points: - var spawn_pos = world.get_node("spawn_points/" + str(spawn_points[p_id])).position + var spawn_pos = world.get_node("SpawnPoints/" + str(spawn_points[p_id])).position var player = player_scene.instance() - player.set_name(str(p_id)) # Use unique ID as node name + player.set_name(str(p_id)) # Use unique ID as node name. player.position=spawn_pos - player.set_network_master(p_id) #set unique id as master + player.set_network_master(p_id) #set unique id as master. if p_id == get_tree().get_network_unique_id(): - # If node for this peer id, set name + # If node for this peer id, set name. player.set_player_name(player_name) else: - # Otherwise set name from peer + # Otherwise set name from peer. player.set_player_name(players[p_id]) - world.get_node("players").add_child(player) + world.get_node("Players").add_child(player) - # Set up score - world.get_node("score").add_player(get_tree().get_network_unique_id(), player_name) + # Set up score. + world.get_node("Score").add_player(get_tree().get_network_unique_id(), player_name) for pn in players: - world.get_node("score").add_player(pn, players[pn]) + world.get_node("Score").add_player(pn, players[pn]) if not get_tree().is_network_server(): - # Tell server we are ready to start + # Tell server we are ready to start. rpc_id(1, "ready_to_start", get_tree().get_network_unique_id()) elif players.size() == 0: post_start_game() + remote func post_start_game(): get_tree().set_pause(false) # Unpause and unleash the game! -var players_ready = [] remote func ready_to_start(id): assert(get_tree().is_network_server()) @@ -114,48 +122,54 @@ remote func ready_to_start(id): rpc_id(p, "post_start_game") post_start_game() + func host_game(new_player_name): player_name = new_player_name var host = NetworkedMultiplayerENet.new() host.create_server(DEFAULT_PORT, MAX_PEERS) get_tree().set_network_peer(host) + func join_game(ip, new_player_name): player_name = new_player_name - var host = NetworkedMultiplayerENet.new() - host.create_client(ip, DEFAULT_PORT) - get_tree().set_network_peer(host) + var client = NetworkedMultiplayerENet.new() + client.create_client(ip, DEFAULT_PORT) + get_tree().set_network_peer(client) + func get_player_list(): return players.values() + func get_player_name(): return player_name + func begin_game(): assert(get_tree().is_network_server()) - # Create a dictionary with peer id and respective spawn points, could be improved by randomizing + # Create a dictionary with peer id and respective spawn points, could be improved by randomizing. var spawn_points = {} - spawn_points[1] = 0 # Server in spawn point 0 + spawn_points[1] = 0 # Server in spawn point 0. var spawn_point_idx = 1 for p in players: spawn_points[p] = spawn_point_idx spawn_point_idx += 1 - # Call to pre-start game with the spawn points + # Call to pre-start game with the spawn points. for p in players: rpc_id(p, "pre_start_game", spawn_points) pre_start_game(spawn_points) + func end_game(): - if has_node("/root/world"): # Game is in progress + if has_node("/root/World"): # Game is in progress. # End it - get_node("/root/world").queue_free() + get_node("/root/World").queue_free() emit_signal("game_ended") players.clear() - get_tree().set_network_peer(null) # End networking + func _ready(): get_tree().connect("network_peer_connected", self, "_player_connected") diff --git a/networking/multiplayer_bomber/lobby.gd b/networking/multiplayer_bomber/lobby.gd index c6872458..7d04f2d6 100644 --- a/networking/multiplayer_bomber/lobby.gd +++ b/networking/multiplayer_bomber/lobby.gd @@ -7,66 +7,82 @@ func _ready(): gamestate.connect("player_list_changed", self, "refresh_lobby") gamestate.connect("game_ended", self, "_on_game_ended") gamestate.connect("game_error", self, "_on_game_error") + # Set the player name according to the system username. Fallback to the path. + if OS.has_environment("USERNAME"): + $Connect/Name.text = OS.get_environment("USERNAME") + else: + var desktop_path = OS.get_system_dir(0).replace("\\", "/").split("/") + $Connect/Name.text = desktop_path[desktop_path.size() - 2] + func _on_host_pressed(): - if get_node("connect/name").text == "": - get_node("connect/error_label").text = "Invalid name!" + if $Connect/Name.text == "": + $Connect/ErrorLabel.text = "Invalid name!" return - get_node("connect").hide() - get_node("players").show() - get_node("connect/error_label").text = "" + $Connect.hide() + $Players.show() + $Connect/ErrorLabel.text = "" - var player_name = get_node("connect/name").text + var player_name = $Connect/Name.text gamestate.host_game(player_name) refresh_lobby() + func _on_join_pressed(): - if get_node("connect/name").text == "": - get_node("connect/error_label").text = "Invalid name!" + if $Connect/Name.text == "": + $Connect/ErrorLabel.text = "Invalid name!" return - var ip = get_node("connect/ip").text + var ip = $Connect/IPAddress.text if not ip.is_valid_ip_address(): - get_node("connect/error_label").text = "Invalid IPv4 address!" + $Connect/ErrorLabel.text = "Invalid IP address!" return - get_node("connect/error_label").text="" - get_node("connect/host").disabled = true - get_node("connect/join").disabled = true + $Connect/ErrorLabel.text = "" + $Connect/Host.disabled = true + $Connect/Join.disabled = true - var player_name = get_node("connect/name").text + var player_name = $Connect/Name.text gamestate.join_game(ip, player_name) - # refresh_lobby() gets called by the player_list_changed signal + func _on_connection_success(): - get_node("connect").hide() - get_node("players").show() + $Connect.hide() + $Players.show() + func _on_connection_failed(): - get_node("connect/host").disabled = false - get_node("connect/join").disabled = false - get_node("connect/error_label").set_text("Connection failed.") + $Connect/Host.disabled = false + $Connect/Join.disabled = false + $Connect/ErrorLabel.set_text("Connection failed.") + func _on_game_ended(): show() - get_node("connect").show() - get_node("players").hide() - get_node("connect/host").disabled = false + $Connect.show() + $Players.hide() + $Connect/Host.disabled = false + $Connect/Join.disabled = false + func _on_game_error(errtxt): - get_node("error").dialog_text = errtxt - get_node("error").popup_centered_minsize() + $ErrorDialog.dialog_text = errtxt + $ErrorDialog.popup_centered_minsize() + $Connect/Host.disabled = false + $Connect/Join.disabled = false + func refresh_lobby(): var players = gamestate.get_player_list() players.sort() - get_node("players/list").clear() - get_node("players/list").add_item(gamestate.get_player_name() + " (You)") + $Players/List.clear() + $Players/List.add_item(gamestate.get_player_name() + " (You)") for p in players: - get_node("players/list").add_item(p) + $Players/List.add_item(p) + + $Players/Start.disabled = not get_tree().is_network_server() - get_node("players/start").disabled = not get_tree().is_network_server() func _on_start_pressed(): gamestate.begin_game() diff --git a/networking/multiplayer_bomber/lobby.tscn b/networking/multiplayer_bomber/lobby.tscn index cfb2bce7..c923ba1d 100644 --- a/networking/multiplayer_bomber/lobby.tscn +++ b/networking/multiplayer_bomber/lobby.tscn @@ -2,7 +2,7 @@ [ext_resource path="res://lobby.gd" type="Script" id=1] -[node name="lobby" type="Control"] +[node name="Lobby" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 size_flags_horizontal = 2 @@ -12,7 +12,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="players" type="Panel" parent="."] +[node name="Players" type="Panel" parent="."] visible = false anchor_left = 0.5 anchor_top = 0.5 @@ -25,7 +25,7 @@ margin_bottom = 177.5 size_flags_horizontal = 2 size_flags_vertical = 2 -[node name="label" type="Label" parent="players"] +[node name="Label" type="Label" parent="Players"] margin_left = 26.0 margin_top = 18.0 margin_right = 142.0 @@ -34,7 +34,7 @@ size_flags_horizontal = 2 size_flags_vertical = 0 text = "Awaiting Players..." -[node name="start" type="Button" parent="players"] +[node name="Start" type="Button" parent="Players"] margin_left = 68.0 margin_top = 307.0 margin_right = 193.0 @@ -43,7 +43,7 @@ size_flags_horizontal = 2 size_flags_vertical = 2 text = "START!" -[node name="list" type="ItemList" parent="players"] +[node name="List" type="ItemList" parent="Players"] margin_left = 25.0 margin_top = 37.0 margin_right = 229.0 @@ -51,7 +51,7 @@ margin_bottom = 296.0 size_flags_horizontal = 2 size_flags_vertical = 2 -[node name="connect" type="Panel" parent="."] +[node name="Connect" type="Panel" parent="."] anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 @@ -63,7 +63,7 @@ margin_bottom = 83.5 size_flags_horizontal = 2 size_flags_vertical = 2 -[node name="name_label" type="Label" parent="connect"] +[node name="NameLabel" type="Label" parent="Connect"] margin_left = 14.0 margin_top = 11.0 margin_right = 56.0 @@ -72,7 +72,7 @@ size_flags_horizontal = 2 size_flags_vertical = 0 text = "Name:" -[node name="name" type="LineEdit" parent="connect"] +[node name="Name" type="LineEdit" parent="Connect"] margin_left = 17.0 margin_top = 30.0 margin_right = 173.0 @@ -81,7 +81,7 @@ size_flags_horizontal = 2 size_flags_vertical = 2 text = "The Warrior" -[node name="ip_label" type="Label" parent="connect"] +[node name="IPLabel" type="Label" parent="Connect"] margin_left = 15.0 margin_top = 66.0 margin_right = 57.0 @@ -90,7 +90,7 @@ size_flags_horizontal = 2 size_flags_vertical = 0 text = "IP:" -[node name="ip" type="LineEdit" parent="connect"] +[node name="IPAddress" type="LineEdit" parent="Connect"] margin_left = 17.0 margin_top = 85.0 margin_right = 173.0 @@ -99,7 +99,7 @@ size_flags_horizontal = 2 size_flags_vertical = 2 text = "127.0.0.1" -[node name="host" type="Button" parent="connect"] +[node name="Host" type="Button" parent="Connect"] margin_left = 181.0 margin_top = 31.0 margin_right = 246.0 @@ -108,7 +108,7 @@ size_flags_horizontal = 2 size_flags_vertical = 2 text = "Host" -[node name="join" type="Button" parent="connect"] +[node name="Join" type="Button" parent="Connect"] margin_left = 181.0 margin_top = 87.0 margin_right = 246.0 @@ -117,7 +117,7 @@ size_flags_horizontal = 2 size_flags_vertical = 2 text = "Join" -[node name="error_label" type="Label" parent="connect"] +[node name="ErrorLabel" type="Label" parent="Connect"] margin_left = 15.0 margin_top = 125.0 margin_right = 257.0 @@ -127,11 +127,11 @@ size_flags_vertical = 0 custom_colors/font_color = Color( 0.820312, 0.291595, 0.291595, 1 ) align = 1 -[node name="error" type="AcceptDialog" parent="."] +[node name="ErrorDialog" type="AcceptDialog" parent="."] margin_right = 55.0 margin_bottom = 58.0 size_flags_horizontal = 2 size_flags_vertical = 2 -[connection signal="pressed" from="players/start" to="." method="_on_start_pressed"] -[connection signal="pressed" from="connect/host" to="." method="_on_host_pressed"] -[connection signal="pressed" from="connect/join" to="." method="_on_join_pressed"] +[connection signal="pressed" from="Players/Start" to="." method="_on_start_pressed"] +[connection signal="pressed" from="Connect/Host" to="." method="_on_host_pressed"] +[connection signal="pressed" from="Connect/Join" to="." method="_on_join_pressed"] diff --git a/networking/multiplayer_bomber/project.godot b/networking/multiplayer_bomber/project.godot index 65317ce5..08c4aa48 100644 --- a/networking/multiplayer_bomber/project.godot +++ b/networking/multiplayer_bomber/project.godot @@ -46,25 +46,40 @@ gen_mipmaps=false move_down={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) ] } move_left={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null) ] } move_right={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null) ] } move_up={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null) ] } set_bomb={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":1,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null) ] } diff --git a/networking/multiplayer_bomber/rock.gd b/networking/multiplayer_bomber/rock.gd index 83a9f653..6f7920bc 100644 --- a/networking/multiplayer_bomber/rock.gd +++ b/networking/multiplayer_bomber/rock.gd @@ -2,10 +2,10 @@ extends KinematicBody2D # Sent to everyone else puppet func do_explosion(): - get_node("anim").play("explode") + $"AnimationPlayer".play("explode") # Received by owner of the rock master func exploded(by_who): rpc("do_explosion") # Re-sent to puppet rocks - get_node("../../score").rpc("increase_score", by_who) + $"../../Score".rpc("increase_score", by_who) do_explosion() diff --git a/networking/multiplayer_bomber/rock.tscn b/networking/multiplayer_bomber/rock.tscn index 30c6d4cd..17722201 100644 --- a/networking/multiplayer_bomber/rock.tscn +++ b/networking/multiplayer_bomber/rock.tscn @@ -23,7 +23,7 @@ tracks/0/keys = { } ] } tracks/1/type = "value" -tracks/1/path = NodePath("sprite:visible") +tracks/1/path = NodePath("Sprite:visible") tracks/1/interp = 1 tracks/1/loop_wrap = true tracks/1/imported = false @@ -35,17 +35,16 @@ tracks/1/keys = { "values": [ false ] } -[node name="rock" type="KinematicBody2D"] +[node name="Rock" type="KinematicBody2D"] script = ExtResource( 1 ) -[node name="sprite" type="Sprite" parent="."] +[node name="Sprite" type="Sprite" parent="."] texture = ExtResource( 2 ) region_enabled = true region_rect = Rect2( 96, 0, 48, 48 ) -[node name="shape" type="CollisionShape2D" parent="."] +[node name="Shape" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) -[node name="anim" type="AnimationPlayer" parent="."] +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] anims/explode = SubResource( 2 ) - diff --git a/networking/multiplayer_bomber/score.gd b/networking/multiplayer_bomber/score.gd index 28347106..ef5d8058 100644 --- a/networking/multiplayer_bomber/score.gd +++ b/networking/multiplayer_bomber/score.gd @@ -3,7 +3,7 @@ extends HBoxContainer var player_labels = {} func _process(_delta): - var rocks_left = get_node("../rocks").get_child_count() + var rocks_left = $"../Rocks".get_child_count() if rocks_left == 0: var winner_name = "" var winner_score = 0 @@ -12,8 +12,9 @@ func _process(_delta): winner_score = player_labels[p].score winner_name = player_labels[p].name - get_node("../winner").set_text("THE WINNER IS:\n" + winner_name) - get_node("../winner").show() + $"../Winner".set_text("THE WINNER IS:\n" + winner_name) + $"../Winner".show() + sync func increase_score(for_who): assert(for_who in player_labels) @@ -21,6 +22,7 @@ sync func increase_score(for_who): pl.score += 1 pl.label.set_text(pl.name + "\n" + str(pl.score)) + func add_player(id, new_player_name): var l = Label.new() l.set_align(Label.ALIGN_CENTER) @@ -34,9 +36,11 @@ func add_player(id, new_player_name): player_labels[id] = { name = new_player_name, label = l, score = 0 } + func _ready(): - get_node("../winner").hide() + $"../Winner".hide() set_process(true) + func _on_exit_game_pressed(): gamestate.end_game() diff --git a/networking/multiplayer_bomber/tile_scene.tscn b/networking/multiplayer_bomber/tile_scene.tscn index 9c7d10bc..4251d6f9 100644 --- a/networking/multiplayer_bomber/tile_scene.tscn +++ b/networking/multiplayer_bomber/tile_scene.tscn @@ -5,19 +5,19 @@ [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 24, 24 ) -[node name="Node2D" type="Node2D"] +[node name="TileScene" type="Node2D"] -[node name="wall" type="Sprite" parent="."] +[node name="Wall" type="Sprite" parent="."] position = Vector2( 24, 24 ) texture = ExtResource( 1 ) region_rect = Rect2( 0, 0, 48, 48 ) -[node name="col" type="StaticBody2D" parent="wall"] +[node name="StaticBody2D" type="StaticBody2D" parent="Wall"] -[node name="CollisionShape2D" type="CollisionShape2D" parent="wall/col"] +[node name="CollisionShape2D" type="CollisionShape2D" parent="Wall/StaticBody2D"] shape = SubResource( 1 ) -[node name="floor" type="Sprite" parent="."] +[node name="Floor" type="Sprite" parent="."] position = Vector2( 72, 24 ) texture = ExtResource( 1 ) region_rect = Rect2( 48, 0, 48, 48 ) diff --git a/networking/multiplayer_bomber/world.tscn b/networking/multiplayer_bomber/world.tscn index 31d805d6..58d74deb 100644 --- a/networking/multiplayer_bomber/world.tscn +++ b/networking/multiplayer_bomber/world.tscn @@ -9,9 +9,9 @@ size = 44 font_data = ExtResource( 4 ) -[node name="world" type="Node2D"] +[node name="World" type="Node2D"] -[node name="map" type="TileMap" parent="."] +[node name="TileMap" type="TileMap" parent="."] tile_set = ExtResource( 1 ) cell_size = Vector2( 48, 48 ) format = 1 @@ -20,266 +20,269 @@ __meta__ = { "_edit_lock_": true } -[node name="spawn_points" type="Node2D" parent="."] +[node name="SpawnPoints" type="Node2D" parent="."] -[node name="0" type="Position2D" parent="spawn_points"] +[node name="0" type="Position2D" parent="SpawnPoints"] position = Vector2( 72, 72 ) -[node name="1" type="Position2D" parent="spawn_points"] +[node name="1" type="Position2D" parent="SpawnPoints"] position = Vector2( 264, 216 ) -[node name="2" type="Position2D" parent="spawn_points"] +[node name="2" type="Position2D" parent="SpawnPoints"] position = Vector2( 72, 456 ) -[node name="3" type="Position2D" parent="spawn_points"] +[node name="3" type="Position2D" parent="SpawnPoints"] position = Vector2( 360, 552 ) -[node name="4" type="Position2D" parent="spawn_points"] +[node name="4" type="Position2D" parent="SpawnPoints"] position = Vector2( 840, 360 ) -[node name="5" type="Position2D" parent="spawn_points"] +[node name="5" type="Position2D" parent="SpawnPoints"] position = Vector2( 456, 264 ) -[node name="6" type="Position2D" parent="spawn_points"] +[node name="6" type="Position2D" parent="SpawnPoints"] position = Vector2( 696, 264 ) -[node name="7" type="Position2D" parent="spawn_points"] +[node name="7" type="Position2D" parent="SpawnPoints"] position = Vector2( 744, 456 ) -[node name="8" type="Position2D" parent="spawn_points"] +[node name="8" type="Position2D" parent="SpawnPoints"] position = Vector2( 312, 456 ) -[node name="9" type="Position2D" parent="spawn_points"] +[node name="9" type="Position2D" parent="SpawnPoints"] position = Vector2( 696, 72 ) -[node name="10" type="Position2D" parent="spawn_points"] +[node name="10" type="Position2D" parent="SpawnPoints"] position = Vector2( 504, 72 ) -[node name="11" type="Position2D" parent="spawn_points"] +[node name="11" type="Position2D" parent="SpawnPoints"] position = Vector2( 936, 72 ) -[node name="rocks" type="Node2D" parent="."] +[node name="Rocks" type="Node2D" parent="."] -[node name="rock" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock0" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 120, 72 ) -[node name="rock1" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock1" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 264, 168 ) -[node name="rock2" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock2" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 264, 120 ) -[node name="rock3" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock3" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 216, 72 ) -[node name="rock4" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock4" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 264, 72 ) -[node name="rock5" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock5" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 312, 72 ) -[node name="rock6" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock6" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 552, 168 ) -[node name="rock7" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock7" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 600, 168 ) -[node name="rock8" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock8" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 552, 216 ) -[node name="rock9" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock9" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 264, 312 ) -[node name="rock10" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock10" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 120, 360 ) -[node name="rock11" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock11" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 168, 360 ) -[node name="rock12" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock12" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 216, 360 ) -[node name="rock13" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock13" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 120, 264 ) -[node name="rock14" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock14" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 168, 216 ) -[node name="rock15" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock15" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 72, 360 ) -[node name="rock16" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock16" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 72, 312 ) -[node name="rock17" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock17" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 72, 264 ) -[node name="rock18" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock18" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 360, 360 ) -[node name="rock19" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock19" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 408, 360 ) -[node name="rock20" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock20" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 504, 360 ) -[node name="rock21" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock21" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 600, 360 ) -[node name="rock22" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock22" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 648, 360 ) -[node name="rock23" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock23" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 504, 456 ) -[node name="rock24" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock24" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 552, 456 ) -[node name="rock25" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock25" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 552, 408 ) -[node name="rock26" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock26" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 360, 456 ) -[node name="rock27" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock27" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 360, 504 ) -[node name="rock28" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock28" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 264, 504 ) -[node name="rock29" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock29" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 264, 552 ) -[node name="rock30" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock30" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 168, 456 ) -[node name="rock31" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock31" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 168, 504 ) -[node name="rock32" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock32" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 72, 552 ) -[node name="rock33" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock33" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 120, 552 ) -[node name="rock34" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock34" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 504, 552 ) -[node name="rock35" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock35" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 600, 552 ) -[node name="rock36" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock36" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 648, 552 ) -[node name="rock37" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock37" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 648, 504 ) -[node name="rock38" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock38" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 456, 216 ) -[node name="rock39" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock39" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 360, 216 ) -[node name="rock40" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock40" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 360, 168 ) -[node name="rock41" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock41" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 456, 120 ) -[node name="rock42" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock42" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 456, 408 ) -[node name="rock43" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock43" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 456, 456 ) -[node name="rock44" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock44" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 456, 504 ) -[node name="rock45" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock45" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 600, 264 ) -[node name="rock46" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock46" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 600, 72 ) -[node name="rock47" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock47" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 408, 72 ) -[node name="rock48" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock48" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 792, 168 ) -[node name="rock49" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock49" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 744, 168 ) -[node name="rock50" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock50" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 744, 264 ) -[node name="rock51" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock51" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 792, 264 ) -[node name="rock52" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock52" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 744, 360 ) -[node name="rock53" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock53" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 744, 408 ) -[node name="rock54" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock54" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 792, 552 ) -[node name="rock55" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock55" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 840, 552 ) -[node name="rock56" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock56" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 840, 504 ) -[node name="rock57" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock57" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 840, 312 ) -[node name="rock58" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock58" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 840, 264 ) -[node name="rock59" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock59" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 840, 216 ) -[node name="rock60" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock60" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 840, 120 ) -[node name="rock61" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock61" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 792, 72 ) -[node name="rock62" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock62" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 840, 72 ) -[node name="rock63" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock63" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 936, 216 ) -[node name="rock64" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock64" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 936, 264 ) -[node name="rock65" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock65" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 936, 408 ) -[node name="rock66" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock66" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 888, 456 ) -[node name="rock67" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock67" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 936, 456 ) -[node name="rock68" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock68" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 792, 456 ) -[node name="rock69" parent="rocks" instance=ExtResource( 2 )] +[node name="Rock69" parent="Rocks" instance=ExtResource( 2 )] position = Vector2( 840, 456 ) -[node name="players" type="Node2D" parent="."] +[node name="Players" type="Node2D" parent="."] -[node name="score" type="HBoxContainer" parent="."] +[node name="Score" type="HBoxContainer" parent="."] margin_right = 1024.0 margin_bottom = 40.0 size_flags_horizontal = 2 size_flags_vertical = 2 script = ExtResource( 3 ) +__meta__ = { +"_edit_use_anchors_": false +} -[node name="winner" type="Label" parent="."] +[node name="Winner" type="Label" parent="."] margin_right = 1031.0 margin_bottom = 617.0 size_flags_horizontal = 2 @@ -294,7 +297,7 @@ YOU" align = 1 valign = 1 -[node name="exit_game" type="Button" parent="winner"] +[node name="ExitGame" type="Button" parent="Winner"] margin_left = 384.0 margin_top = 408.0 margin_right = 649.0 @@ -303,8 +306,11 @@ size_flags_horizontal = 2 size_flags_vertical = 2 custom_fonts/font = SubResource( 1 ) text = "EXIT GAME" +__meta__ = { +"_edit_use_anchors_": false +} [node name="Camera2D" type="Camera2D" parent="."] offset = Vector2( 512, 300 ) current = true -[connection signal="pressed" from="winner/exit_game" to="score" method="_on_exit_game_pressed"] +[connection signal="pressed" from="Winner/ExitGame" to="Score" method="_on_exit_game_pressed"]