extends Node2D # TODO: Make a small title screen that starts before the game scene # TODO: MAYBE track high score in a file & show it on HUD const COMET_SPAWNER = preload("res://scenes/comet_spawner.tscn") @export var level : int = 1 var viewport_size : Vector2 var score : int = 0 var points_per_comet := 300 func _ready() -> void: new_level(level) viewport_size = get_viewport_rect().size $Background/Stars.emission_rect_extents = viewport_size func _process(_delta: float) -> void: update_ui() func new_level(current_level : int) -> void: var comet_spawner := COMET_SPAWNER.instantiate() comet_spawner.comet_count *= current_level comet_spawner.comet_shot.connect(increase_score) comet_spawner.screen_cleared.connect(level_finished) self.add_child(comet_spawner) func level_finished() -> void: level += 1 new_level(level) 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 # TODO: Set focus on one of the buttons once the game over screen when shown func increase_score(comet_size : int) -> void: # We add one since comet_size starts count at 0 comet_size += 1 score += points_per_comet / comet_size 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)