mirror of
https://github.com/HarmonyHoney/tiny_crate.git
synced 2026-01-23 02:34:53 +00:00
death & speedrun counter working (=
This commit is contained in:
parent
97cd918f51
commit
73c11b4659
7 changed files with 92 additions and 36 deletions
|
|
@ -246,6 +246,7 @@ func remove_player():
|
|||
|
||||
func death():
|
||||
print(name + " died")
|
||||
Shared.die()
|
||||
|
||||
# explosion
|
||||
var inst = scene_explosion.instance()
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ var bus_volume = [10, 10, 10]
|
|||
var current_map := 0
|
||||
var maps := []
|
||||
var map_save := 0
|
||||
var map_name := ""
|
||||
var map_clock := 0.0
|
||||
var map_times := {}
|
||||
var deaths := {}
|
||||
|
||||
var actors := []
|
||||
var player
|
||||
|
|
@ -53,19 +57,7 @@ func _ready():
|
|||
print("maps: ", maps)
|
||||
|
||||
# load save data
|
||||
var l = load_file(save_filename)
|
||||
if l:
|
||||
save_data = JSON.parse(l).result
|
||||
print("save_data: " + JSON.print(save_data, "\t"))
|
||||
if save_data.has("map"):
|
||||
map_save = int(save_data["map"])
|
||||
if save_data.has("notes"):
|
||||
notes = PoolIntArray(save_data["notes"])
|
||||
else:
|
||||
create_save()
|
||||
else:
|
||||
print(save_filename + " not found")
|
||||
create_save()
|
||||
load_save()
|
||||
|
||||
Wipe.connect("finish", self, "wipe_finish")
|
||||
|
||||
|
|
@ -75,7 +67,7 @@ func _ready():
|
|||
"api_key": str(api_key),
|
||||
"game_id": "TinyCrate",
|
||||
"game_version": "1.0.0",
|
||||
"log_level": 1})
|
||||
"log_level": 2})
|
||||
|
||||
SilentWolf.configure_scores({"open_scene_on_close": "res://scenes/MainPage.tscn"})
|
||||
|
||||
|
|
@ -89,6 +81,10 @@ func _physics_process(delta):
|
|||
reset_clock -= delta
|
||||
if reset_clock < 0:
|
||||
do_reset()
|
||||
|
||||
# map time
|
||||
if !Pause.is_paused:
|
||||
map_clock += delta
|
||||
|
||||
### Changing Maps
|
||||
|
||||
|
|
@ -127,12 +123,33 @@ func change_map():
|
|||
get_tree().change_scene(scene_path)
|
||||
is_level_select = scene_path == level_select_path
|
||||
is_in_game = scene_path.begins_with(map_path) or scene_path.begins_with(win_screen_path)
|
||||
#TouchScreen.pause.visible = is_in_game
|
||||
map_name = "" if !is_in_game else scene_path.split("/")[-1].trim_suffix(".tscn")
|
||||
map_clock = 0.0
|
||||
|
||||
Pause.set_process_input(true)
|
||||
is_note = false
|
||||
UI.notes.visible = is_level_select
|
||||
UI.notes_label.text = str(notes.size())
|
||||
UI.keys(false, false)
|
||||
|
||||
if is_in_game:
|
||||
TouchScreen.turn_arrows(false)
|
||||
TouchScreen.show_keys(true, true, true, true, true)
|
||||
elif is_level_select:
|
||||
UI.keys()
|
||||
TouchScreen.turn_arrows(false)
|
||||
TouchScreen.show_keys()
|
||||
elif scene_path == main_menu_path:
|
||||
UI.keys(true, true, false)
|
||||
TouchScreen.turn_arrows(true)
|
||||
TouchScreen.show_keys(true, false, true)
|
||||
elif scene_path == options_menu_path:
|
||||
UI.keys()
|
||||
TouchScreen.turn_arrows(true)
|
||||
TouchScreen.show_keys()
|
||||
elif scene_path == credits_path:
|
||||
UI.keys(false, true)
|
||||
TouchScreen.show_keys(false, true, false)
|
||||
|
||||
### Saving and Loading
|
||||
|
||||
|
|
@ -149,11 +166,34 @@ func load_file(fname = "box.save"):
|
|||
file.close()
|
||||
return content
|
||||
|
||||
func save():
|
||||
save_file(save_filename, JSON.print(save_data, "\t"))
|
||||
|
||||
func create_save():
|
||||
save_data = {}
|
||||
save_data["map"] = 0
|
||||
save_data["notes"] = []
|
||||
save_file(save_filename, JSON.print(save_data, "\t"))
|
||||
save_data["times"] = {}
|
||||
save()
|
||||
|
||||
func load_save():
|
||||
var l = load_file(save_filename)
|
||||
if l:
|
||||
save_data = JSON.parse(l).result
|
||||
print("save_data: " + JSON.print(save_data, "\t"))
|
||||
if save_data.has("map"):
|
||||
map_save = int(save_data["map"])
|
||||
if save_data.has("notes"):
|
||||
notes = PoolIntArray(save_data["notes"])
|
||||
if save_data.has("times"):
|
||||
map_times = Dictionary(save_data["times"])
|
||||
if save_data.has("deaths"):
|
||||
deaths = Dictionary(save_data["deaths"])
|
||||
else:
|
||||
create_save()
|
||||
else:
|
||||
print(save_filename + " not found")
|
||||
create_save()
|
||||
|
||||
func delete_save():
|
||||
print("delete save")
|
||||
|
|
@ -162,9 +202,10 @@ func delete_save():
|
|||
func unlock():
|
||||
map_save = 99
|
||||
save_data["map"] = map_save
|
||||
save_file(save_filename, JSON.print(save_data, "\t"))
|
||||
save()
|
||||
|
||||
func win():
|
||||
var ms = map_save
|
||||
if map_save < current_map + 1:
|
||||
map_save = current_map + 1
|
||||
|
||||
|
|
@ -172,15 +213,29 @@ func win():
|
|||
notes.append(current_map)
|
||||
notes.sort()
|
||||
|
||||
if !map_times.has(map_name) or (map_times.has(map_name) and (map_times[map_name] > map_clock)):
|
||||
map_times[map_name] = map_clock
|
||||
|
||||
save_data["map"] = map_save
|
||||
save_data["notes"] = notes
|
||||
save_data["times"] = map_times
|
||||
|
||||
save_file(save_filename, JSON.print(save_data, "\t"))
|
||||
save()
|
||||
print("map complete, save_data: ", save_data)
|
||||
|
||||
set_map(current_map + 1)
|
||||
if map_save > ms:
|
||||
set_map(current_map + 1)
|
||||
else:
|
||||
scene_path = level_select_path
|
||||
start_reset()
|
||||
|
||||
func die():
|
||||
deaths[map_name] = 1 if !deaths.has(map_name) else (deaths[map_name] + 1)
|
||||
save_data["deaths"] = deaths
|
||||
save()
|
||||
print("you died, save_data: ", save_data)
|
||||
|
||||
|
||||
# look into a folder and return a list of filenames without file extension
|
||||
func dir_list(path : String):
|
||||
var array = []
|
||||
|
|
|
|||
|
|
@ -20,9 +20,6 @@ onready var node_audio_no : AudioStreamPlayer = $Audio/No
|
|||
|
||||
func _ready():
|
||||
switch_menu("main", true)
|
||||
UI.keys(true, true, false)
|
||||
TouchScreen.turn_arrows(true)
|
||||
TouchScreen.show_keys(true, false, true)
|
||||
|
||||
func _input(event):
|
||||
if !is_input:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
extends Node2D
|
||||
|
||||
func _ready():
|
||||
UI.keys(false, true)
|
||||
TouchScreen.show_keys(false, true, false)
|
||||
pass
|
||||
|
||||
func _input(event):
|
||||
if event.is_action_pressed("action"):
|
||||
|
|
|
|||
|
|
@ -8,9 +8,6 @@ onready var node_audio_scroll : AudioStreamPlayer = $AudioScroll
|
|||
|
||||
func _ready():
|
||||
select_item(0)
|
||||
UI.keys()
|
||||
TouchScreen.turn_arrows(true)
|
||||
TouchScreen.show_keys()
|
||||
|
||||
func _input(event):
|
||||
var up = event.is_action_pressed("up")
|
||||
|
|
|
|||
|
|
@ -18,11 +18,6 @@ onready var node_audio_back : AudioStreamPlayer = $AudioBack
|
|||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
Shared.is_level_select = true
|
||||
UI.keys()
|
||||
TouchScreen.turn_arrows(false)
|
||||
TouchScreen.show_keys()
|
||||
|
||||
# make screens
|
||||
screen = $Control/Screen.duplicate()
|
||||
$Control/Screen.queue_free()
|
||||
|
|
@ -35,6 +30,18 @@ func _ready():
|
|||
new.rect_position += Vector2(sx + (sy % 2) * 0.5, sy) * screen_dist
|
||||
new.get_node("Overlay/Label").text = Shared.maps[i]
|
||||
new.get_node("Overlay/Note").visible = Shared.notes.has(i)
|
||||
|
||||
var map_name = Shared.maps[i].trim_suffix(".tscn")
|
||||
var is_time := Shared.map_times.has(map_name)
|
||||
new.get_node("Overlay/Time").visible = is_time
|
||||
if is_time:
|
||||
new.get_node("Overlay/Time/Label").text = str(Shared.map_times[map_name]).pad_decimals(2)
|
||||
|
||||
var is_death : bool = Shared.deaths.has(map_name) and Shared.deaths[map_name] > 0
|
||||
new.get_node("Overlay/Death").visible = is_death
|
||||
if is_death:
|
||||
new.get_node("Overlay/Death/Label").text = str(Shared.deaths[map_name])
|
||||
|
||||
screens.add_child(new)
|
||||
view_scene(new.get_node("Vis/ViewportContainer/Viewport"), Shared.map_path + Shared.maps[i])
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
extends Node2D
|
||||
|
||||
func _ready():
|
||||
if !Shared.is_level_select:
|
||||
TouchScreen.turn_arrows(false)
|
||||
TouchScreen.show_keys(true, true, true, true, true)
|
||||
#func _ready():
|
||||
# if !Shared.is_level_select:
|
||||
# TouchScreen.turn_arrows(false)
|
||||
# TouchScreen.show_keys(true, true, true, true, true)
|
||||
|
||||
#class_name Stage
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue