diff --git a/project.godot b/project.godot index d5628ae..1a221e8 100644 --- a/project.godot +++ b/project.godot @@ -173,6 +173,12 @@ debug_camera_4={ "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":52,"unicode":0,"echo":false,"script":null) ] } +controls_menu={ +"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":16777217,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null) + ] +} [layer_names] diff --git a/resources/ui/i18n.csv b/resources/ui/i18n.csv index b07aa9d..028b501 100644 --- a/resources/ui/i18n.csv +++ b/resources/ui/i18n.csv @@ -27,6 +27,7 @@ ALERT,Alert!,Fehler! CONTROLS,Controls,Steuerung RESET,Reset,Zurücksetzen PRESS_KEY,Press any key...,Taste drücken… +KEY_ALREADY_TAKEN,Key already in use:,Taste wird bereits verwendet: ERROR_SERVER_CREATION,Cannot create server!,Server konnte nicht erstellt werden! ERROR_GAME_CREATION,"Cannot create game! (Server full or blocked?)","Spiel konnte nicht erstellt werden! @@ -89,3 +90,4 @@ controls_prev_road_type,Previous type,Vorherige Kategorie controls_next_road_variant,Next variant,Nächste Variante controls_prev_road_variant,Previous variant,Vorherige Variante controls_reset,Reset,Zurücksetzen +controls_menu,Menu,Menu diff --git a/scenes/game/Game.tscn b/scenes/game/Game.tscn index 274f567..53c84ff 100644 --- a/scenes/game/Game.tscn +++ b/scenes/game/Game.tscn @@ -13,6 +13,7 @@ script = ExtResource( 2 ) [node name="sun" type="DirectionalLight" parent="."] transform = Transform( 0.324827, 0.775291, 0.541675, -0.754407, -0.133022, 0.642788, 0.570402, -0.617438, 0.541675, 0, 0, 0 ) +visible = false light_color = Color( 0.921569, 0.741176, 0.368627, 1 ) directional_shadow_mode = 1 directional_shadow_max_distance = 25.0 diff --git a/scenes/menus/IngameMenu.tscn b/scenes/menus/IngameMenu.tscn index 293f188..cc0998c 100644 --- a/scenes/menus/IngameMenu.tscn +++ b/scenes/menus/IngameMenu.tscn @@ -6,7 +6,6 @@ [ext_resource path="res://assets/icons/wrench.png" type="Texture" id=4] [ext_resource path="res://assets/icons/arrowLeft.png" type="Texture" id=5] - [node name="ingame_menu" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 @@ -59,7 +58,7 @@ margin_top = 136.0 margin_right = 310.0 margin_bottom = 201.0 focus_neighbour_top = NodePath("../settings") -focus_neighbour_bottom = NodePath(".") +focus_neighbour_bottom = NodePath("../resume") size_flags_horizontal = 3 size_flags_vertical = 3 text = "END_GAME" diff --git a/scenes/menus/SettingsControlsMenu.tscn b/scenes/menus/SettingsControlsMenu.tscn index 3a22a31..adb15b8 100644 --- a/scenes/menus/SettingsControlsMenu.tscn +++ b/scenes/menus/SettingsControlsMenu.tscn @@ -20,7 +20,6 @@ [ext_resource path="res://assets/icons/DPAD_right.png" type="Texture" id=18] [ext_resource path="res://assets/icons/fightJ.png" type="Texture" id=19] - [node name="settings_controls_menu" type="Control"] margin_left = 12.0 margin_top = 8.0 @@ -28,17 +27,7 @@ margin_right = 858.0 margin_bottom = 335.0 script = ExtResource( 1 ) -[node name="key_dialog" type="ConfirmationDialog" parent="."] -margin_left = 18.0 -margin_top = 16.0 -margin_right = 311.0 -margin_bottom = 100.0 -popup_exclusive = true -window_title = "" -dialog_text = "Press any key..." - [node name="ScrollContainer" type="ScrollContainer" parent="."] -editor/display_folded = true anchor_right = 1.0 anchor_bottom = 1.0 @@ -71,6 +60,7 @@ align = 1 valign = 1 [node name="icons" type="GridContainer" parent="."] +editor/display_folded = true visible = false margin_right = 40.0 margin_bottom = 40.0 @@ -188,3 +178,24 @@ margin_top = 960.0 margin_right = 62.0 margin_bottom = 1016.0 icon = ExtResource( 19 ) + +[node name="key_dialog" type="ConfirmationDialog" parent="."] +margin_left = 57.9108 +margin_top = 57.5398 +margin_right = 367.911 +margin_bottom = 216.54 +popup_exclusive = true +window_title = "" + +[node name="action_button" type="Button" parent="key_dialog"] +margin_left = 8.0 +margin_top = 8.0 +margin_right = 302.0 +margin_bottom = 123.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 12 +size_flags_vertical = 12 +flat = true +clip_text = true +align = 0 diff --git a/scenes/menus/SettingsMenu.tscn b/scenes/menus/SettingsMenu.tscn index dbf78c3..772ede9 100644 --- a/scenes/menus/SettingsMenu.tscn +++ b/scenes/menus/SettingsMenu.tscn @@ -20,6 +20,10 @@ script = ExtResource( 2 ) [node name="menu" parent="." instance=ExtResource( 3 )] +[node name="back" parent="menu" index="0"] +focus_neighbour_top = NodePath("../tabs/game") +focus_neighbour_right = NodePath("../HBoxContainer/apply") + [node name="tabs" type="TabContainer" parent="menu"] anchor_left = 0.5 anchor_top = 0.5 @@ -31,6 +35,7 @@ margin_right = 459.5 margin_bottom = 177.5 grow_horizontal = 2 grow_vertical = 2 +focus_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 tab_align = 0 @@ -43,6 +48,9 @@ margin_left = 4.0 margin_top = 45.0 margin_right = -4.0 margin_bottom = -4.0 +focus_neighbour_right = NodePath("../controls") +focus_neighbour_bottom = NodePath("GridContainer/settings_player/VBoxContainer/name") +focus_mode = 2 [node name="GridContainer" type="GridContainer" parent="menu/tabs/game"] margin_left = 9.0 @@ -64,6 +72,8 @@ margin_bottom = 27.0 margin_top = 31.0 margin_right = 407.0 margin_bottom = 68.0 +focus_neighbour_top = NodePath("../../../..") +focus_neighbour_bottom = NodePath("../color") [node name="color_label" parent="menu/tabs/game/GridContainer/settings_player/VBoxContainer" index="2"] margin_top = 72.0 @@ -74,11 +84,15 @@ margin_bottom = 99.0 margin_top = 103.0 margin_right = 407.0 margin_bottom = 136.0 +focus_neighbour_top = NodePath("../name") +focus_neighbour_bottom = NodePath("../../../bots") [node name="bots" type="CheckButton" parent="menu/tabs/game/GridContainer"] margin_top = 150.0 margin_right = 143.0 margin_bottom = 190.0 +focus_neighbour_top = NodePath("../settings_player/VBoxContainer/color") +focus_neighbour_bottom = NodePath("../../../../HBoxContainer/apply") size_flags_horizontal = 0 size_flags_vertical = 0 text = "Bots" @@ -92,6 +106,9 @@ margin_left = 4.0 margin_top = 45.0 margin_right = -4.0 margin_bottom = -4.0 +focus_neighbour_left = NodePath("../game") +focus_neighbour_right = NodePath("../graphics") +focus_mode = 2 [node name="settings_controls" parent="menu/tabs/controls" instance=ExtResource( 5 )] @@ -104,8 +121,10 @@ margin_bottom = 27.0 [node name="joypad_label" parent="menu/tabs/controls/settings_controls/ScrollContainer/grid" index="2"] margin_bottom = 27.0 +[node name="action_button" parent="menu/tabs/controls/settings_controls/key_dialog" index="3"] +margin_bottom = 110.0 + [node name="graphics" type="Tabs" parent="menu/tabs"] -editor/display_folded = true visible = false anchor_right = 1.0 anchor_bottom = 1.0 @@ -113,6 +132,9 @@ margin_left = 4.0 margin_top = 45.0 margin_right = -4.0 margin_bottom = -4.0 +focus_neighbour_left = NodePath("../controls") +focus_neighbour_right = NodePath("../system") +focus_mode = 2 [node name="VBoxContainer" type="VBoxContainer" parent="menu/tabs/graphics"] margin_right = 40.0 @@ -126,6 +148,7 @@ margin_bottom = 33.0 margin_top = 37.0 margin_right = 248.0 margin_bottom = 77.0 +pressed = true text = "FULLSCREEN" [node name="light" type="CheckButton" parent="menu/tabs/graphics/VBoxContainer"] @@ -138,9 +161,11 @@ text = "LIGHT" margin_top = 125.0 margin_right = 248.0 margin_bottom = 165.0 +disabled = true text = "SHADOWS" [node name="system" type="Tabs" parent="menu/tabs"] +editor/display_folded = true visible = false anchor_right = 1.0 anchor_bottom = 1.0 @@ -148,6 +173,8 @@ margin_left = 4.0 margin_top = 45.0 margin_right = -4.0 margin_bottom = -4.0 +focus_neighbour_left = NodePath("../graphics") +focus_mode = 2 [node name="GridContainer" type="GridContainer" parent="menu/tabs/system"] margin_left = 12.0 @@ -214,6 +241,9 @@ margin_right = 150.0 margin_bottom = 56.0 grow_horizontal = 0 grow_vertical = 0 +focus_neighbour_left = NodePath("../../back") +focus_neighbour_top = NodePath("../../tabs/game") +focus_neighbour_right = NodePath("../save") size_flags_horizontal = 10 size_flags_vertical = 10 text = "APPLY" @@ -227,12 +257,15 @@ margin_right = 286.0 margin_bottom = 56.0 grow_horizontal = 0 grow_vertical = 0 +focus_neighbour_left = NodePath("../apply") +focus_neighbour_top = NodePath("../../tabs/game") size_flags_horizontal = 10 size_flags_vertical = 10 text = "SAVE" icon = ExtResource( 7 ) flat = true align = 0 +[connection signal="toggled" from="menu/tabs/graphics/VBoxContainer/light" to="." method="_on_light_toggled"] [connection signal="item_selected" from="menu/tabs/system/GridContainer/locales" to="." method="_on_locales_item_selected"] [connection signal="tree_exiting" from="menu/tabs/system/GridContainer/locales" to="." method="_on_locales_tree_exiting"] [connection signal="pressed" from="menu/HBoxContainer/apply" to="." method="_on_apply_pressed"] diff --git a/scripts/game/game.gd b/scripts/game/game.gd index 3960c93..1ea8df3 100644 --- a/scripts/game/game.gd +++ b/scripts/game/game.gd @@ -12,6 +12,9 @@ const REMOVE_LAST = 2 func _ready(): route = get_node("route") + find_node("sun").set_visible(settings.read_value("light", false)) + if find_node("sun").is_visible_in_tree(): + find_node("sun").set_shadow(settings.read_value("shadows", false)) if is_network_master(): route.rpc("add_road",roads_factory.START, -1) diff --git a/scripts/game/settings.gd b/scripts/game/settings.gd index da89ec7..097395f 100644 --- a/scripts/game/settings.gd +++ b/scripts/game/settings.gd @@ -4,6 +4,10 @@ const FILE_PATH = "user://local_storage" const RESOLUTIONS = [Vector2(1920,1080),Vector2(1600,900),Vector2(1366,758),Vector2(1280,720),Vector2(1136,640),Vector2(1024,576)] +const CONTROL_ACTIONS = ["controls_thrust", "controls_break", "controls_add_road", "controls_next_road_type", "controls_prev_road_type", "controls_next_road_variant", "controls_prev_road_variant", "controls_reset", "controls_menu"] + +const INPUT_UI_MAPPING = {"ui_accept" : "controls_add_road", "ui_select" : "controls_add_road", "ui_up" : "controls_next_road_variant", "ui_down" : "controls_prev_road_variant", "ui_left" : "controls_prev_road_type", "ui_right" : "controls_next_road_type"} + onready var view_port = get_tree().get_root() @@ -66,7 +70,8 @@ func apply_settings(): apply_locale() apply_game_server() apply_resolution() - + apply_controls() + func apply_locale(): TranslationServer.set_locale(read_value("locale","en")) @@ -83,12 +88,32 @@ func apply_game_server(): func apply_resolution(): OS.set_window_fullscreen(read_value("fullscreen", true)) - + if OS.is_window_fullscreen(): var base_size = Vector2(1920, 1080) var scale= base_size.x / RESOLUTIONS[read_value("resolution",0)].x - + get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_2D,SceneTree.STRETCH_ASPECT_EXPAND,base_size,scale) else: OS.set_window_size(RESOLUTIONS[read_value("resolution",0)]) - get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT,SceneTree.STRETCH_ASPECT_IGNORE,OS.get_window_size(),1) \ No newline at end of file + get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT,SceneTree.STRETCH_ASPECT_IGNORE,OS.get_window_size(),1) + + +func apply_controls(): + InputMap.load_from_globals() + var control_map = read_value("controls",{}) + for action in InputMap.get_actions(): + if control_map.has(action): + for event in InputMap.get_action_list(action): + if event is InputEventKey && control_map[action].has("key"): + InputMap.action_erase_event(action, event) + event.set_scancode(OS.find_scancode_from_string(control_map[action]["key"])) + InputMap.action_add_event(action,event) + elif event is InputEventJoypadButton && control_map[action].has("joypad"): + InputMap.action_erase_event(action, event) + event.set_button_index(control_map[action]["joypad"]) + InputMap.action_add_event(action,event) + + for ui_mapping in INPUT_UI_MAPPING: + for event in InputMap.get_action_list(INPUT_UI_MAPPING[ui_mapping]): + InputMap.action_add_event(ui_mapping, event) \ No newline at end of file diff --git a/scripts/menus/ingame_menu.gd b/scripts/menus/ingame_menu.gd index 5d22064..8cac0cd 100644 --- a/scripts/menus/ingame_menu.gd +++ b/scripts/menus/ingame_menu.gd @@ -5,14 +5,6 @@ func _draw(): find_node("resume").grab_focus() -func _physics_process(delta): - if Input.is_action_just_pressed("ui_cancel"): - if is_visible_in_tree(): - hide() - else: - show() - - func _on_resume_pressed(): hide() diff --git a/scripts/menus/settings_controls_menu.gd b/scripts/menus/settings_controls_menu.gd index f9a9b49..80aae0d 100644 --- a/scripts/menus/settings_controls_menu.gd +++ b/scripts/menus/settings_controls_menu.gd @@ -18,72 +18,106 @@ func _ready(): func init_mapping(): new_inputs = {} - for action in InputMap.get_actions(): - if action.begins_with("controls_"): - var action_label = Label.new() - action_label.set_name(action + "_label") - action_label.set_text(action) - grid.add_child(action_label) - - var key_action_button = Button.new() - key_action_button.set_h_size_flags(SIZE_SHRINK_CENTER) - key_action_button.set_flat(true) - key_action_button.set_meta("action",action) - key_action_button.set_button_icon(get_node("icons/key").get_button_icon()) - - var joypad_action_button = Button.new() - joypad_action_button.set_h_size_flags(SIZE_SHRINK_CENTER) - joypad_action_button.set_flat(true) - joypad_action_button.set_meta("action",action) - - for mapping in InputMap.get_action_list(action): - if mapping is InputEventKey: - key_action_button.set_text(mapping.as_text()) - key_action_button.set_tooltip(mapping.as_text()) - elif mapping is InputEventJoypadButton: - joypad_action_button.set_tooltip(str(mapping.button_index)) - if has_node("icons/joypad/" + str(mapping.button_index)): - joypad_action_button.set_button_icon(get_node("icons/joypad/" + str(mapping.button_index)).get_button_icon()) - else: - joypad_action_button.set_button_icon(get_node("icons/joypad/other").get_button_icon()) - joypad_action_button.set_text(str(mapping.button_index)) - - grid.add_child(key_action_button) - key_action_button.connect("pressed",self,"_on_button_pressed",[action, INPUT_TYPE_KEY]) - - grid.add_child(joypad_action_button) - joypad_action_button.connect("pressed",self,"_on_button_pressed",[action, INPUT_TYPE_JOYPAD]) + for action in settings.CONTROL_ACTIONS: + var action_label = Label.new() + action_label.set_name(action + "_label") + action_label.set_text(action) + grid.add_child(action_label) + + var key_action_button = Button.new() + key_action_button.set_h_size_flags(SIZE_SHRINK_CENTER) + key_action_button.set_flat(true) + key_action_button.set_meta("action",action) + key_action_button.set_button_icon(get_node("icons/key").get_button_icon()) + + var joypad_action_button = Button.new() + joypad_action_button.set_h_size_flags(SIZE_SHRINK_CENTER) + joypad_action_button.set_flat(true) + joypad_action_button.set_meta("action",action) + + for event in InputMap.get_action_list(action): + if event is InputEventKey: + key_action_button.set_text(event.as_text()) + key_action_button.set_tooltip(event.as_text()) + elif event is InputEventJoypadButton: + joypad_action_button.set_tooltip(str(event.button_index)) + if has_node("icons/joypad/" + str(event.button_index)): + joypad_action_button.set_button_icon(get_node("icons/joypad/" + str(event.button_index)).get_button_icon()) + else: + joypad_action_button.set_button_icon(get_node("icons/joypad/other").get_button_icon()) + joypad_action_button.set_text(str(event.button_index)) + + grid.add_child(key_action_button) + key_action_button.connect("pressed",self,"_on_button_pressed",[key_action_button, INPUT_TYPE_KEY]) + + grid.add_child(joypad_action_button) + joypad_action_button.connect("pressed",self,"_on_button_pressed",[joypad_action_button, INPUT_TYPE_JOYPAD]) func _unhandled_input(event): if key_dialog.is_visible_in_tree(): + var action_button = key_dialog.find_node("action_button") + var check_usage = false if key_dialog.get_meta("type") == INPUT_TYPE_KEY && event is InputEventKey: + check_usage = true last_event = event - key_dialog.set_text(tr(last_event.as_text())) - key_dialog.get_ok().set_disabled(false) + action_button.set_button_icon(get_node("icons/key").get_button_icon()) + action_button.set_text(event.as_text()) + action_button.set_tooltip(event.as_text()) elif key_dialog.get_meta("type") == INPUT_TYPE_JOYPAD && event is InputEventJoypadButton: + check_usage = true last_event = event - key_dialog.set_text(last_event.as_text()) - key_dialog.get_ok().set_disabled(false) + action_button.set_tooltip(str(event.button_index)) + if has_node("icons/joypad/" + str(event.button_index)): + action_button.set_text("") + action_button.set_button_icon(get_node("icons/joypad/" + str(event.button_index)).get_button_icon()) + else: + action_button.set_button_icon(get_node("icons/joypad/other").get_button_icon()) + action_button.set_text(str(event.button_index)) + + if check_usage: + var has_event = "" + for action in settings.CONTROL_ACTIONS: + if InputMap.event_is_action(event, action): + has_event = action + if not has_event == "" && not has_event == last_action: + key_dialog.set_text(tr("KEY_ALREADY_TAKEN") + '\n\'' + tr(has_event) + '\'') + key_dialog.get_ok().set_disabled(true) + else: + key_dialog.set_text(tr("PRESS_KEY")) + key_dialog.get_ok().set_disabled(false) -func _on_button_pressed(action, type): - last_action = action + +func _on_button_pressed(button, type): + last_action = button.get_meta("action") last_event = null + + var action_button = key_dialog.find_node("action_button") + action_button.set_text("") + action_button.set_button_icon(null) key_dialog.set_text(tr("PRESS_KEY")) key_dialog.set_meta("type", type) - key_dialog.connect("confirmed",self,"_on_dialog_confirmed",[type]) + key_dialog.connect("confirmed",self,"_on_dialog_confirmed",[button]) key_dialog.get_ok().set_disabled(true) + key_dialog.get_label().set_align(HALIGN_CENTER) key_dialog.popup_centered() -func _on_dialog_confirmed(type): +func _on_dialog_confirmed(button): if not new_inputs.has(last_action): new_inputs[last_action] = {} match key_dialog.get_meta("type"): INPUT_TYPE_KEY: if last_event is InputEventKey: new_inputs[last_action]["key"] = OS.get_scancode_string(last_event.scancode) + button.set_text(last_event.as_text()) + button.set_tooltip(last_event.as_text()) INPUT_TYPE_JOYPAD: if last_event is InputEventJoypadButton: new_inputs[last_action]["joypad"] = last_event.button_index - print(new_inputs) \ No newline at end of file + button.set_tooltip(str(last_event.button_index)) + if has_node("icons/joypad/" + str(last_event.button_index)): + button.set_button_icon(get_node("icons/joypad/" + str(last_event.button_index)).get_button_icon()) + else: + button.set_button_icon(get_node("icons/joypad/other").get_button_icon()) + button.set_text(str(last_event.button_index)) \ No newline at end of file diff --git a/scripts/menus/settings_menu.gd b/scripts/menus/settings_menu.gd index 505327e..5341ce3 100644 --- a/scripts/menus/settings_menu.gd +++ b/scripts/menus/settings_menu.gd @@ -11,24 +11,31 @@ var locale func _ready(): get_node("menu/back").connect("pressed",self,"_on_back_pressed") - + # game find_node("bots").set_pressed(settings.read_value("bots", true)) - + # graphics find_node("fullscreen").set_pressed(settings.read_value("fullscreen", true)) - + find_node("light").set_pressed(settings.read_value("light", false)) + find_node("shadows").set_pressed(settings.read_value("shadows", false)) + find_node("shadows").set_disabled(not find_node("light").is_pressed()) + for resolution in settings.RESOLUTIONS: find_node("resolution").add_item(str(resolution.x) + " * " + str(resolution.y)) - + find_node("resolution").select(settings.read_value("resolution", 0)) - + # system find_node("server_addr").set_text(game_server.get_server_addr()) find_node("api_addr").set_text(game_server.get_api_addr()) _init_locales() +func _draw(): + game_tab.grab_focus() + + func _on_back_pressed(): queue_free() get_tree().get_root().get_node("main_menu").show() @@ -75,30 +82,37 @@ func _on_save_pressed(): func _on_apply_pressed(): var values = {} - + # game values['player_name'] = player_settings.get_name_node().get_text() values['player_color'] = player_settings.get_color_node().color.to_html() values['bots'] = find_node("bots").is_pressed() values['locale'] = locale - + # graphics values['resolution'] = find_node("resolution").get_selected() values['fullscreen'] = find_node("fullscreen").is_pressed() - values['light'] = find_node("fullscreen").is_pressed() - values['shadows'] = find_node("fullscreen").is_pressed() - + values['light'] = find_node("light").is_pressed() + values['shadows'] = find_node("shadows").is_pressed() + + # controls + values['controls'] = find_node("settings_controls").new_inputs + # system var server_addr = find_node("server_addr").get_text() if server_addr.empty(): server_addr = game_server.SERVER_ADDR values['server_addr'] = server_addr - + var api_addr = find_node("api_addr").get_text() if api_addr.empty(): api_addr = game_server.API_ADDR values['api_addr'] = api_addr - + settings.write_values(values) - + settings.apply_settings() + + +func _on_light_toggled(button_pressed): + find_node("shadows").set_disabled(not button_pressed) diff --git a/scripts/player/human_controls.gd b/scripts/player/human_controls.gd index a7cc74b..95d6ee6 100644 --- a/scripts/player/human_controls.gd +++ b/scripts/player/human_controls.gd @@ -2,38 +2,41 @@ extends Spatial var player:Player onready var camera:InterpolatedCamera = get_node("camera") +onready var ingame_menu:Spatial = find_node("ingame_menu") func _physics_process(delta): if is_network_master() && player != null: + if Input.is_action_just_pressed("controls_menu"): + ingame_menu.set_visible(not ingame_menu.is_visible_in_tree()) if player.is_out: camera.set_speed(0.1) if player.timer.get_time_left() > 0: get_node("hud/reset").set_text(str(int(player.timer.get_time_left()) + 1)) else: - get_node("hud/reset").set_text(tr("RESET")) + get_node("hud/reset").set_text(tr("RESET")) if Input.is_action_pressed("controls_reset"): if player.reset(): camera.set_speed(10) - get_node("hud/reset").set_text("") - else: + get_node("hud/reset").set_text("") + elif not ingame_menu.is_visible_in_tree(): if Input.is_action_pressed("controls_thrust"): player.thrust = 1 elif Input.is_action_pressed("controls_break"): player.thrust = -1 else: player.thrust = 0 - + get_node("hud/speed_slider").set_value(player.current_speed * 1000) - + if Input.is_action_pressed("debug_camera_1"): - set_debug_camera(0) + set_debug_camera(0) elif Input.is_action_pressed("debug_camera_2"): - set_debug_camera(1) + set_debug_camera(1) elif Input.is_action_pressed("debug_camera_3"): - set_debug_camera(2) + set_debug_camera(2) elif Input.is_action_pressed("debug_camera_4"): - set_debug_camera(3) + set_debug_camera(3) func set_player(path:String): diff --git a/scripts/player/player.gd b/scripts/player/player.gd index 5024285..50248cd 100644 --- a/scripts/player/player.gd +++ b/scripts/player/player.gd @@ -53,7 +53,7 @@ func _physics_process(delta): if is_network_master(): if not is_out: var max_speed = MAX_SPEED - + if get_road() != null: var road = get_road() if is_in_group("first"): @@ -62,30 +62,30 @@ func _physics_process(delta): max_speed *= road.get_creator_speed_factor() else: max_speed *= road.get_chasers_speed_factor() - - + + if thrust == 1: current_speed += speed_factor elif thrust == -1: current_speed -= speed_factor * brake_factor else: current_speed -= speed_factor * friction_brake_factor - + if current_speed >= max_speed: current_speed = max_speed elif current_speed < 0: current_speed = 0 - + follow.set_offset(follow.get_offset() + current_speed) - + if follow.get_offset() < 0: follow.set_offset(0) - + if has_next && (path.curve.get_point_count() == 0 || follow.get_unit_offset() >= 1.0): has_next = false if path.curve.get_point_count() > 0: path.curve.clear_points() - + path.curve.set_bake_interval(0.05) for i in range(buffered_curve.get_point_count()): var _pos = buffered_curve.get_point_position(i) @@ -105,7 +105,7 @@ func _physics_process(delta): if get_road() != null: var road = get_road() var penalty_index = road.penalty_index(follow.get_offset(), current_speed) - + if penalty_index >= 0: torque_penalty = road.get_torque_penalty(penalty_index) force_penalty = road.get_force_penalty(penalty_index) @@ -113,7 +113,7 @@ func _physics_process(delta): is_out = true is_resetable = false timer.start() - + check_position() else: var road = get_road() @@ -137,21 +137,21 @@ func get_road(): func _on_raceCar_road_entered(road): - + var prev_road = route.get_road(road.get_index()-1) if prev_road != null: prev_road.body.set_collision_layer_bit(get_index(),0) - + buffered_curve = road.get_lane_curve(lane) - + buffered_rotation = last_rotation - + if path.curve.get_point_count() > 0: buffered_translate = Util.curve_get_last_point(path.curve) - + if road.get_end_rotation().length() != 0: last_rotation += road.get_end_rotation() - + has_next = true @@ -190,31 +190,31 @@ master func reset(): if is_resetable: has_next = false current_speed = 0 - + var road = race_car.road road.body.set_collision_layer_bit(get_index(),1) - + while road.reset_index != 0: road = route.get_road(road.get_index() - road.reset_index) road.body.set_collision_layer_bit(get_index(),1) - + path.curve.clear_points() - + force_penalty = Vector3(0,0,0) torque_penalty = Vector3(0,0,0) - + buffered_translate = road.get_translation() last_rotation = road.get_rotation() - + race_car.road_index = road.get_index() race_car.road = null race_car.collider = null race_car.transform = Transform() race_car.get_node("ray").set_enabled(true) - + follow.set_transform(road.get_transform()) - + is_out = false is_resetable = false return true