Kaynağa Gözat

Add score counter

DricomDragon 3 yıl önce
ebeveyn
işleme
5e6708957e

+ 34 - 1
godot/scenes/main.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=15 format=2]
+[gd_scene load_steps=16 format=2]
 
 [ext_resource path="res://image/launcher.png" type="Texture" id=1]
 [ext_resource path="res://image/brik.png" type="Texture" id=2]
@@ -8,6 +8,7 @@
 [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]
+[ext_resource path="res://scripts/ScoreCounterLabel.gd" type="Script" id=9]
 
 [sub_resource type="PhysicsMaterial" id=1]
 friction = 0.0
@@ -161,6 +162,37 @@ script = ExtResource( 8 )
 __meta__ = {
 "_edit_use_anchors_": false
 }
+
+[node name="ScorePanel" type="Panel" parent="UI"]
+margin_left = 350.0
+margin_top = 360.0
+margin_right = 390.0
+margin_bottom = 390.0
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="ScoreLabel" type="Label" parent="UI/ScorePanel"]
+margin_right = 40.0
+margin_bottom = 14.0
+text = "Score"
+align = 1
+valign = 1
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="ScoreCounterLabel" type="Label" parent="UI/ScorePanel"]
+margin_top = 15.0
+margin_right = 40.0
+margin_bottom = 30.0
+text = "0"
+align = 1
+valign = 1
+script = ExtResource( 9 )
+__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"]
@@ -168,4 +200,5 @@ __meta__ = {
 [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"]
 [connection signal="kace_broken" from="Launcher/Grid" to="Launcher" method="_on_Grid_kace_broken"]
+[connection signal="kace_damaged" from="Launcher/Grid" to="UI/ScorePanel/ScoreCounterLabel" method="_on_Grid_kace_damaged"]
 [connection signal="timeout" from="Launcher/ShootDelay" to="Launcher" method="_on_ShootDelay_timeout"]

+ 2 - 0
godot/scripts/Grid.gd

@@ -1,6 +1,7 @@
 extends TileMap
 
 signal kace_broken
+signal kace_damaged
 signal has_moved
 
 enum Tile {
@@ -45,6 +46,7 @@ func damage_cell(tile_pos : Vector2):
 	var cell_id = get_cellv(tile_pos)
 	if cell_id != TileMap.INVALID_CELL and cell_id == Tile.BRICK:
 		living_cells[tile_pos] -= 1
+		emit_signal("kace_damaged")
 		if living_cells[tile_pos] <= 0:
 			break_cell(tile_pos)
 

+ 13 - 0
godot/scripts/ScoreCounterLabel.gd

@@ -0,0 +1,13 @@
+extends Label
+
+
+var total_score = 0
+
+
+func score_point():
+	total_score += 1
+	text = str(total_score)
+
+
+func _on_Grid_kace_damaged():
+	score_point()