diff --git a/Game.gd b/Game.gd index 309c54d..6ea3584 100644 --- a/Game.gd +++ b/Game.gd @@ -1,12 +1,12 @@ extends Spatial -export var is_server = true - 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 MAX_PLAYERS = 10 export (String, "MENU", "PLAYING") var GAME_MODE = "MENU" +var mouse_sensitivity_multiplier = 1.0 + var player_scene = preload("res://Player.tscn") # Called when the node enters the scene tree for the first time. @@ -17,35 +17,43 @@ func _ready(): func _input(event): if event.is_action_pressed("ToggleMenu"): if GAME_MODE == "PLAYING" and not $MenuContainer.is_visible(): - open_menu() + open_menus() elif $MenuContainer/MainMenu.is_visible(): - close_menu() + close_menus() else: # Find the back button var children = $MenuContainer.get_children() for child in children: - var buttons = child.get_children() - for button in buttons: - if button.name == "Back": - button.emit_signal("pressed") + if child.is_visible(): + var buttons = child.get_children() + for button in buttons: + if button.name == "Back": + print(child.name) + button.emit_signal("pressed") -func open_menu(): +func open_menus(): GAME_MODE = "MENU" Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) $MenuContainer.show() -func close_menu(): +func close_menus(): GAME_MODE = "PLAYING" Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) $MenuContainer.hide() -func open_quick_join_menu(): - $MenuContainer/MainMenu.hide() - $MenuContainer/QuickJoinMenu.show() +func return_to_menu(type): + for menu in $MenuContainer.get_children(): + if menu.name == type: + menu.show() + else: + menu.hide() -func close_quick_join_menu(): - $MenuContainer/MainMenu.show() - $MenuContainer/QuickJoinMenu.hide() +func open_menu(type): + for menu in $MenuContainer.get_children(): + if menu.name == type: + menu.show() + else: + menu.hide() func join_home(): SERVER_IP = "127.0.0.1" @@ -59,6 +67,13 @@ func join_jan(): SERVER_IP = "172.25.166.24" initialize_client() +func set_mouse_sensitivity(sensitivity_multiplier): + mouse_sensitivity_multiplier = sensitivity_multiplier + print(sensitivity_multiplier) + +func set_fullscreen(is_fullscreen): + OS.window_fullscreen = is_fullscreen + func debug_connection_status(): if (get_tree().network_peer.get_connection_status() == NetworkedMultiplayerPeer.CONNECTION_CONNECTING): print("We are trying to connect") @@ -75,7 +90,7 @@ func initialize_server(): 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_menu() + close_menus() add_player(1, false) func initialize_client(): @@ -84,7 +99,7 @@ func initialize_client(): get_tree().connect("connected_to_server", self, "on_connection_established") get_tree().connect("connection_failed", self, "on_connection_failed") get_tree().network_peer = peer - close_menu() + close_menus() func quit(): get_tree().quit() diff --git a/Game.tscn b/Game.tscn index d8db51c..cc7e29b 100644 --- a/Game.tscn +++ b/Game.tscn @@ -19,67 +19,73 @@ __meta__ = { } [node name="MainMenu" type="VBoxContainer" parent="MenuContainer"] -margin_left = 362.0 -margin_top = 252.0 -margin_right = 662.0 -margin_bottom = 348.0 -rect_min_size = Vector2( 300, 0 ) +margin_left = 312.0 +margin_top = 240.0 +margin_right = 712.0 +margin_bottom = 360.0 +rect_min_size = Vector2( 400, 0 ) [node name="QuickJoin" type="Button" parent="MenuContainer/MainMenu"] -margin_right = 300.0 +margin_right = 400.0 margin_bottom = 20.0 text = "Quick Join" [node name="Destination" type="HBoxContainer" parent="MenuContainer/MainMenu"] margin_top = 24.0 -margin_right = 300.0 +margin_right = 400.0 margin_bottom = 48.0 [node name="IPAdress" type="LineEdit" parent="MenuContainer/MainMenu/Destination"] -margin_right = 208.0 +margin_right = 278.0 margin_bottom = 24.0 size_flags_horizontal = 3 size_flags_stretch_ratio = 2.38 placeholder_text = "IP address" [node name="Port" type="LineEdit" parent="MenuContainer/MainMenu/Destination"] -margin_left = 212.0 -margin_right = 300.0 +margin_left = 282.0 +margin_right = 400.0 margin_bottom = 24.0 size_flags_horizontal = 3 placeholder_text = "port" [node name="NetworkType" type="HBoxContainer" parent="MenuContainer/MainMenu"] margin_top = 52.0 -margin_right = 300.0 +margin_right = 400.0 margin_bottom = 72.0 [node name="Host" type="Button" parent="MenuContainer/MainMenu/NetworkType"] -margin_right = 148.0 +margin_right = 198.0 margin_bottom = 20.0 size_flags_horizontal = 3 text = "Host" [node name="Join" type="Button" parent="MenuContainer/MainMenu/NetworkType"] -margin_left = 152.0 -margin_right = 300.0 +margin_left = 202.0 +margin_right = 400.0 margin_bottom = 20.0 size_flags_horizontal = 3 text = "Join" -[node name="Quit" type="Button" parent="MenuContainer/MainMenu"] +[node name="Options" type="Button" parent="MenuContainer/MainMenu"] margin_top = 76.0 -margin_right = 300.0 +margin_right = 400.0 margin_bottom = 96.0 +text = "Options" + +[node name="Quit" type="Button" parent="MenuContainer/MainMenu"] +margin_top = 100.0 +margin_right = 400.0 +margin_bottom = 120.0 text = "Quit" [node name="QuickJoinMenu" type="VBoxContainer" parent="MenuContainer"] visible = false -margin_left = 362.0 +margin_left = 312.0 margin_top = 254.0 -margin_right = 662.0 +margin_right = 712.0 margin_bottom = 346.0 -rect_min_size = Vector2( 300, 0 ) +rect_min_size = Vector2( 400, 0 ) [node name="Back" type="Button" parent="MenuContainer/QuickJoinMenu"] margin_right = 300.0 @@ -103,11 +109,101 @@ margin_top = 72.0 margin_right = 300.0 margin_bottom = 92.0 text = "Jan" -[connection signal="pressed" from="MenuContainer/MainMenu/QuickJoin" to="." method="open_quick_join_menu"] + +[node name="OptionsMenu" type="VBoxContainer" parent="MenuContainer"] +visible = false +margin_left = 312.0 +margin_top = 266.0 +margin_right = 712.0 +margin_bottom = 334.0 +rect_min_size = Vector2( 400, 0 ) + +[node name="Back" type="Button" parent="MenuContainer/OptionsMenu"] +margin_left = 129.0 +margin_top = -10.0 +margin_right = 171.0 +margin_bottom = 10.0 +text = "Back" + +[node name="Controls" type="Button" parent="MenuContainer/OptionsMenu"] +margin_left = 129.0 +margin_top = -10.0 +margin_right = 171.0 +margin_bottom = 10.0 +text = "Controls" + +[node name="Graphics" type="Button" parent="MenuContainer/OptionsMenu"] +margin_left = 129.0 +margin_top = -10.0 +margin_right = 171.0 +margin_bottom = 10.0 +text = "Graphics" + +[node name="ControlsMenu" type="VBoxContainer" parent="MenuContainer"] +visible = false +margin_left = 312.0 +margin_top = 280.0 +margin_right = 712.0 +margin_bottom = 320.0 +rect_min_size = Vector2( 400, 0 ) + +[node name="Back" type="Button" parent="MenuContainer/ControlsMenu"] +margin_right = 300.0 +margin_bottom = 20.0 +text = "Back" + +[node name="HBoxContainer" type="HBoxContainer" parent="MenuContainer/ControlsMenu"] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="SensitivityLabel" type="Label" parent="MenuContainer/ControlsMenu/HBoxContainer"] +margin_right = 40.0 +margin_bottom = 14.0 +text = "Sensitivity" + +[node name="SensitivitySlider" type="HSlider" parent="MenuContainer/ControlsMenu/HBoxContainer"] +margin_right = 16.0 +margin_bottom = 16.0 +size_flags_horizontal = 3 +min_value = 0.2 +max_value = 5.0 +step = 0.0 +value = 1.0 +exp_edit = true +allow_greater = true +allow_lesser = true + +[node name="GraphicsMenu" type="VBoxContainer" parent="MenuContainer"] +visible = false +margin_left = 312.0 +margin_top = 268.0 +margin_right = 712.0 +margin_bottom = 332.0 +rect_min_size = Vector2( 400, 0 ) + +[node name="Back" type="Button" parent="MenuContainer/GraphicsMenu"] +margin_right = 300.0 +margin_bottom = 20.0 +text = "Back" + +[node name="Fullscreen" type="CheckButton" parent="MenuContainer/GraphicsMenu"] +margin_top = 24.0 +margin_right = 300.0 +margin_bottom = 64.0 +text = "Fullscreen" +[connection signal="pressed" from="MenuContainer/MainMenu/QuickJoin" to="." method="open_menu" binds= [ "QuickJoinMenu" ]] [connection signal="pressed" from="MenuContainer/MainMenu/NetworkType/Host" to="." method="initialize_server"] [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"] -[connection signal="pressed" from="MenuContainer/QuickJoinMenu/Back" to="." method="close_quick_join_menu"] +[connection signal="pressed" from="MenuContainer/QuickJoinMenu/Back" to="." method="return_to_menu" binds= [ "MainMenu" ]] [connection signal="pressed" from="MenuContainer/QuickJoinMenu/Home" to="." method="join_home"] [connection signal="pressed" from="MenuContainer/QuickJoinMenu/Unfa" to="." method="join_unfa"] [connection signal="pressed" from="MenuContainer/QuickJoinMenu/Jan" to="." method="join_jan"] +[connection signal="pressed" from="MenuContainer/OptionsMenu/Back" to="." method="return_to_menu" binds= [ "MainMenu" ]] +[connection signal="pressed" from="MenuContainer/OptionsMenu/Controls" to="." method="open_menu" binds= [ "ControlsMenu" ]] +[connection signal="pressed" from="MenuContainer/OptionsMenu/Graphics" to="." method="open_menu" binds= [ "GraphicsMenu" ]] +[connection signal="pressed" from="MenuContainer/ControlsMenu/Back" to="." method="return_to_menu" binds= [ "OptionsMenu" ]] +[connection signal="value_changed" from="MenuContainer/ControlsMenu/HBoxContainer/SensitivitySlider" to="." method="set_mouse_sensitivity"] +[connection signal="pressed" from="MenuContainer/GraphicsMenu/Back" to="." method="return_to_menu" binds= [ "OptionsMenu" ]] +[connection signal="toggled" from="MenuContainer/GraphicsMenu/Fullscreen" to="." method="set_fullscreen"] diff --git a/Player.gd b/Player.gd index bf2eeea..9c5db9b 100644 --- a/Player.gd +++ b/Player.gd @@ -9,7 +9,7 @@ const AIR_CONTROL = 0.1 const WALK_ACCEL = 0.25 const WALK_DECEL = 0.1 -const MOUSE_SENSITIVITY = 1.0 / 300 +const MOUSE_SENSITIVITY = 1.0 / 1000 export var max_health = 150 onready var health = max_health @@ -19,8 +19,6 @@ onready var debug = $Debug onready var game = get_parent().get_parent() -onready var crosshair_pos = $CrosshairContainer.rect_size / 2 - var velocity = Vector3.ZERO var walkDirection = Vector2.ZERO @@ -67,8 +65,9 @@ remote func jump(): velocity.y = JUMP_VELOCITY remote func mouselook(rel): - self.rotate_y(- rel.x * MOUSE_SENSITIVITY) - camera.rotation.x = clamp(camera.rotation.x-rel.y * MOUSE_SENSITIVITY, -PI/2, PI/2) + var sensitivity = MOUSE_SENSITIVITY * game.mouse_sensitivity_multiplier + self.rotate_y(- rel.x * sensitivity) + camera.rotation.x = clamp(camera.rotation.x-rel.y * sensitivity, -PI/2, PI/2) func motion(delta): self.move_and_slide(velocity * delta, Vector3.UP, true) @@ -100,6 +99,7 @@ func spawn(): func shoot(): var space_state = get_world().direct_space_state + var crosshair_pos = OS.get_real_window_size() / 2 var from = $Camera.project_ray_origin(crosshair_pos) var to = from + $Camera.project_ray_normal(crosshair_pos) * 1000