From c62cf258a8ba1c8f40c69208a28a82c5afc71343 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 10 Feb 2021 23:53:06 +0100 Subject: Adds GameOver screen --- Global.gd | 7 ++----- Network/Lobby.gd | 6 +++++- Network/Network.gd | 5 +++-- Network/Remote.gd | 6 ------ Network/Sync.gd | 6 ------ UI/GameOver.gd | 9 +++++++++ UI/GameOver.tscn | 45 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 64 insertions(+), 20 deletions(-) delete mode 100644 Network/Remote.gd delete mode 100644 Network/Sync.gd create mode 100644 UI/GameOver.gd create mode 100644 UI/GameOver.tscn diff --git a/Global.gd b/Global.gd index 3c8a3a3..7f7582c 100644 --- a/Global.gd +++ b/Global.gd @@ -110,11 +110,8 @@ func end_game(): emit_signal("game_ended") -func _on_Network_game_ended(winning_player): - # TODO: change scene for all to win scene and set winning player id, - # so it can be displayed with self.players - print(winning_player) - get_tree().change_scene("res://Network/Lobby.tscn") +func _on_Network_game_ended(): + get_tree().change_scene("res://UI/GameOver.tscn") self.Level_Map = [] self.init() diff --git a/Network/Lobby.gd b/Network/Lobby.gd index b30bc1f..d192640 100644 --- a/Network/Lobby.gd +++ b/Network/Lobby.gd @@ -60,7 +60,11 @@ func _on_Host_pressed(): $Players.show() $Connect/Error.text = "" - $Players/IP.text = IP.get_local_addresses()[6] + for ip in IP.get_local_addresses(): + if ip.begins_with("192.168"): + $Players/IP.text = ip + break + var player_name = $Connect/Name.text Network.host_game(player_name) self.refresh_lobby() diff --git a/Network/Network.gd b/Network/Network.gd index fbef800..d58de75 100644 --- a/Network/Network.gd +++ b/Network/Network.gd @@ -22,6 +22,7 @@ var player = { name = "", character = "Tux", } +var winning_player = player # Dictionary { id = { idx: 1, name: "" } } var players = {} @@ -111,8 +112,8 @@ func _on_Global_game_won(winning_player): sync func _end_game(winning_player): - print("winning_player") - emit_signal("game_ended", winning_player) + self.winning_player = winning_player + emit_signal("game_ended") func _player_connected(_id): diff --git a/Network/Remote.gd b/Network/Remote.gd deleted file mode 100644 index 1b1de57..0000000 --- a/Network/Remote.gd +++ /dev/null @@ -1,6 +0,0 @@ -extends Node - -# rpc remote functions - -func _ready(): - pass diff --git a/Network/Sync.gd b/Network/Sync.gd deleted file mode 100644 index cb81ec8..0000000 --- a/Network/Sync.gd +++ /dev/null @@ -1,6 +0,0 @@ -extends Node - -# rpc sync functions - -func _ready(): - pass diff --git a/UI/GameOver.gd b/UI/GameOver.gd new file mode 100644 index 0000000..6340e89 --- /dev/null +++ b/UI/GameOver.gd @@ -0,0 +1,9 @@ +extends Panel + + +func _ready(): + $Winner.text = Network.winning_player.name + " won!" + + +func _on_BackToLobby_pressed(): + get_tree().change_scene("res://Network/Lobby.tscn") diff --git a/UI/GameOver.tscn b/UI/GameOver.tscn new file mode 100644 index 0000000..67d985d --- /dev/null +++ b/UI/GameOver.tscn @@ -0,0 +1,45 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://Assets/Fonts/impact-label/Impact_Label_Reversed.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://Assets/Fonts/geometry-soft-pro/Geometry_Soft_Pro-Bold_N.otf" type="DynamicFontData" id=2] +[ext_resource path="res://UI/GameOver.gd" type="Script" id=3] + +[sub_resource type="DynamicFont" id=1] +size = 144 +font_data = ExtResource( 1 ) + +[sub_resource type="DynamicFont" id=2] +size = 36 +font_data = ExtResource( 2 ) + +[node name="GameOver" type="Panel"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 3 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Title" type="Label" parent="."] +margin_left = 112.0 +margin_top = 56.0 +margin_right = 891.0 +margin_bottom = 200.0 +custom_fonts/font = SubResource( 1 ) +text = "GAME OVER" + +[node name="Winner" type="Label" parent="."] +margin_left = 400.0 +margin_top = 264.0 +margin_right = 585.0 +margin_bottom = 301.0 +custom_fonts/font = SubResource( 2 ) +text = "NAME won!" + +[node name="BackToLobby" type="Button" parent="."] +margin_left = 448.0 +margin_top = 464.0 +margin_right = 576.0 +margin_bottom = 496.0 +text = "Back to Lobby" +[connection signal="pressed" from="BackToLobby" to="." method="_on_BackToLobby_pressed"] -- cgit v1.2.3