ape-ame/MainMenu.gd

54 lines
1.7 KiB
GDScript3
Raw Normal View History

2024-04-17 15:00:20 -04:00
extends Control
2024-04-19 17:59:19 -04:00
const MAIN_SCENE_PATH = "res://main.tscn"
const TUTORIAL_SCENE_PATH = "res://tutorial.tscn"
2024-04-23 14:38:44 -04:00
var tip_level = 1
var config = ConfigFile.new()
2024-04-19 17:59:19 -04:00
2024-04-24 14:57:29 -04:00
func disabled_ready():
if config.load("user://settings.cfg") == OK and "hidden" in config.get_sections() and config.get_value("hidden", "tip_level") != null:
tip_level = config.get_value("hidden", "tip_level")
else:
tip_level = 1
config.set_value("hidden", "tip_level", tip_level)
2024-04-23 14:38:44 -04:00
if randi_range(0, 20) == 5: # small chance to get more and more insane tips as you keep playing
tip_level += 1
config.set_value("hidden", "tip_level", tip_level)
2024-04-24 14:57:29 -04:00
config.save("user://settings.cfg")
2024-04-17 15:00:20 -04:00
2024-04-23 14:38:44 -04:00
func pick(l):
return l[randi_range(0, len(l)-1)]
2024-04-17 15:00:20 -04:00
2024-04-23 14:38:44 -04:00
func sort_tips():
var tips = FileAccess.open("res://tips.txt", FileAccess.READ).get_as_text().strip_edges().split("\n")
var tips_by_level = {1: [], 2: [], 3: []}
for tip in tips:
var level = int(tip.split(" | ")[0])
var text = tip.split(" | ")[1]
tips_by_level[level].append(text)
return tips_by_level
2024-04-17 15:00:20 -04:00
func play():
2024-04-23 14:43:16 -04:00
ResourceLoader.load_threaded_request(MAIN_SCENE_PATH)
2024-04-23 14:38:44 -04:00
$"LoadingScreen".show()
var tip_options = []
for i in range(1, tip_level+1):
tip_options += sort_tips()[i]
var tip = pick(tip_options)
$LoadingScreen/Tip.text = "Tip: %s" % tip
2024-05-09 14:23:34 -04:00
await get_tree().create_timer(0.8).timeout
2024-04-23 14:43:16 -04:00
var game = ResourceLoader.load_threaded_get(MAIN_SCENE_PATH)
get_tree().change_scene_to_packed(game)
func play_tutorial():
ResourceLoader.load_threaded_request(TUTORIAL_SCENE_PATH)
$"LoadingScreen".show()
var tip_options = []
$LoadingScreen/Tip.text = "Try different characters and movement settings"
await get_tree().create_timer(3).timeout
var game = ResourceLoader.load_threaded_get(TUTORIAL_SCENE_PATH)
get_tree().change_scene_to_packed(game)