diff --git a/clicky-clicker/game.gd b/clicky-clicker/game.gd index ba91dd5..b867aa9 100644 --- a/clicky-clicker/game.gd +++ b/clicky-clicker/game.gd @@ -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") @@ -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): diff --git a/clicky-clicker/game.tscn b/clicky-clicker/game.tscn index 85411ce..92d504a 100644 --- a/clicky-clicker/game.tscn +++ b/clicky-clicker/game.tscn @@ -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) @@ -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