typed everything, added high scores
parent
ea064173eb
commit
2c00f4b3be
|
@ -1,7 +1,12 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
func _on_start_pressed():
|
func _on_start_pressed():
|
||||||
|
NewScript.startGame()
|
||||||
get_tree().change_scene_to_file("res://TmAP.tscn")
|
get_tree().change_scene_to_file("res://TmAP.tscn")
|
||||||
|
|
||||||
func _on_quit_pressed():
|
func _on_quit_pressed():
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_high_pressed():
|
||||||
|
NewScript.getHigh()
|
||||||
|
|
40
TileMap.gd
40
TileMap.gd
|
@ -1,8 +1,8 @@
|
||||||
extends TileMap
|
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()
|
var rng = RandomNumberGenerator.new()
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
|
@ -10,41 +10,39 @@ func _ready():
|
||||||
|
|
||||||
#return random int
|
#return random int
|
||||||
func roller():
|
func roller():
|
||||||
var rum = rng.randi_range(0, 200)
|
var rum :int = rng.randi_range(0, 200)
|
||||||
var randomHouse = rng.randi_range(5,10)
|
var randomHouse :int = rng.randi_range(5,10)
|
||||||
var randomPower = rng.randi_range(2,8)
|
var randomPower :int = rng.randi_range(2,8)
|
||||||
var randomGap = rng.randi_range(1,20)
|
var randomGap :int = rng.randi_range(1,15)
|
||||||
var randomSet = [rum, randomHouse,randomPower,randomGap]
|
var randomSet :Array = [rum, randomHouse,randomPower,randomGap]
|
||||||
return randomSet
|
return randomSet
|
||||||
|
|
||||||
#draws the ground, houses and powerups
|
#draws the ground, houses and powerups
|
||||||
func drawPat(playerPos):
|
func drawPat(playerPost :Vector2):
|
||||||
var tilePos = Vector2i(playerPos.x+(36),11)
|
var tilePos = Vector2(playerPost.x+(36),11)
|
||||||
var tileCheck = tilePos + Vector2i(1,1)
|
var tileCheck = tilePos + Vector2(1,1)
|
||||||
var rum = roller()
|
var rum = roller()
|
||||||
|
|
||||||
if get_cell_tile_data(0,tileCheck,false) == null:
|
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 int(playerPos.x) % 3 == 0:
|
||||||
if rum[0] > 180:
|
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 int(playerPos.x) % 7 == 0:
|
||||||
if rum[0] > 180:
|
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
|
#removes old tiles
|
||||||
func garbageCollect(playerPos):
|
func garbageCollect(playerPost :Vector2):
|
||||||
for dist in get_used_cells(0):
|
for dist in get_used_cells(0):
|
||||||
if playerPos.x-dist.x > 0:
|
if playerPost.x-dist.x > 100:
|
||||||
if sqrt((playerPos.x-dist.x) ** 2 + (playerPos.y - dist.y)**2) > 200:
|
erase_cell(0, dist)
|
||||||
erase_cell(0, dist)
|
|
||||||
for dist in get_used_cells(1):
|
for dist in get_used_cells(1):
|
||||||
if playerPos.x-dist.x > 0:
|
if playerPost.x-dist.x > 100:
|
||||||
if sqrt((playerPos.x-dist.x) ** 2 + (playerPos.y - dist.y)**2) > 200:
|
erase_cell(1, dist)
|
||||||
erase_cell(1, dist)
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# 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)
|
playerPos = self.local_to_map(player.position)
|
||||||
if playerPos.y > 15:
|
if playerPos.y > 15:
|
||||||
NewScript.playerDeath()
|
NewScript.playerDeath()
|
||||||
|
|
|
@ -49,4 +49,5 @@ offset_bottom = 336.0
|
||||||
text = "Quit Game"
|
text = "Quit Game"
|
||||||
|
|
||||||
[connection signal="pressed" from="Start" to="Control" method="_on_start_pressed"]
|
[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"]
|
[connection signal="pressed" from="Quit" to="Control" method="_on_quit_pressed"]
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
var savePath :String ="user://user.save"
|
||||||
|
|
||||||
var score= 0
|
var score :int = 0
|
||||||
|
var highScores : Array = [0]
|
||||||
|
|
||||||
func playerPoScore():
|
func playerPoScore():
|
||||||
score += 1
|
score += 1
|
||||||
|
@ -11,5 +13,31 @@ func hit(data):
|
||||||
elif data == "power":
|
elif data == "power":
|
||||||
score += 30
|
score += 30
|
||||||
|
|
||||||
func playerDeath():
|
|
||||||
|
func startGame():
|
||||||
score = 0
|
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)
|
||||||
|
|
10
player.gd
10
player.gd
|
@ -1,8 +1,8 @@
|
||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
const speed = 190.0
|
const speed :float = 190.0
|
||||||
const JUMP_VELOCITY = -400.0
|
const JUMP_VELOCITY :float = -400.0
|
||||||
const accel = 1.0071
|
const accel :float = 1.0071
|
||||||
const strength= 3.5
|
const strength :float = 3.5
|
||||||
|
|
||||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||||
|
@ -18,7 +18,7 @@ func get_input():
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
var playerInput = get_input()
|
var playerInput = get_input()
|
||||||
|
|
||||||
# Add the gravity.
|
# Add the Gravity.
|
||||||
if not is_on_floor():
|
if not is_on_floor():
|
||||||
velocity.y += gravity * delta* 3
|
velocity.y += gravity * delta* 3
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ config_version=5
|
||||||
|
|
||||||
config/name="Testrun"
|
config/name="Testrun"
|
||||||
run/main_scene="res://mainMenu.tscn"
|
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/features=PackedStringArray("4.2", "Forward Plus")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue