fully sync player movements over network

This commit is contained in:
2023-01-17 13:54:26 +01:00
parent 1ef5d54d6c
commit 9893bc45b4
19 changed files with 434 additions and 62 deletions

57
scenes/GUI/MAIN.tscn Normal file
View File

@@ -0,0 +1,57 @@
[gd_scene load_steps=2 format=3 uid="uid://3o430r2kys4k"]
[ext_resource type="Script" path="res://scenes/GUI/main.gd" id="1_i8nr4"]
[node name="MAIN" type="Control"]
layout_mode = 3
anchors_preset = 0
script = ExtResource("1_i8nr4")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -198.0
offset_top = -104.0
offset_right = 199.0
offset_bottom = 64.0
grow_horizontal = 2
grow_vertical = 2
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 2
[node name="Start" type="Button" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Start Game"
[node name="ModsMenu" type="MenuButton" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Select Mod"
flat = false
item_count = 2
popup/item_0/text = "test1"
popup/item_0/id = 0
popup/item_1/text = "test2"
popup/item_1/id = 1
[node name="VBoxContainer2" type="VBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 10
[node name="SettingsButton" type="Button" parent="VBoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Game Settings"
icon_alignment = 1
[node name="ExitButton" type="Button" parent="VBoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Exit"
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Start" to="." method="_on_start_pressed"]

25
scenes/GUI/MainMenu.gd Normal file
View File

@@ -0,0 +1,25 @@
extends Control
@onready var game = get_tree().get_current_scene() as Game
@onready var previous = $MAIN
@onready var current = $MAIN
func _on_main_start_game():
previous = current
current = $"START GAME"
$"START GAME".show()
func back():
current.hide()
previous.show()
var tmp = current
current = previous
previous = tmp
func _on_start_game_start_game():
game.load_map()
self.hide()
func _on_start_game_back():
previous = $MAIN
back()

View File

@@ -0,0 +1,62 @@
[gd_scene load_steps=2 format=3 uid="uid://d0kkhtesg83g"]
[ext_resource type="Script" path="res://scenes/GUI/start_game.gd" id="1_amknd"]
[node name="START GAME" type="Control"]
layout_mode = 3
anchors_preset = 0
script = ExtResource("1_amknd")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -198.0
offset_top = -104.0
offset_right = 199.0
offset_bottom = 64.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
metadata/_edit_use_anchors_ = true
[node name="HostContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 2
[node name="HostButton" type="Button" parent="VBoxContainer/HostContainer"]
layout_mode = 2
text = "Host"
[node name="JoinContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 2
[node name="IPAdress" type="TextEdit" parent="VBoxContainer/JoinContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_font_sizes/font_size = 13
placeholder_text = "localhost"
[node name="JoinButton" type="Button" parent="VBoxContainer/JoinContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 0
text = "Join
"
[node name="BackContainer" type="VBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
[node name="BackButton" type="Button" parent="VBoxContainer/BackContainer"]
layout_mode = 2
text = "Back"
[connection signal="pressed" from="VBoxContainer/HostContainer/HostButton" to="." method="_on_host_button_pressed"]
[connection signal="pressed" from="VBoxContainer/JoinContainer/JoinButton" to="." method="_on_join_button_pressed"]
[connection signal="pressed" from="VBoxContainer/BackContainer/BackButton" to="." method="_on_back_button_pressed"]

7
scenes/GUI/main.gd Normal file
View File

@@ -0,0 +1,7 @@
extends Control
signal start_game;
func _on_start_pressed():
start_game.emit()
hide()

27
scenes/GUI/start_game.gd Normal file
View File

@@ -0,0 +1,27 @@
extends Control
@onready var IPAdress_Field = $VBoxContainer/JoinContainer/IPAdress as TextEdit
signal start_game
signal back
func _on_join_button_pressed():
if not try_connection():
return
Network.start_network(false, IPAdress_Field.text)
start_game.emit()
func try_connection():
if IPAdress_Field.text.is_empty():
return false
return true
func _on_host_button_pressed():
Network.start_network(true)
start_game.emit()
func _on_back_button_pressed():
hide()
back.emit()