mirror of
https://codeberg.org/Melon-Bread/Comets.gd.git
synced 2024-11-24 21:18:21 -05:00
Added a High Score system
This commit is contained in:
parent
4a090f0d3d
commit
31f6939296
@ -27,6 +27,20 @@ theme_override_font_sizes/font_size = 32
|
||||
text = "LEVEL: 1"
|
||||
horizontal_alignment = 2
|
||||
|
||||
[node name="HighScore" type="Label" parent="UI"]
|
||||
anchors_preset = 5
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
offset_left = -96.0
|
||||
offset_right = 96.0
|
||||
offset_bottom = 39.0
|
||||
grow_horizontal = 2
|
||||
theme_override_fonts/font = ExtResource("2_gwtm0")
|
||||
theme_override_font_sizes/font_size = 18
|
||||
text = "HIGH SCORE:
|
||||
0"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="GameOverScreen" parent="UI" instance=ExtResource("3_yy075")]
|
||||
visible = false
|
||||
|
||||
|
@ -1,17 +1,20 @@
|
||||
extends Node2D
|
||||
|
||||
# TODO: MAYBE track high score in a file & show it on HUD
|
||||
# TODO: MAYBE make ufo enemey that randomly flies in from ones sode to the other
|
||||
|
||||
const COMET_SPAWNER = preload("res://scenes/comet_spawner.tscn")
|
||||
|
||||
@export var level : int = 1
|
||||
|
||||
var save_file := "user://highscore.dat"
|
||||
|
||||
var viewport_size : Vector2
|
||||
var score : int = 0
|
||||
var high_score : int
|
||||
var points_per_comet := 300
|
||||
|
||||
func _ready() -> void:
|
||||
high_score = load_score()
|
||||
new_level(level)
|
||||
viewport_size = get_viewport_rect().size
|
||||
$Background/Stars.emission_rect_extents = viewport_size
|
||||
@ -34,6 +37,8 @@ func game_over() -> void:
|
||||
# Wait 1 second before showing the game over screen for "dramatic" effect
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
$UI/GameOverScreen.visible = true
|
||||
if score > high_score:
|
||||
save_score()
|
||||
|
||||
func increase_score(comet_size : int) -> void:
|
||||
# We add one since comet_size starts count at 0
|
||||
@ -44,6 +49,17 @@ func update_ui()-> void:
|
||||
# Label strings must be all caps for font to render proper
|
||||
$UI/Score.text = "SCORE: " + str(score)
|
||||
$UI/Level.text = "LEVEL: " + str(level)
|
||||
|
||||
$UI/HighScore.text = "HIGH SCORE:\n" + str(high_score)
|
||||
|
||||
func save_score() -> void:
|
||||
var file := FileAccess.open(save_file, FileAccess.WRITE)
|
||||
file.store_var(score)
|
||||
|
||||
func load_score() -> int:
|
||||
if FileAccess.file_exists(save_file):
|
||||
var file := FileAccess.open(save_file, FileAccess.READ)
|
||||
return file.get_var(score)
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user