blocks now break upon colliding once their health is depleted

This commit is contained in:
2024-07-23 20:33:27 +02:00
parent 091d957d26
commit eeffba61b6
3 changed files with 40 additions and 6 deletions
+5 -4
View File
@@ -10,8 +10,8 @@ var _velocity: Vector2
var deg: float var deg: float
func _ready(): func _ready():
_velocity.x = 200#speed * _speed_mult * _direction.x * delta _velocity.x = 400#speed * _speed_mult * _direction.x * delta
_velocity.y = 250#speed * _speed_mult * _direction.y * delta _velocity.y = 450#speed * _speed_mult * _direction.y * delta
func _physics_process(delta): func _physics_process(delta):
@@ -23,9 +23,10 @@ func _physics_process(delta):
_invert_x() _invert_x()
if (deg >= 135 and deg < 225) or deg < 45 or deg >= 315: if (deg >= 135 and deg < 225) or deg < 45 or deg >= 315:
_invert_y() _invert_y()
if collide.get_collider() is Block: print(collide.get_collider())
if collide.get_collider().get_parent() is Block:
print(true) print(true)
collide.get_collider().take_damage(strength) collide.get_collider().get_parent().take_damage(strength)
func _invert_x(): func _invert_x():
_velocity.x *= -1 _velocity.x *= -1
+1 -1
View File
@@ -12,7 +12,7 @@ func _update_text():
func take_damage(damage): func take_damage(damage):
health -= damage health -= damage
_update_text() _update_text()
if health < 0: if health <= 0:
die() die()
func die(): func die():
+34 -1
View File
@@ -84,4 +84,37 @@ floor_stop_on_slope = true
[node name="Blocks" type="Node2D" parent="GameContent"] [node name="Blocks" type="Node2D" parent="GameContent"]
[node name="Block" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] [node name="Block" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(907, 752) position = Vector2(932, 753)
[node name="Block2" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(629, 242)
[node name="Block3" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(1459, 692)
[node name="Block4" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(1391, 162)
[node name="Block5" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(723, 963)
[node name="Block6" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(589, 585)
[node name="Block7" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(1156, 909)
[node name="Block8" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(1272, 461)
[node name="Block9" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(1719, 644)
[node name="Block10" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(950, 176)
[node name="Block11" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(1603, 907)
[node name="Block12" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")]
position = Vector2(1635, 293)