diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-08-10 11:48:05 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-08-10 11:48:05 +0200 |
commit | 46556d864b9685c3b09a0038f5de83966fe7ff94 (patch) | |
tree | c68082eacd35559e14565d1598dd694972fb8e0e /Scenes/Entities/Objects/Box.gd |
Initial commit
Diffstat (limited to 'Scenes/Entities/Objects/Box.gd')
-rw-r--r-- | Scenes/Entities/Objects/Box.gd | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Scenes/Entities/Objects/Box.gd b/Scenes/Entities/Objects/Box.gd new file mode 100644 index 0000000..c7b7d4e --- /dev/null +++ b/Scenes/Entities/Objects/Box.gd @@ -0,0 +1,28 @@ +extends StaticBody2D + + +func _ready(): + var collision_area = Utilities.Collision.Area.new(self, $CollisionShape2D, false) + collision_area.connect("collided", Callable(self, "_collide")) + add_child(collision_area) + + +func hit_by_explosion(): + $AnimationPlayer.play("breaking") + await $AnimationPlayer.animation_finished + + if randi_range(1, 3) == 1: + call_deferred("spawn_coin") + + queue_free() + + +func spawn_coin(): + var coin = preload("res://Scenes/Entities/Objects/Coin.tscn").instantiate() + coin.position = self.position + get_tree().get_current_scene().add_child(coin) + + +func _collide(area: Area2D): + if area.is_in_group("explosions"): + self.hit_by_explosion() |