Ver código fonte

Add number of balls

DricomDragon 3 anos atrás
pai
commit
38ad2198e0

+ 20 - 1
godot/scenes/main.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=14 format=2]
+[gd_scene load_steps=15 format=2]
 
 [ext_resource path="res://image/launcher.png" type="Texture" id=1]
 [ext_resource path="res://image/brik.png" type="Texture" id=2]
@@ -7,6 +7,7 @@
 [ext_resource path="res://image/visor.png" type="Texture" id=5]
 [ext_resource path="res://scripts/Grid.gd" type="Script" id=6]
 [ext_resource path="res://scripts/UI.gd" type="Script" id=7]
+[ext_resource path="res://scripts/BallCounterLabel.gd" type="Script" id=8]
 
 [sub_resource type="PhysicsMaterial" id=1]
 friction = 0.0
@@ -129,8 +130,26 @@ margin_bottom = 225.0
 text = "Game Over"
 align = 1
 valign = 1
+
+[node name="BallCounterPanel" type="Panel" parent="UI"]
+margin_left = 10.0
+margin_top = 370.0
+margin_right = 50.0
+margin_bottom = 390.0
+
+[node name="BallCounterLabel" type="Label" parent="UI/BallCounterPanel"]
+margin_right = 40.0
+margin_bottom = 20.0
+text = "Balls"
+align = 1
+valign = 1
+script = ExtResource( 8 )
+__meta__ = {
+"_edit_use_anchors_": false
+}
 [connection signal="body_entered" from="Catcher" to="Catcher" method="_on_Catcher_body_entered"]
 [connection signal="game_over" from="Catcher" to="UI" method="_on_Catcher_game_over"]
+[connection signal="gain_new_bullet" from="Launcher" to="UI/BallCounterPanel/BallCounterLabel" method="_on_Launcher_gain_new_bullet"]
 [connection signal="get_firing" from="Launcher" to="Launcher" method="_on_Launcher_get_firing"]
 [connection signal="is_full" from="Launcher" to="Launcher/Grid" method="_on_Launcher_is_full"]
 [connection signal="has_moved" from="Launcher/Grid" to="Launcher" method="_on_Grid_has_moved"]

+ 17 - 0
godot/scripts/BallCounterLabel.gd

@@ -0,0 +1,17 @@
+extends Label
+
+
+var nb_bullet = 0
+
+
+func _ready():
+	gain_new_bullet()
+
+
+func gain_new_bullet():
+	nb_bullet += 1
+	text = str(nb_bullet)
+
+
+func _on_Launcher_gain_new_bullet():
+	gain_new_bullet()

+ 7 - 1
godot/scripts/Launcher.gd

@@ -2,6 +2,7 @@ extends Node2D
 
 signal get_firing
 signal is_full
+signal gain_new_bullet
 
 enum State {
 	READY,
@@ -50,6 +51,11 @@ func shoot():
 		bullet.connect("kace_contact", grid, "_on_Ball_kace_contact")
 
 
+func gain_new_bullet():
+	load_bullet(1)
+	emit_signal("gain_new_bullet")
+
+
 func load_bullet(n:int):
 	nbStorage += n
 
@@ -85,4 +91,4 @@ func _on_Grid_has_moved():
 
 
 func _on_Grid_kace_broken():
-	load_bullet(1)
+	gain_new_bullet()