1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-24 17:14:23 +00:00

Add GoldCounter

This commit is contained in:
Steffo 2024-04-24 04:55:31 +02:00
parent a3a5503c17
commit f8f9fa6984
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
7 changed files with 101 additions and 4 deletions

View file

@ -15,7 +15,6 @@ radius = 96.0
[node name="Gold" type="Node2D"]
script = ExtResource("1_lbls1")
speed_up_factor = 8.0
[node name="Collectible" parent="." instance=ExtResource("2_j75yq")]
unique_name_in_owner = true

View file

@ -8,12 +8,13 @@ signal dragged(node: Draggable)
signal dropped(node: Draggable)
@onready var game := MainGame.get_via_group(self)
@onready var game: MainGame = MainGame.get_via_group(self)
@onready var gold_counter: GoldCounter = %"GoldCounter"
var dragging: Draggable = null
static func get_via_group(node: Node) -> MainGame:
static func get_via_group(node: Node) -> Cursor:
var result = node.get_tree().get_nodes_in_group("cursor")
if result.is_empty():
return null

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://col1q3elvkfwk"]
[gd_scene load_steps=4 format=3 uid="uid://col1q3elvkfwk"]
[ext_resource type="Script" path="res://scenes/game/cursor.gd" id="1_1og6v"]
[ext_resource type="PackedScene" uid="uid://cu750c7yd57qa" path="res://scenes/game/gold_counter.tscn" id="2_ofjhi"]
[sub_resource type="CircleShape2D" id="CircleShape2D_j2mj5"]
radius = 4.0
@ -14,3 +15,6 @@ script = ExtResource("1_1og6v")
[node name="Shape" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_j2mj5")
debug_color = Color(1, 1, 1, 1)
[node name="GoldCounter" parent="." instance=ExtResource("2_ofjhi")]
unique_name_in_owner = true

View file

@ -0,0 +1,16 @@
extends PanelContainer
class_name GoldCounter
@onready var label: Label = %"Label"
@onready var animator: AnimationPlayer = %"Animator"
func set_text(value: int) -> void:
label.text = "%d" % value
func display(value: int):
set_text(value)
animator.stop()
animator.play(&"collect")

View file

@ -0,0 +1,69 @@
[gd_scene load_steps=6 format=3 uid="uid://cu750c7yd57qa"]
[ext_resource type="Script" path="res://scenes/game/gold_counter.gd" id="1_koxhc"]
[sub_resource type="Animation" id="Animation_3gb4u"]
resource_name = "RESET"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(1, 1)]
}
[sub_resource type="Animation" id="Animation_8n0bl"]
resource_name = "collect"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector2(1.5, 1.5), Vector2(1, 1)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_bj0k7"]
_data = {
"RESET": SubResource("Animation_3gb4u"),
"collect": SubResource("Animation_8n0bl")
}
[sub_resource type="LabelSettings" id="LabelSettings_1jb4h"]
[node name="GoldCounter" type="PanelContainer"]
offset_left = 16.0
offset_top = 24.0
offset_right = 56.0
offset_bottom = 51.0
script = ExtResource("1_koxhc")
[node name="Animator" type="AnimationPlayer" parent="."]
unique_name_in_owner = true
libraries = {
"": SubResource("AnimationLibrary_bj0k7")
}
next/RESET = &"RESET"
[node name="Margin" type="MarginContainer" parent="."]
layout_mode = 2
theme_override_constants/margin_left = 2
theme_override_constants/margin_top = 2
theme_override_constants/margin_right = 2
theme_override_constants/margin_bottom = 2
[node name="Label" type="Label" parent="Margin"]
unique_name_in_owner = true
layout_mode = 2
text = "0 €"
label_settings = SubResource("LabelSettings_1jb4h")
horizontal_alignment = 2

View file

@ -5,6 +5,7 @@ class_name MainGame
@onready var camera: GameCamera = $"GameCamera"
@onready var default_spawn_parent: Node2D = %"DefaultSpawnParent"
@onready var inventory: Inventory = %"Inventory"
@onready var cursor: Cursor = %"Cursor"
static func get_via_group(node: Node) -> MainGame:
@ -12,3 +13,9 @@ static func get_via_group(node: Node) -> MainGame:
if result.is_empty():
return null
return result[0]
func _ready():
var gold_counter = inventory.get_counter(&"Gold")
gold_counter.changed.connect(cursor.gold_counter.display.unbind(1))
cursor.gold_counter.set_text(gold_counter.value)

View file

@ -831,6 +831,7 @@ layer_0/tile_data = PackedInt32Array(720915, 196608, 9, 655379, 65536, 10, 58984
[node name="GameCamera" parent="." instance=ExtResource("2_db5xs")]
[node name="Cursor" parent="." instance=ExtResource("5_g504x")]
unique_name_in_owner = true
[node name="Walls" type="Node2D" parent="."]