Przeglądaj źródła

:lipstick: Display life amount on bricks

DricomDragon 3 lat temu
rodzic
commit
5796bc9073

+ 6 - 1
godot/component/entity/brick/Brick.tscn

@@ -1,8 +1,9 @@
-[gd_scene load_steps=5 format=2]
+[gd_scene load_steps=6 format=2]
 
 [ext_resource path="res://component/entity/brick/brik.png" type="Texture" id=1]
 [ext_resource path="res://component/entity/brick/Brick.gd" type="Script" id=2]
 [ext_resource path="res://component/entity/brick/BrickMainSprite.gd" type="Script" id=3]
+[ext_resource path="res://component/entity/brick/BrickLifeDisplay.gd" type="Script" id=4]
 
 [sub_resource type="RectangleShape2D" id=1]
 extents = Vector2( 20, 10 )
@@ -20,5 +21,9 @@ script = ExtResource( 3 )
 [node name="Shape" type="CollisionShape2D" parent="."]
 position = Vector2( 20, 10 )
 shape = SubResource( 1 )
+
+[node name="LifeDisplay" type="Node2D" parent="."]
+script = ExtResource( 4 )
 [connection signal="kace_damaged" from="." to="Sprite" method="_on_Brick_kace_damaged"]
 [connection signal="life_changed" from="." to="Sprite" method="_on_Brick_life_changed"]
+[connection signal="life_changed" from="." to="LifeDisplay" method="_on_Brick_life_changed"]

+ 27 - 0
godot/component/entity/brick/BrickLifeDisplay.gd

@@ -0,0 +1,27 @@
+class_name BrickLifeDisplay
+extends Node2D
+
+
+const LABEL_OFFSET = Vector2(5, 15)
+
+
+var default_font
+var life := 0
+
+
+func _ready():
+	create_font()
+
+
+func _draw():
+	draw_string(default_font, position + LABEL_OFFSET, str(life))
+
+
+func create_font():
+	var label = Label.new()
+	default_font = label.get_font("font")
+
+
+func _on_Brick_life_changed(new_life: int):
+	life = new_life
+	update()

+ 0 - 1
godot/component/entity/launcher/Launcher.gd

@@ -130,4 +130,3 @@ func _on_DeadLine_game_lost():
 
 func _on_Ball_kace_contact(pos: Vector2):
 	emit_signal("kace_contact", pos)
-	

+ 6 - 0
godot/project.godot

@@ -19,6 +19,11 @@ _global_script_classes=[ {
 "language": "GDScript",
 "path": "res://component/entity/brick/Brick.gd"
 }, {
+"base": "Node2D",
+"class": "BrickLifeDisplay",
+"language": "GDScript",
+"path": "res://component/entity/brick/BrickLifeDisplay.gd"
+}, {
 "base": "Area2D",
 "class": "Catcher",
 "language": "GDScript",
@@ -42,6 +47,7 @@ _global_script_classes=[ {
 _global_script_class_icons={
 "Ball": "",
 "Brick": "",
+"BrickLifeDisplay": "",
 "Catcher": "",
 "ColorUtil": "",
 "MessagePanel": "",