From 87bbaafb75e3de132f51ac8c0dc21163da8f7ea7 Mon Sep 17 00:00:00 2001 From: Thepuppetqueen57 Date: Thu, 28 Aug 2025 23:48:06 -0700 Subject: [PATCH] Added a score system --- Scenes/Game.tscn | 50 +++++++++++++++++++++++++++++++++++++++- Scripts/BerryLogic.cs | 5 ++++ Scripts/Globals.cs | 3 +++ Scripts/ScoreText.cs | 12 ++++++++++ Scripts/ScoreText.cs.uid | 1 + 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 Scripts/ScoreText.cs create mode 100644 Scripts/ScoreText.cs.uid diff --git a/Scenes/Game.tscn b/Scenes/Game.tscn index 7767490..cf8c5e1 100644 --- a/Scenes/Game.tscn +++ b/Scenes/Game.tscn @@ -1,8 +1,10 @@ -[gd_scene load_steps=5 format=3 uid="uid://bgt46l5p8qrwc"] +[gd_scene load_steps=7 format=3 uid="uid://bgt46l5p8qrwc"] [ext_resource type="Script" uid="uid://dfv3cmvcskd6t" path="res://Scripts/Player.cs" id="1_gl6un"] [ext_resource type="Texture2D" uid="uid://5ecdlqnn0u6g" path="res://Textures/Icons/Bird1.png" id="1_iukft"] [ext_resource type="Script" uid="uid://bdwdadvx0axam" path="res://Scripts/Berries.cs" id="1_kldst"] +[ext_resource type="Script" uid="uid://drbmu7lilwrec" path="res://Scripts/ScoreText.cs" id="4_b2bpf"] +[ext_resource type="FontFile" uid="uid://dq7nkk7n7wrq4" path="res://Fonts/Lexend.ttf" id="4_kldst"] [sub_resource type="CircleShape2D" id="CircleShape2D_j5yw3"] radius = 117.004 @@ -30,3 +32,49 @@ position = Vector2(-5, 23) [node name="CollisionShape2D" type="CollisionShape2D" parent="Player/Hitbox"] shape = SubResource("CircleShape2D_j5yw3") debug_color = Color(1, 1, 1, 0.188235) + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="ScoreText" type="Control" parent="CanvasLayer"] +layout_mode = 3 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -20.0 +offset_right = 20.0 +offset_bottom = 40.0 +grow_horizontal = 2 +script = ExtResource("4_b2bpf") + +[node name="ScoreLabel" type="Label" parent="CanvasLayer/ScoreText"] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -228.0 +offset_right = 720.0 +offset_bottom = 308.0 +grow_horizontal = 2 +scale = Vector2(0.48, 0.48) +theme_override_fonts/font = ExtResource("4_kldst") +theme_override_font_sizes/font_size = 246 +text = "Score: 0" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="HighScoreLabel" type="Label" parent="CanvasLayer/ScoreText"] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -257.0 +offset_top = 148.0 +offset_right = 812.0 +offset_bottom = 361.0 +grow_horizontal = 2 +scale = Vector2(0.48, 0.48) +theme_override_fonts/font = ExtResource("4_kldst") +theme_override_font_sizes/font_size = 156 +text = "High Score: 0" +horizontal_alignment = 1 +vertical_alignment = 1 diff --git a/Scripts/BerryLogic.cs b/Scripts/BerryLogic.cs index 6b80004..6bb1bd3 100644 --- a/Scripts/BerryLogic.cs +++ b/Scripts/BerryLogic.cs @@ -3,6 +3,11 @@ using System; public partial class BerryLogic : Node2D { private void _on_hitbox_area_entered(Area2D area) { + Globals.Score += 1; + if (Globals.Score > Globals.HighScore) { + Globals.HighScore += 1; + } + QueueFree(); } } diff --git a/Scripts/Globals.cs b/Scripts/Globals.cs index 8cbd501..ac0667d 100644 --- a/Scripts/Globals.cs +++ b/Scripts/Globals.cs @@ -5,4 +5,7 @@ public partial class Globals : Node { public static string LatestVersion = ""; public static string AccessLevel = ""; public static bool VersionChecked = false; + + public static int Score = 0; + public static int HighScore = 0; } diff --git a/Scripts/ScoreText.cs b/Scripts/ScoreText.cs new file mode 100644 index 0000000..6acf8fc --- /dev/null +++ b/Scripts/ScoreText.cs @@ -0,0 +1,12 @@ +using Godot; +using System; + +public partial class ScoreText : Control { + public override void _Process(double delta) { + Label ScoreText = GetNode