bugged-racing/menu/start_menu.gd

45 lines
1.6 KiB
GDScript
Raw Normal View History

2021-11-12 23:03:35 +00:00
extends Panel
const buggy = preload("res://vehicles/buggy.tscn")
const beetle = preload("res://vehicles/beetlecar.tscn")
2021-11-16 17:48:41 +00:00
const bugmobile = preload("res://vehicles/bugmobile.tscn")
2021-11-12 23:03:35 +00:00
const test_scene = preload("res://scenes/test_level.tscn")
2021-11-13 22:55:18 +00:00
const gui_scene = preload("res://player/gui.tscn")
2021-11-12 23:03:35 +00:00
onready var vehicle_selector = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/VehicleSelector
onready var track_selector = $MarginContainer/VSplitContainer/CenterContainer/VBoxContainer/TrackSelector
var vehicles = [beetle, buggy, bugmobile]
var tracks = [test_scene]
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
track_selector.add_item("Test track")
2021-11-12 23:03:35 +00:00
func _on_StartButton_pressed() -> void:
print(vehicle_selector.get_selected_id())
print(track_selector.get_selected_id())
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(track.instance(), vehicle.instance())
2021-11-16 17:48:41 +00:00
func _start_track_with_vehicle(track: Node, vehicle: Node) -> void:
2021-11-13 22:55:18 +00:00
var gui = gui_scene.instance()
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()
func _on_BackButton_pressed() -> void:
2021-11-18 19:48:47 +00:00
get_tree().change_scene("res://menu/main_menu.tscn")