ball now more consistently collides with arbitrary objects and bounces off them appropriately

This commit is contained in:
2024-07-23 20:07:13 +02:00
parent 3fea3c89ed
commit 091d957d26
7 changed files with 147 additions and 102 deletions
+19
View File
@@ -0,0 +1,19 @@
extends Sprite2D
class_name Block
@export var health: int = 1
func _ready():
_update_text()
func _update_text():
$Label.text = "%s" % health
func take_damage(damage):
health -= damage
_update_text()
if health < 0:
die()
func die():
self.queue_free()
+33 -1
View File
@@ -1,3 +1,35 @@
[gd_scene format=3 uid="uid://c1i1fp3xbp6ly"]
[gd_scene load_steps=5 format=3 uid="uid://c1i1fp3xbp6ly"]
[ext_resource type="Texture2D" uid="uid://c7ejgh4t0c7cw" path="res://blocks/block.webp" id="1_lqtqu"]
[ext_resource type="Script" path="res://blocks/block.gd" id="2_jqrjk"]
[ext_resource type="FontFile" uid="uid://dxgnofummhosw" path="res://fonts/play_bold.ttf" id="3_gmjev"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_46e0q"]
size = Vector2(120, 50)
[node name="Block" type="Sprite2D"]
texture = ExtResource("1_lqtqu")
script = ExtResource("2_jqrjk")
[node name="Area2D" type="StaticBody2D" parent="."]
collision_layer = 8
collision_mask = 4
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("RectangleShape2D_46e0q")
[node name="Label" type="Label" parent="."]
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -71.0
offset_top = -48.0
offset_right = -48.0
offset_bottom = -1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_fonts/font = ExtResource("3_gmjev")
theme_override_font_sizes/font_size = 40