mirror of
https://git.kittycat.homes/zoe/pegchamp.git
synced 2024-08-15 03:15:39 +00:00
63 lines
1.4 KiB
GDScript
63 lines
1.4 KiB
GDScript
extends Node2D
|
|
|
|
export var stage_name = "test stage"
|
|
export var high_score = 0
|
|
export var already_beaten = false
|
|
|
|
func _ready():
|
|
load_level()
|
|
$Killzone.connect("level_just_won", self, "save_level")
|
|
GameStats.multiplier = 1
|
|
print(high_score)
|
|
|
|
func _physics_process(_delta):
|
|
fast_forward()
|
|
|
|
func fast_forward():
|
|
if (Input.is_action_pressed("fast_forward")):
|
|
Engine.time_scale = 3
|
|
if (Input.is_action_just_released("fast_forward")):
|
|
Engine.time_scale = 1
|
|
|
|
func load_level():
|
|
var filename = give_filename()
|
|
var file = File.new()
|
|
if file.file_exists(filename):
|
|
var err = file.open(filename, File.READ)
|
|
if err == OK:
|
|
var data = file.get_var()
|
|
file.close()
|
|
load_data(data)
|
|
|
|
func load_data(data):
|
|
already_beaten = data.already_beaten
|
|
high_score = data.high_score
|
|
|
|
|
|
func save_level():
|
|
print("saving game")
|
|
if !already_beaten:
|
|
GameStats.unlock_points += 10
|
|
already_beaten = true
|
|
else: GameStats.unlock_points += 1
|
|
|
|
|
|
if GameStats.score > high_score:
|
|
print("New High score!")
|
|
high_score = GameStats.score
|
|
|
|
var data = {
|
|
"high_score" : high_score,
|
|
"already_beaten" : already_beaten
|
|
}
|
|
var file = File.new()
|
|
var err = file.open(give_filename(), File.WRITE)
|
|
if err == OK:
|
|
file.store_var(data)
|
|
file.close()
|
|
else: print("something went wrong while saving your high scores! please check file permissions!")
|
|
Saves.save_game()
|
|
|
|
func give_filename():
|
|
var save_path = "user://" + String(stage_name) + ".dat"
|
|
return save_path
|