- New selfmade Font

- persistent files
- Hiscore
This commit is contained in:
megamichi 2024-10-09 21:02:14 +02:00
parent 4676b83b61
commit 4c881027a1
56 changed files with 1711 additions and 175 deletions

View file

@ -15,6 +15,7 @@ func _on_duck_gameover() -> void:
$"../../Audio/GameOver".play()
$"../../Audio/Gui-in".play()
show()
func _on_restart_pressed() -> void:

3
code/first_save.json Normal file
View file

@ -0,0 +1,3 @@
{
"hiscore":0
}

39
code/global.gd Normal file
View file

@ -0,0 +1,39 @@
extends Node
signal levelup
signal start
var maxspeed = 260
var speed = 100
var score = 0
var gamerunning = false
var hiscore
func _ready() -> void:
load_save()
#write_save()
func load_save():
var data : FileAccess
if (not FileAccess.file_exists("user://save.json")) or FileAccess.open("user://save.json",FileAccess.READ_WRITE).get_as_text() == "":
data = FileAccess.open("user://save.json",FileAccess.WRITE)
data.store_string(FileAccess.open("res://code/first_save.json",FileAccess.READ).get_as_text())
data.close()
data = FileAccess.open("user://save.json",FileAccess.READ)
var contenttext = JSON.parse_string(data.get_as_text())
print(contenttext)
hiscore = contenttext["hiscore"]
func write_save():
var data : FileAccess
data = FileAccess.open("user://save.json",FileAccess.WRITE)
data.store_string(
JSON.stringify(
{
"hiscore":$"/root/Game/Gui/HiscoreContainer/hiscore".get_score()
}
)
)

18
code/hiscore.gd Normal file
View file

@ -0,0 +1,18 @@
extends Label
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
text = str($"/root/Global".hiscore)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func set_new_hiscore():
if int(text) < int(%ScoreContainer/text.text):
text = %ScoreContainer/text.text
$"/root/Global".write_save()
func get_score():
return int(text)

View file

@ -5,6 +5,8 @@ var biom_n_w = preload("res://assets/Ground/normal_wueste.png")
var biom_w = preload("res://assets/Ground/wueste.png")
func _ready() -> void:
$Screen/Background/Floor/EasterEggFixCollision.disabled = false
$Gui/HiscoreContainer.show()
%ScoreContainer.hide()
func start_game():
$Screen/Background/Floor/EasterEggFixCollision.disabled = true
@ -13,6 +15,8 @@ func start_game():
$Screen/Duck.start()
$Screen/HindernissSpawner.del_all()
$Screen/EastereggSpawner.del_all()
$Gui/HiscoreContainer.hide()
%ScoreContainer.show()
$"/root/Global".gamerunning = true
$"/root/Global".start.emit()
$"/root/Global".score = 0
@ -25,17 +29,14 @@ func _on_level_up_timer_timeout() -> void:
func _score() -> void:
if not $"/root/Global".gamerunning:
$Gui/Score.text = ""
%ScoreContainer/score.text = ""
elif $Screen/Duck.alive:
$"/root/Global".score += 10
$Gui/Score.text = "Score: "+str($"/root/Global".score)
%ScoreContainer/score.text = str($"/root/Global".score)
func _process(delta):
var background_size_x = $Screen/Background/Sprite.texture.get_size().x
var bla = (background_size_x) + $Screen/Background/Sprite.position.x
if $"/root/Global".gamerunning:
$Screen/Background/Sprite.position.x -= $"/root/Global".speed*delta

View file

@ -1,9 +0,0 @@
extends Label
var speed = 70
# Called when the node enters the scene tree for the first time.
#func _ready() -> void:
#text = "0"
# Called every frame. 'delta' is the elapsed time since the previous frame.