improve coin counter HUD

This commit is contained in:
Chris Cromer 2022-09-01 18:34:37 -04:00
parent 2818e210c9
commit 3ca5f4e7b2
Signed by: cromer
GPG Key ID: FA91071797BEEEC2
4 changed files with 37 additions and 27 deletions

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=8 format=2]
[ext_resource path="res://assets/coin.png" type="Texture" id=1]
[ext_resource path="res://hud/coin/Counter.gdns" type="Script" id=2]
[ext_resource path="res://hud/coin/CoinCounter.gdns" type="Script" id=2]
[ext_resource path="res://hud/CoinHUD.gd" type="Script" id=3]
[sub_resource type="StyleBoxFlat" id=1]
@ -28,31 +28,34 @@ pause_mode = 2
script = ExtResource( 3 )
[node name="Panel" type="Panel" parent="."]
margin_left = 144.0
margin_top = 18.0
margin_right = 288.0
margin_bottom = 54.0
anchor_left = 0.5
anchor_right = 0.5
margin_left = -44.5
margin_top = 5.0
margin_right = 44.5
margin_bottom = 25.0
custom_styles/panel = SubResource( 1 )
[node name="Label" type="Label" parent="."]
margin_left = 180.0
margin_top = 18.0
margin_right = 220.0
margin_bottom = 36.0
[node name="X" type="Label" parent="Panel"]
margin_left = 40.0
margin_top = 4.0
margin_right = 53.0
margin_bottom = 24.0
text = "X"
[node name="Coins" type="Label" parent="."]
margin_left = 198.0
margin_top = 18.0
margin_right = 238.0
margin_bottom = 32.0
[node name="Coins" type="Label" parent="Panel"]
anchor_left = 0.5
anchor_right = 0.5
margin_left = 13.5
margin_top = 4.0
margin_right = 36.0
margin_bottom = 18.0
text = "##"
script = ExtResource( 2 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
position = Vector2( 162, 18 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="Panel"]
position = Vector2( 12, 1 )
frames = SubResource( 4 )
animation = "spin"
frame = 1
playing = true
centered = false

View File

@ -55,5 +55,3 @@ position = Vector2( 72, 450 )
position = Vector2( 234, 450 )
[node name="Goal" parent="." instance=ExtResource( 8 )]
[editable path="Coins/coin"]

View File

@ -23,15 +23,24 @@ void alai::CoinCounter::_init()
coins = 0;
}
void alai::CoinCounter::_on_coin_collected(int amount)
{
coins = coins + amount;
set_text(godot::String::num(coins));
}
void alai::CoinCounter::_ready()
{
set_text("0");
set_text("00");
auto event = get_node<alai::Event>("/root/Event");
event->connect("coin_collected", this, "_on_coin_collected");
}
void alai::CoinCounter::_on_coin_collected(int amount)
{
coins = coins + amount;
godot::String coin_string = godot::String();
if (coins <= 9)
{
coin_string = "0" + godot::String::num(coins);
}
else{
coin_string = godot::String::num(coins);
}
set_text(coin_string);
}