Merge pull request 'improve coin counter HUD' (#46) from feature/cleanup_coin_counter into develop
Reviewed-on: #46
This commit is contained in:
commit
615b2a0ba2
@ -1,7 +1,7 @@
|
|||||||
[gd_scene load_steps=8 format=2]
|
[gd_scene load_steps=8 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://assets/coin.png" type="Texture" id=1]
|
[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]
|
[ext_resource path="res://hud/CoinHUD.gd" type="Script" id=3]
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id=1]
|
[sub_resource type="StyleBoxFlat" id=1]
|
||||||
@ -28,31 +28,34 @@ pause_mode = 2
|
|||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="Panel" type="Panel" parent="."]
|
[node name="Panel" type="Panel" parent="."]
|
||||||
margin_left = 144.0
|
anchor_left = 0.5
|
||||||
margin_top = 18.0
|
anchor_right = 0.5
|
||||||
margin_right = 288.0
|
margin_left = -44.5
|
||||||
margin_bottom = 54.0
|
margin_top = 5.0
|
||||||
|
margin_right = 44.5
|
||||||
|
margin_bottom = 25.0
|
||||||
custom_styles/panel = SubResource( 1 )
|
custom_styles/panel = SubResource( 1 )
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="."]
|
[node name="X" type="Label" parent="Panel"]
|
||||||
margin_left = 180.0
|
margin_left = 40.0
|
||||||
margin_top = 18.0
|
margin_top = 4.0
|
||||||
margin_right = 220.0
|
margin_right = 53.0
|
||||||
margin_bottom = 36.0
|
margin_bottom = 24.0
|
||||||
text = "X"
|
text = "X"
|
||||||
|
|
||||||
[node name="Coins" type="Label" parent="."]
|
[node name="Coins" type="Label" parent="Panel"]
|
||||||
margin_left = 198.0
|
anchor_left = 0.5
|
||||||
margin_top = 18.0
|
anchor_right = 0.5
|
||||||
margin_right = 238.0
|
margin_left = 13.5
|
||||||
margin_bottom = 32.0
|
margin_top = 4.0
|
||||||
|
margin_right = 36.0
|
||||||
|
margin_bottom = 18.0
|
||||||
text = "##"
|
text = "##"
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="Panel"]
|
||||||
position = Vector2( 162, 18 )
|
position = Vector2( 12, 1 )
|
||||||
frames = SubResource( 4 )
|
frames = SubResource( 4 )
|
||||||
animation = "spin"
|
animation = "spin"
|
||||||
frame = 1
|
|
||||||
playing = true
|
playing = true
|
||||||
centered = false
|
centered = false
|
||||||
|
@ -55,5 +55,3 @@ position = Vector2( 72, 450 )
|
|||||||
position = Vector2( 234, 450 )
|
position = Vector2( 234, 450 )
|
||||||
|
|
||||||
[node name="Goal" parent="." instance=ExtResource( 8 )]
|
[node name="Goal" parent="." instance=ExtResource( 8 )]
|
||||||
|
|
||||||
[editable path="Coins/coin"]
|
|
||||||
|
@ -23,15 +23,24 @@ void alai::CoinCounter::_init()
|
|||||||
coins = 0;
|
coins = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::CoinCounter::_on_coin_collected(int amount)
|
|
||||||
{
|
|
||||||
coins = coins + amount;
|
|
||||||
set_text(godot::String::num(coins));
|
|
||||||
}
|
|
||||||
|
|
||||||
void alai::CoinCounter::_ready()
|
void alai::CoinCounter::_ready()
|
||||||
{
|
{
|
||||||
set_text("0");
|
set_text("00");
|
||||||
auto event = get_node<alai::Event>("/root/Event");
|
auto event = get_node<alai::Event>("/root/Event");
|
||||||
event->connect("coin_collected", this, "_on_coin_collected");
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user