Score saving, and loading
This commit is contained in:
@ -26,7 +26,11 @@ const MORTAR_TOWER = preload("res://Game/Towers/mortar_tower.tscn")
|
||||
const DELETER = preload("res://Game/Accesories/deleter.tscn")
|
||||
|
||||
var lives = 0
|
||||
var originallives = 0
|
||||
var coins = 0
|
||||
var save_path = "user://map_scores.save"
|
||||
var map_scores = {}
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
get_node("pausemenu").hide()
|
||||
@ -60,6 +64,11 @@ func _ready() -> void:
|
||||
|
||||
delete_tower_button.connect("button_up", Spawn_Deleter)
|
||||
|
||||
var file = FileAccess.open(save_path, FileAccess.READ)
|
||||
if file:
|
||||
map_scores = file.get_var()
|
||||
file.close()
|
||||
|
||||
func _process(delta : float)-> void:
|
||||
coinlabel.text = "Coins: " + str(coins)
|
||||
livelabel.text = "Lives: " + str(lives)
|
||||
@ -68,6 +77,7 @@ func _process(delta : float)-> void:
|
||||
|
||||
func set_Lifes(amount) -> void:
|
||||
lives = amount
|
||||
originallives = amount
|
||||
|
||||
func get_Lifes():
|
||||
return lives
|
||||
@ -163,6 +173,12 @@ func GameOver() -> void:
|
||||
func GameWon() -> void:
|
||||
get_node("Panel").hide()
|
||||
get_node("GameWon").show()
|
||||
|
||||
map_scores[get_parent().get_parent().name] = int((lives / originallives) *10)
|
||||
var file = FileAccess.open(save_path, FileAccess.WRITE)
|
||||
if file:
|
||||
file.store_var(map_scores)
|
||||
file.close()
|
||||
|
||||
func _on_button_3_pressed() -> void:
|
||||
get_node("pausemenu").hide()
|
||||
|
Reference in New Issue
Block a user