From a3d1e2cd52502d681f4c83689d833b39f43aa53f Mon Sep 17 00:00:00 2001 From: Melon Bread Date: Sun, 12 May 2024 22:42:28 -0400 Subject: [PATCH] Made a basic game UI and started fleshing out game states --- scenes/game.tscn | 40 +++++++++++++++++++++++++--------------- scripts/game.gd | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 scripts/game.gd diff --git a/scenes/game.tscn b/scenes/game.tscn index 00253ed..dec387a 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,12 +1,31 @@ -[gd_scene load_steps=4 format=3 uid="uid://bdarunpk3c2eh"] +[gd_scene load_steps=5 format=3 uid="uid://bdarunpk3c2eh"] -[ext_resource type="Script" path="res://scenes/game.gd" id="1_6727i"] +[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="PackedScene" uid="uid://bsonrs8vhtly8" path="res://scenes/comet.tscn" id="2_b37uv"] +[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") +[node name="UI" type="CanvasLayer" parent="."] + +[node name="Score" type="Label" parent="UI"] +offset_right = 40.0 +offset_bottom = 23.0 +theme_override_fonts/font = ExtResource("2_gwtm0") +theme_override_font_sizes/font_size = 32 +text = "SCORE: 0" + +[node name="Level" type="Label" parent="UI"] +offset_left = 908.0 +offset_right = 1148.0 +offset_bottom = 45.0 +theme_override_fonts/font = ExtResource("2_gwtm0") +theme_override_font_sizes/font_size = 32 +text = "LEVEL: 1" +horizontal_alignment = 2 + [node name="Background" type="CanvasLayer" parent="."] layer = -1 @@ -23,16 +42,7 @@ color = Color(0, 0, 0, 1) z_index = 1 position = Vector2(622, 309) -[node name="Comet" parent="." instance=ExtResource("2_b37uv")] -position = Vector2(276, 249) -current_size = 1 +[node name="CometSpawner" parent="." instance=ExtResource("3_gh4tl")] -[node name="Comet2" parent="." instance=ExtResource("2_b37uv")] -position = Vector2(439, 459) - -[node name="Comet3" parent="." instance=ExtResource("2_b37uv")] -position = Vector2(834, 136) -current_size = 0 - -[node name="Comet4" parent="." instance=ExtResource("2_b37uv")] -position = Vector2(938, 402) +[connection signal="crashed" from="Ship" to="." method="game_over"] +[connection signal="comet_shot" from="CometSpawner" to="." method="increase_score"] diff --git a/scripts/game.gd b/scripts/game.gd new file mode 100644 index 0000000..9f87f8a --- /dev/null +++ b/scripts/game.gd @@ -0,0 +1,34 @@ +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 + +var points_per_comet := 300 + +func _ready() -> void: + pass + +func _process(_delta: float) -> void: + update_ui() + +func new_level(current_level : int) -> void: + pass + +func game_over() -> void: + pass + +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)