Lekcja 11 - score

 avatar
TaktycznyBocian
plain_text
2 years ago
771 B
6
Indexable
extends Node2D

const SAVE_FILE_PAHT = "user://savedata.save"

var highscore = 0

func load_score():
	var save_data = File.new()
	if save_data.file_exists(SAVE_FILE_PAHT):
		save_data.open(SAVE_FILE_PAHT, File.READ)
		var content = save_data.get_as_text()
		highscore = int(content)
		save_data.close()

func save_score():
	var save_data = File.new()
	save_data.open(SAVE_FILE_PAHT, File.WRITE)
	save_data.store_string(str(highscore))
	save_data.close()
	
func _ready():
	load_score()
	$HighccoreText.text = "H: " + str(highscore)

func update_score(snake_lenght):
	$ScoreText.text = "P: " + str(snake_lenght - 2)
	if snake_lenght - 2 > highscore:
		highscore = snake_lenght - 2
		save_score()
		$HighccoreText.text = "H: " + str(highscore)
Editor is loading...