97 lines
3.1 KiB
GDScript
97 lines
3.1 KiB
GDScript
extends Node2D
|
|
|
|
##Onreadys
|
|
#onready var levels = preload("res://maps/leveldata/levels.tres")
|
|
onready var title = $Title
|
|
onready var shard_title = $ShardTitle
|
|
onready var shard_arrow = $ShardArrow
|
|
onready var high_score_any = $HighScoreAny
|
|
onready var high_score_100 = $HighScore100
|
|
onready var levelarrow_up = $LevelArrowUp
|
|
onready var levelarrow_down = $LevelArrowDown
|
|
onready var lives_mode_text = $LivesModeText
|
|
onready var easy_mode_text = $EasyModeText
|
|
#Shards
|
|
onready var shards = [
|
|
$ShardGraphics/Shard,
|
|
$ShardGraphics/Shard2,
|
|
$ShardGraphics/Shard3,
|
|
$ShardGraphics/Shard4,
|
|
$ShardGraphics/Shard5,
|
|
$ShardGraphics/Shard6,
|
|
$ShardGraphics/Shard7,
|
|
$ShardGraphics/Shard8
|
|
]
|
|
##Runtime
|
|
var save = 0
|
|
var current_level = 0
|
|
var current_shard = 0
|
|
#Here just so game doesnt crash
|
|
export var target_time_100 = 0
|
|
export var target_time_any = 0
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
easy_mode_text.text = "difficulty: %s, Z to change" % ["sweet", "salty", "spicy", "pungent"][Game.difficulty]
|
|
Fade.fade_in(0.000000000000001)
|
|
change_current_level(Game.current_level)
|
|
Audio.ac_music.stop()
|
|
|
|
func _physics_process(delta):
|
|
if Input.is_action_just_pressed("ui_up"): change_current_level(-1)
|
|
if Input.is_action_just_pressed("ui_down"): change_current_level(1)
|
|
if Input.is_action_just_pressed("ui_left"): change_current_shard(-1)
|
|
if Input.is_action_just_pressed("ui_right"): change_current_shard(1)
|
|
# get current level's data
|
|
var level = LevelData.levels[current_level]
|
|
#Draw level title
|
|
title.text = level.title
|
|
#Draw Shard Title
|
|
shard_title.text = level.shard_titles[current_shard]
|
|
#Select level
|
|
if Input.is_action_just_pressed("ui_accept"):
|
|
Game.current_level = current_level
|
|
Game.change_map(level.scene)
|
|
#Toggle lives mode
|
|
if Input.is_action_just_pressed("ui_cancel"):
|
|
Game.difficulty = (Game.difficulty + 1) % 4
|
|
easy_mode_text.text = "difficulty: %s, Z to change" % ["sweet", "salty", "spicy", "pungent"][Game.difficulty]
|
|
|
|
func change_current_shard(amount):
|
|
if current_shard + amount != -1 && current_shard + amount != 8: #Check if in range
|
|
current_shard += amount
|
|
shard_arrow.position.x += 15 * amount
|
|
|
|
func change_current_level(amount):
|
|
#Change level
|
|
if current_level + amount >= 0 && current_level + amount < LevelData.levels.size(): #Check if in range
|
|
current_level += amount
|
|
#Show arrows or don't
|
|
if current_level == 0:
|
|
levelarrow_up.visible = false
|
|
levelarrow_down.visible = true
|
|
elif current_level == LevelData.levels.size() - 1:
|
|
levelarrow_up.visible = true
|
|
levelarrow_down.visible = false
|
|
else:
|
|
levelarrow_down.visible = true
|
|
levelarrow_up.visible = true
|
|
#Return Shard select
|
|
current_shard = 0
|
|
shard_arrow.position.x = 76
|
|
#Load new data
|
|
var save_id = LevelData.levels[current_level].save_id
|
|
var save_data = Save.current_file.levels[save_id]
|
|
# set any% scores
|
|
high_score_any.text = "Any%%\n%05d\n%s" % [
|
|
save_data.score_any,
|
|
Game.format_time(save_data.time_any)
|
|
]
|
|
# set 100% scores
|
|
high_score_100.text = "100%%\n%05d\n%s" % [
|
|
save_data.score_100,
|
|
Game.format_time(save_data.time_100)
|
|
]
|
|
# set collected shards
|
|
for i in 8:
|
|
shards[i].visible = save_data.shards_collected[i]
|