From 9254faaa1140aebdfb07714fa92c9de75f42f443 Mon Sep 17 00:00:00 2001 From: Kilokem Date: Fri, 25 Oct 2024 18:46:17 +0200 Subject: [PATCH] Texts and coin counter --- scenes/game.tscn | 61 ++++++++++++++++++++++++++++++++++++----- scripts/coin.gd | 3 +- scripts/game_manager.gd | 19 +++++++++++++ 3 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 scripts/game_manager.gd diff --git a/scenes/game.tscn b/scenes/game.tscn index be4709b..189f9b2 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,11 +1,13 @@ -[gd_scene load_steps=13 format=4 uid="uid://ddx678te8glnm"] +[gd_scene load_steps=15 format=4 uid="uid://ddx678te8glnm"] [ext_resource type="PackedScene" uid="uid://cxdkngh6fo5p7" path="res://scenes/player.tscn" id="1_866nb"] +[ext_resource type="Script" path="res://scripts/game_manager.gd" id="1_clwrx"] [ext_resource type="Texture2D" uid="uid://dcqrtadm8khs6" path="res://assets/sprites/world_tileset.png" id="2_xrfdw"] [ext_resource type="PackedScene" uid="uid://c54bhvh3awmhl" path="res://scenes/platform.tscn" id="3_3twsu"] [ext_resource type="PackedScene" uid="uid://dbjp33ljlh1vh" path="res://scenes/coin.tscn" id="4_ydnys"] [ext_resource type="PackedScene" uid="uid://cxkr1ot3mkts1" path="res://scenes/killzone.tscn" id="5_sa1lr"] [ext_resource type="PackedScene" uid="uid://btfpng5d31b83" path="res://scenes/slime.tscn" id="6_solsf"] +[ext_resource type="FontFile" uid="uid://fw4vwtwjmcu" path="res://assets/fonts/PixelOperator8.ttf" id="7_jqhk7"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_gsgsl"] texture = ExtResource("2_xrfdw") @@ -216,6 +218,22 @@ distance = 11.0 [node name="Game" type="Node2D"] +[node name="GameManager" type="Node" parent="."] +unique_name_in_owner = true +script = ExtResource("1_clwrx") + +[node name="Label" type="Label" parent="GameManager"] +offset_left = 1453.0 +offset_top = -65.0 +offset_right = 1512.0 +offset_bottom = -54.0 +scale = Vector2(1, 1.12) +theme_override_fonts/font = ExtResource("7_jqhk7") +theme_override_font_sizes/font_size = 8 +text = "Coins: " +vertical_alignment = 3 +autowrap_mode = 2 + [node name="AnimatableBody2D" parent="." instance=ExtResource("3_3twsu")] position = Vector2(-12, -59) @@ -279,14 +297,43 @@ position = Vector2(-40, 8) [node name="Coin7" parent="Coins" instance=ExtResource("4_ydnys")] position = Vector2(524, 66) -[node name="Coin8" parent="Coins" instance=ExtResource("4_ydnys")] -position = Vector2(744, 41) - -[node name="Coin9" parent="Coins" instance=ExtResource("4_ydnys")] -position = Vector2(1424, -61) - [node name="Coin10" parent="Coins" instance=ExtResource("4_ydnys")] position = Vector2(1288, -24) [node name="slime" parent="." instance=ExtResource("6_solsf")] position = Vector2(556, 68) + +[node name="labels" type="Node" parent="."] + +[node name="Label" type="Label" parent="labels"] +offset_left = -182.0 +offset_top = -65.0 +offset_right = -33.0 +offset_bottom = -24.0 +scale = Vector2(1, 1.12) +theme_override_fonts/font = ExtResource("7_jqhk7") +theme_override_font_sizes/font_size = 8 +text = "To jump press \"space\", \"w\" or \"upp arrow\" whatewer you feel like!" +vertical_alignment = 3 +autowrap_mode = 2 + +[node name="Label2" type="Label" parent="labels"] +offset_left = 508.0 +offset_top = -98.0 +offset_right = 655.0 +offset_bottom = -76.0 +scale = Vector2(1, 1.12) +theme_override_fonts/font = ExtResource("7_jqhk7") +theme_override_font_sizes/font_size = 8 +text = "Just jump already! +" + +[node name="Label3" type="Label" parent="labels"] +offset_left = 1384.0 +offset_top = -155.0 +offset_right = 1531.0 +offset_bottom = -133.0 +scale = Vector2(1, 1.12) +theme_override_fonts/font = ExtResource("7_jqhk7") +theme_override_font_sizes/font_size = 8 +text = "Made with <3 by Kilokem" diff --git a/scripts/coin.gd b/scripts/coin.gd index ec0f714..0c8bc63 100644 --- a/scripts/coin.gd +++ b/scripts/coin.gd @@ -1,7 +1,8 @@ extends Area2D +@onready var game_manager: Node = %GameManager func _on_body_entered(body: Node2D) -> void: - print("+1 coin!!") + game_manager.add_point() queue_free() diff --git a/scripts/game_manager.gd b/scripts/game_manager.gd new file mode 100644 index 0000000..c61d988 --- /dev/null +++ b/scripts/game_manager.gd @@ -0,0 +1,19 @@ +extends Node + +var score = 0 + +@onready var label: Label = $Label + + +func add_point(): + score += 1 + label.text = "Coins: " + str(score) + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass