- implementing biom change
- fixing typo in "highscore"
This commit is contained in:
parent
520a5db2c6
commit
431fb8220e
24 changed files with 242 additions and 105 deletions
|
@ -1,6 +1,4 @@
|
|||
extends Control
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
show()
|
||||
|
|
|
@ -3,7 +3,7 @@ extends TextureRect
|
|||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
#global_position.y = -80
|
||||
$AnimationPlayer.play_backwards("out-in")
|
||||
hide()
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
|
@ -15,7 +15,10 @@ func _on_duck_gameover() -> void:
|
|||
$"../../Audio/GameOver".play()
|
||||
$"../../Audio/Gui-in".play()
|
||||
show()
|
||||
|
||||
print($"/root/Global".hiscore)
|
||||
if %ScoreContainer.get_score() > $"/root/Global".hiscore:
|
||||
$"/root/Global".write_save()
|
||||
|
||||
|
||||
|
||||
func _on_restart_pressed() -> void:
|
||||
|
|
|
@ -4,36 +4,43 @@ 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())
|
||||
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"]
|
||||
data = FileAccess.open("user://save.json", FileAccess.READ)
|
||||
|
||||
var content_text = JSON.parse_string(data.get_as_text())
|
||||
|
||||
if content_text:
|
||||
print("loaded: ",content_text)
|
||||
hiscore = content_text.get("hiscore", 0)
|
||||
else:
|
||||
print("Failed to parse JSON")
|
||||
data.close()
|
||||
|
||||
|
||||
func write_save():
|
||||
var data : FileAccess
|
||||
data = FileAccess.open("user://save.json",FileAccess.WRITE)
|
||||
data.store_string(
|
||||
JSON.stringify(
|
||||
var content = JSON.stringify(
|
||||
{
|
||||
"hiscore":$"/root/Game/Gui/HiscoreContainer/hiscore".get_score()
|
||||
"hiscore":$/root/Game/Gui/ScoreContainer.get_score()
|
||||
}
|
||||
)
|
||||
)
|
||||
print("saved: ",content)
|
||||
data.store_string(content)
|
||||
|
|
|
@ -8,11 +8,6 @@ func _ready() -> void:
|
|||
# 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)
|
||||
#func get_score():
|
||||
# return int(text)
|
||||
|
|
16
code/main.gd
16
code/main.gd
|
@ -1,8 +1,5 @@
|
|||
extends Node
|
||||
|
||||
var biom_n = preload("res://assets/Ground/normal.png")
|
||||
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()
|
||||
|
@ -10,11 +7,11 @@ func _ready() -> void:
|
|||
|
||||
func start_game():
|
||||
$Screen/Background/Floor/EasterEggFixCollision.disabled = true
|
||||
$Screen/HindernissSpawner.del_all()
|
||||
$Gui/EastereggSpawner.del_all()
|
||||
$Screen/SpawnTimer.start()
|
||||
$Screen/LevelUpTimer.start()
|
||||
$Screen/Duck.start()
|
||||
$Screen/HindernissSpawner.del_all()
|
||||
$Screen/EastereggSpawner.del_all()
|
||||
$Gui/HiscoreContainer.hide()
|
||||
%ScoreContainer.show()
|
||||
$"/root/Global".gamerunning = true
|
||||
|
@ -35,12 +32,5 @@ func _score() -> void:
|
|||
%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
|
||||
if bla <= 0:
|
||||
#$Screen/Background/Sprite.texture =biom_n_w
|
||||
$Screen/Background/Sprite.position.x = 0
|
||||
pass
|
||||
|
||||
|
|
14
code/score.gd
Normal file
14
code/score.gd
Normal file
|
@ -0,0 +1,14 @@
|
|||
extends HBoxContainer
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func get_score():
|
||||
return int($score.text)
|
Loading…
Add table
Add a link
Reference in a new issue