Skip to content

Commit

Permalink
Adding a bit more tracking stuff to the screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
nanodeath committed Jul 9, 2024
1 parent 1f702a1 commit 6d8fb94
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
18 changes: 16 additions & 2 deletions clicky-clicker/game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ class_name Game extends Control
@export_range(1, 30) var ball_lifetime: float

@onready var click_button: Button = $VBoxContainer/ClickButton
@onready var counter_label: RichTextLabel = $VBoxContainer/CounterLabel
@onready var counter_label: RichTextLabel = $VBoxContainer/TotalCounterLabel
@onready var current_counter_label = $VBoxContainer/CurrentCounterLabel

var ball_count := 0
var maximum_ball_count := 0

const BALL = preload("res://ball.tscn")

Expand Down Expand Up @@ -38,8 +42,18 @@ func _button_pressed():
var tween = get_tree().create_tween()
var color := Color(randf(), randf(), randf(), 0)
tween.tween_property(ball, "modulate", color, 1)
tween.tween_callback(func(): ball.queue_free())
tween.tween_callback(func():
ball.queue_free()
ball_count -= 1
_update_current_ball_count()
)
)
ball_count += 1
maximum_ball_count = max(maximum_ball_count, ball_count)
_update_current_ball_count()

func _update_current_ball_count():
current_counter_label.text = str(ball_count) + "/" + str(maximum_ball_count)

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
Expand Down
14 changes: 12 additions & 2 deletions clicky-clicker/game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_objr7")
ball_lifetime = 20.0
ball_lifetime = 10.0

[node name="VBoxContainer" type="VBoxContainer" parent="."]
custom_minimum_size = Vector2(400, 400)
Expand All @@ -76,14 +76,24 @@ grow_horizontal = 2
grow_vertical = 2
theme_override_constants/separation = 20

[node name="CurrentCounterLabel" type="RichTextLabel" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
tooltip_text = "Current and maximum number of Godots on the screen."
theme_override_font_sizes/normal_font_size = 24
text = "0"
fit_content = true
autowrap_mode = 0

[node name="ClickButton" type="Button" parent="VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 200
text = "Click!"

[node name="CounterLabel" type="RichTextLabel" parent="VBoxContainer"]
[node name="TotalCounterLabel" type="RichTextLabel" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
tooltip_text = "Total clicks"
text = "0"
fit_content = true
autowrap_mode = 0
Expand Down

0 comments on commit 6d8fb94

Please sign in to comment.