From 6c32b12a3cc8db11ff0d8f2cb254b1829dcd41d2 Mon Sep 17 00:00:00 2001 From: Melon Bread Date: Mon, 13 May 2024 08:15:21 -0400 Subject: [PATCH] Game now have a level system. --- scenes/game.tscn | 6 +----- scripts/comet_spawner.gd | 3 ++- scripts/game.gd | 19 ++++++++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/scenes/game.tscn b/scenes/game.tscn index dec387a..c6b5b39 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=5 format=3 uid="uid://bdarunpk3c2eh"] +[gd_scene load_steps=4 format=3 uid="uid://bdarunpk3c2eh"] [ext_resource type="Script" path="res://scripts/game.gd" id="1_6727i"] [ext_resource type="PackedScene" uid="uid://cbo47ftx0vcro" path="res://scenes/ship.tscn" id="1_esyqo"] [ext_resource type="FontFile" uid="uid://bkcxbtx1vcj8w" path="res://assets/fonts/Color Basic.otf" id="2_gwtm0"] -[ext_resource type="PackedScene" uid="uid://6c6g7e5v3ifr" path="res://scenes/comet_spawner.tscn" id="3_gh4tl"] [node name="Game" type="Node2D"] script = ExtResource("1_6727i") @@ -42,7 +41,4 @@ color = Color(0, 0, 0, 1) z_index = 1 position = Vector2(622, 309) -[node name="CometSpawner" parent="." instance=ExtResource("3_gh4tl")] - [connection signal="crashed" from="Ship" to="." method="game_over"] -[connection signal="comet_shot" from="CometSpawner" to="." method="increase_score"] diff --git a/scripts/comet_spawner.gd b/scripts/comet_spawner.gd index 6a5910e..a256f30 100644 --- a/scripts/comet_spawner.gd +++ b/scripts/comet_spawner.gd @@ -14,12 +14,13 @@ func _ready() -> void: for comet in range(comet_count): random_position.x = randf_range(viewport_size.x - 100, viewport_size.x) random_position.y = randf_range(viewport_size.y - 100, viewport_size.y) - spawn_comet(0, random_position) + spawn_comet(2, random_position) func _process(_delta: float) -> void: viewport_size = get_viewport_rect().size if $Comets.get_child_count() <= 0: screen_cleared.emit() + queue_free() func spawn_comet(size : int, pos : Vector2) -> void: diff --git a/scripts/game.gd b/scripts/game.gd index 9f87f8a..8c35064 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -1,24 +1,33 @@ extends Node2D # TODO: Display a game over screen when the ship is hit by a comet with abilty to restart -# TODO: Detect when all comets are gone and increase the level (& maybe speed?) # TODO: Make a space like background, maybe some scrolling, maybe randomly generated # TODO: Make a small title screen that starts before the game scene # TODO: MAYBE track high score in a file & show it on HUD -@export var level : int = 1 -var score : int = 0 +const COMET_SPAWNER = preload("res://scenes/comet_spawner.tscn") +@export var level : int = 1 + +var score : int = 0 var points_per_comet := 300 func _ready() -> void: - pass + new_level(level) func _process(_delta: float) -> void: update_ui() func new_level(current_level : int) -> void: - pass + 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: pass