diff --git a/Control.gd b/Control.gd index f8e6082..6c1c6ef 100644 --- a/Control.gd +++ b/Control.gd @@ -1,7 +1,12 @@ extends Node2D func _on_start_pressed(): + NewScript.startGame() get_tree().change_scene_to_file("res://TmAP.tscn") func _on_quit_pressed(): get_tree().quit() + + +func _on_high_pressed(): + NewScript.getHigh() diff --git a/TileMap.gd b/TileMap.gd index ed40409..8f836a3 100644 --- a/TileMap.gd +++ b/TileMap.gd @@ -1,8 +1,8 @@ extends TileMap -@export var playerPos = Vector2.ZERO +@export var playerPos :Vector2 = Vector2.ZERO -@onready var player =$"../CharacterBody2D" +@onready var player :CharacterBody2D =$"../CharacterBody2D" var rng = RandomNumberGenerator.new() # Called when the node enters the scene tree for the first time. func _ready(): @@ -10,41 +10,39 @@ func _ready(): #return random int func roller(): - var rum = rng.randi_range(0, 200) - var randomHouse = rng.randi_range(5,10) - var randomPower = rng.randi_range(2,8) - var randomGap = rng.randi_range(1,20) - var randomSet = [rum, randomHouse,randomPower,randomGap] + var rum :int = rng.randi_range(0, 200) + var randomHouse :int = rng.randi_range(5,10) + var randomPower :int = rng.randi_range(2,8) + var randomGap :int = rng.randi_range(1,15) + var randomSet :Array = [rum, randomHouse,randomPower,randomGap] return randomSet #draws the ground, houses and powerups -func drawPat(playerPos): - var tilePos = Vector2i(playerPos.x+(36),11) - var tileCheck = tilePos + Vector2i(1,1) +func drawPat(playerPost :Vector2): + var tilePos = Vector2(playerPost.x+(36),11) + var tileCheck = tilePos + Vector2(1,1) var rum = roller() if get_cell_tile_data(0,tileCheck,false) == null: - set_pattern(0,tilePos +Vector2i(rum[3],0),tile_set.get_pattern(1)) + set_pattern(0,tilePos +Vector2(rum[3],0),tile_set.get_pattern(1)) if int(playerPos.x) % 3 == 0: if rum[0] > 180: - set_pattern(1,tilePos-Vector2i(-8,rum[1]),tile_set.get_pattern(4)) + set_pattern(1,tilePos-Vector2(-8,rum[1]),tile_set.get_pattern(4)) if int(playerPos.x) % 7 == 0: if rum[0] > 180: - set_pattern(1,tilePos-Vector2i(-8,rum[2]),tile_set.get_pattern(5)) + set_pattern(1,tilePos-Vector2(-8,rum[2]),tile_set.get_pattern(5)) #removes old tiles -func garbageCollect(playerPos): +func garbageCollect(playerPost :Vector2): for dist in get_used_cells(0): - if playerPos.x-dist.x > 0: - if sqrt((playerPos.x-dist.x) ** 2 + (playerPos.y - dist.y)**2) > 200: - erase_cell(0, dist) + if playerPost.x-dist.x > 100: + erase_cell(0, dist) for dist in get_used_cells(1): - if playerPos.x-dist.x > 0: - if sqrt((playerPos.x-dist.x) ** 2 + (playerPos.y - dist.y)**2) > 200: - erase_cell(1, dist) + if playerPost.x-dist.x > 100: + erase_cell(1, dist) # Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): +func _process(_delta): playerPos = self.local_to_map(player.position) if playerPos.y > 15: NewScript.playerDeath() diff --git a/mainMenu.tscn b/mainMenu.tscn index 11c4b5e..fb9ad70 100644 --- a/mainMenu.tscn +++ b/mainMenu.tscn @@ -49,4 +49,5 @@ offset_bottom = 336.0 text = "Quit Game" [connection signal="pressed" from="Start" to="Control" method="_on_start_pressed"] +[connection signal="pressed" from="High" to="Control" method="_on_high_pressed"] [connection signal="pressed" from="Quit" to="Control" method="_on_quit_pressed"] diff --git a/new_script.gd b/new_script.gd index abcb7fc..f56140b 100644 --- a/new_script.gd +++ b/new_script.gd @@ -1,6 +1,8 @@ extends Node +var savePath :String ="user://user.save" -var score= 0 +var score :int = 0 +var highScores : Array = [0] func playerPoScore(): score += 1 @@ -11,5 +13,31 @@ func hit(data): elif data == "power": score += 30 -func playerDeath(): + +func startGame(): score = 0 + +func playerDeath(): + if FileAccess.file_exists("user://user.save"): + var file = FileAccess.open(savePath, FileAccess.READ) + if file.get_as_text(): + print(highScores.min()) + highScores = str_to_var(file.get_as_text()) + if score > highScores.min(): + highScores.append(score) + else: + highScores.append(score) + save() + +func save(): + var file = FileAccess.open(savePath, FileAccess.WRITE) + file.store_line(str(highScores)) + + +func getHigh(): + print("here") + if not FileAccess.file_exists("user://user.save"): + pass + var file = FileAccess.open(savePath, FileAccess.READ) + var data = file.get_as_text() + print(data) diff --git a/player.gd b/player.gd index d75e538..299e6dc 100644 --- a/player.gd +++ b/player.gd @@ -1,8 +1,8 @@ extends CharacterBody2D -const speed = 190.0 -const JUMP_VELOCITY = -400.0 -const accel = 1.0071 -const strength= 3.5 +const speed :float = 190.0 +const JUMP_VELOCITY :float = -400.0 +const accel :float = 1.0071 +const strength :float = 3.5 # Get the gravity from the project settings to be synced with RigidBody nodes. var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") @@ -18,7 +18,7 @@ func get_input(): func _physics_process(delta): var playerInput = get_input() - # Add the gravity. + # Add the Gravity. if not is_on_floor(): velocity.y += gravity * delta* 3 diff --git a/project.godot b/project.godot index 146d986..8fc199f 100644 --- a/project.godot +++ b/project.godot @@ -12,6 +12,8 @@ config_version=5 config/name="Testrun" run/main_scene="res://mainMenu.tscn" +config/use_custom_user_dir=true +config/custom_user_dir_name="SavesT" config/features=PackedStringArray("4.2", "Forward Plus") config/icon="res://icon.svg"