bugged-racing/menu/start_menu.gd

57 lines
2.1 KiB
GDScript
Raw Normal View History

2021-11-12 23:03:35 +00:00
extends Panel
const BUGGY = "res://vehicles/buggy.tscn"
const BEETLE = "res://vehicles/beetlecar.tscn"
const BUGMOBILE = "res://vehicles/bugmobile.tscn"
const TEST_SCENE = "res://scenes/test_level.tscn"
const INFINITE_LOOP_SCENE = "res://scenes/infinite_loop_track_level.tscn"
const ROUNDING_ERROR = "res://scenes/rounding_error_track_level.tscn"
const SCARAB = "res://scenes/scarab_track_level.tscn"
const RACE_CONDITION = "res://scenes/race_condition_track_level.tscn"
const GUI_SCENE = "res://player/gui.tscn"
2021-11-12 23:03:35 +00:00
2021-11-18 23:36:05 +00:00
var vehicles = [BEETLE, BUGGY, BUGMOBILE]
2021-11-22 17:36:13 +00:00
var tracks = [INFINITE_LOOP_SCENE, ROUNDING_ERROR, RACE_CONDITION, SCARAB, TEST_SCENE]
2021-11-18 23:36:05 +00:00
# gdlint: ignore=max-line-length
onready var vehicle_selector = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/VehicleSelector
2021-11-18 23:36:05 +00:00
# gdlint: ignore=max-line-length
onready var track_selector = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/TrackSelector
2021-11-14 21:54:55 +00:00
func _ready() -> void:
vehicle_selector.grab_focus()
vehicle_selector.add_item("Beetlecar")
vehicle_selector.add_item("Buggy")
vehicle_selector.add_item("Bugmobile")
2021-11-12 23:03:35 +00:00
2021-11-18 20:58:24 +00:00
track_selector.add_item("Infinite Loop")
2021-11-20 19:26:24 +00:00
track_selector.add_item("Rounding Error")
2021-11-22 17:36:13 +00:00
track_selector.add_item("Race Condition")
2021-11-21 22:08:52 +00:00
track_selector.add_item("Scarab")
track_selector.add_item("Testing grounds")
2021-11-12 23:03:35 +00:00
2021-11-18 23:36:05 +00:00
func _on_StartButton_pressed() -> void:
if vehicle_selector.get_selected_id() < 0:
return
if track_selector.get_selected_id() < 0:
return
var vehicle = vehicles[vehicle_selector.get_selected_id()]
var track = tracks[track_selector.get_selected_id()]
_start_track_with_vehicle(load(track).instance(), load(vehicle).instance())
2021-11-16 17:48:41 +00:00
2021-11-18 23:36:05 +00:00
func _start_track_with_vehicle(track: Node, vehicle: Node) -> void:
var gui = load(GUI_SCENE).instance()
2021-11-13 22:55:18 +00:00
vehicle.connect("speed_updated", gui, "update_speed")
vehicle.connect("rpm_updated", gui, "update_rpm")
vehicle.connect("gear_updated", gui, "update_gear")
track.call_deferred("spawn_player", vehicle, gui)
get_tree().root.call_deferred("add_child", track)
2021-11-12 23:03:35 +00:00
queue_free()
2021-11-18 23:36:05 +00:00
2021-11-12 23:03:35 +00:00
func _on_BackButton_pressed() -> void:
2021-11-18 19:48:47 +00:00
get_tree().change_scene("res://menu/main_menu.tscn")