Merge branch 'master' of github.com:unfa/jam-01 into master

remotes/1705382094874458415/tmp_refs/heads/godot4-port
unfa 2020-09-21 22:26:49 +02:00
commit 762f776a20
3 changed files with 36 additions and 12 deletions

23
Game.gd
View File

@ -1,9 +1,10 @@
extends Spatial
extends Node
export var SERVER_PORT = 9999 setget , get_port
export(String, "172.28.162.191", "172.28.166.24", "127.0.0.1") var SERVER_IP = "172.28.162.191" setget , get_ip
export var SERVER_PORT = 80 setget , get_port
export(String, "172.28.162.191", "172.28.166.24", "127.0.0.1") var SERVER_IP = "172.28.162.191" setget , get_ip
export var MAX_PLAYERS = 10
export (String, "MENU", "PLAYING") var GAME_MODE = "MENU"
export var auto_host = false
var mouse_sensitivity_multiplier = 1.0
@ -20,6 +21,10 @@ func _ready():
$MenuContainer/MainMenu/Destination/Port.set_text(str(SERVER_PORT))
load_settings()
if auto_host:
initialize_server(false)
print("qwueyhgfiuyqwgaadsf")
func load_settings():
var load_settings = File.new()
@ -71,9 +76,10 @@ func open_menus():
$MenuContainer.show()
func close_menus():
GAME_MODE = "PLAYING"
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
$MenuContainer.hide()
if has_node("MenuContainer"):
GAME_MODE = "PLAYING"
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
$MenuContainer.hide()
func return_to_menu(type):
for menu in $MenuContainer.get_children():
@ -136,14 +142,15 @@ func get_ip():
func get_port():
return SERVER_PORT
func initialize_server():
func initialize_server(join=true):
var peer = NetworkedMultiplayerENet.new()
peer.create_server(SERVER_PORT, MAX_PLAYERS)
get_tree().connect("network_peer_connected", self, "on_peer_connected")
get_tree().connect("network_peer_disconnected", self, "on_peer_disconnected")
get_tree().network_peer = peer
close_menus()
add_player(1, false)
if join:
add_player(1, false)
func initialize_client():
var peer = NetworkedMultiplayerENet.new()

View File

@ -26,7 +26,7 @@ glow_blend_mode = 0
glow_hdr_threshold = 1.5
glow_bicubic_upscale = true
[node name="Game" type="Spatial"]
[node name="Game" type="Node"]
script = ExtResource( 2 )
SERVER_IP = "127.0.0.1"
@ -36,7 +36,6 @@ environment = SubResource( 2 )
[node name="Level" parent="." instance=ExtResource( 3 )]
[node name="Players" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 12.6315, 8.00684, -4.99273 )
[node name="MenuContainer" type="CenterContainer" parent="."]
anchor_right = 1.0
@ -68,6 +67,8 @@ margin_bottom = 24.0
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.38
placeholder_text = "IP address"
caret_blink = true
caret_blink_speed = 0.5
[node name="Port" type="LineEdit" parent="MenuContainer/MainMenu/Destination"]
margin_left = 282.0
@ -75,6 +76,8 @@ margin_right = 400.0
margin_bottom = 24.0
size_flags_horizontal = 3
placeholder_text = "port"
caret_blink = true
caret_blink_speed = 0.5
[node name="NetworkType" type="HBoxContainer" parent="MenuContainer/MainMenu"]
margin_top = 52.0
@ -82,13 +85,20 @@ margin_right = 400.0
margin_bottom = 72.0
[node name="Host" type="Button" parent="MenuContainer/MainMenu/NetworkType"]
margin_right = 198.0
margin_right = 130.0
margin_bottom = 20.0
size_flags_horizontal = 3
text = "Host"
[node name="HostAsSpectator" type="Button" parent="MenuContainer/MainMenu/NetworkType"]
margin_left = 134.0
margin_right = 265.0
margin_bottom = 20.0
size_flags_horizontal = 3
text = "Host As Spectator"
[node name="Join" type="Button" parent="MenuContainer/MainMenu/NetworkType"]
margin_left = 202.0
margin_left = 269.0
margin_right = 400.0
margin_bottom = 20.0
size_flags_horizontal = 3
@ -221,6 +231,7 @@ text = "Fullscreen"
[connection signal="pressed" from="MenuContainer/MainMenu/QuickJoin" to="." method="open_menu" binds= [ "QuickJoinMenu" ]]
[connection signal="text_changed" from="MenuContainer/MainMenu/Destination/IPAdress" to="." method="set_ip"]
[connection signal="pressed" from="MenuContainer/MainMenu/NetworkType/Host" to="." method="initialize_server"]
[connection signal="pressed" from="MenuContainer/MainMenu/NetworkType/HostAsSpectator" to="." method="initialize_server" binds= [ false ]]
[connection signal="pressed" from="MenuContainer/MainMenu/NetworkType/Join" to="." method="initialize_client"]
[connection signal="pressed" from="MenuContainer/MainMenu/Options" to="." method="open_menu" binds= [ "OptionsMenu" ]]
[connection signal="pressed" from="MenuContainer/MainMenu/Quit" to="." method="quit"]

6
Server.tscn Normal file
View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Game.tscn" type="PackedScene" id=2]
[node name="Game" instance=ExtResource( 2 )]
auto_host = true