This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues/pull-requests.
evospace/ui/main_menu/menu.gd

59 lines
1.5 KiB
GDScript
Raw Permalink Normal View History

2020-09-06 23:02:19 +03:00
extends Control
onready var caret = $caret
var index = 0
var spacing = 16
var start_position = 8
var menu_items = 0
2020-09-07 01:16:05 +03:00
var positions = [ 8, 24, 40 ]
2020-09-06 23:02:19 +03:00
var highscores_screen = load("ui/hiscores/hiscores.tscn")
var game_screen = load("levels/demo.tscn")
func _ready():
menu_items = get_children().size() - 1
highscores_screen = highscores_screen.instance()
game_screen = game_screen.instance()
func _process(delta):
if Input.is_action_just_pressed("ui_down"):
if index == menu_items - 1:
index = 0
else:
index += 1
update_caret()
elif Input.is_action_just_pressed("ui_up"):
if index == 0:
index = menu_items - 1
else:
index -= 1
update_caret()
if Input.is_action_just_pressed("player_shoot"):
var action = str(get_child(index).name)
if has_method(action):
call(action)
Input.action_release("player_shoot")
else:
print_debug(action, " is not a valid menu action!")
func update_caret():
caret.rect_position.y = start_position + (spacing * index)
func start():
get_node("../../").queue_free()
get_tree().get_root().add_child(game_screen)
2020-09-07 01:16:05 +03:00
func infinite():
get_node("../../").queue_free()
get_tree().get_root().add_child(game_screen)
get_tree().get_root().get_node("level").get_node("hud").timer.stop()
get_tree().get_root().get_node("level").get_node("hud").get_node("layer").get_node("timer_label").hide() # Oh boy...there is a better way of doing this _I know it_
2020-09-06 23:02:19 +03:00
func highscores():
get_node("../../").queue_free()
get_tree().get_root().add_child(highscores_screen)
func quit():
get_tree().quit()