summaryrefslogtreecommitdiff
path: root/Scenes/Entities/Objects/Tree.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-04-27 20:06:49 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-04-27 20:06:49 +0200
commit81cc6f1d22677dd4a60aa9377c91b291bf10e523 (patch)
tree9c22712a9746ed0598a44be6e88727d021436860 /Scenes/Entities/Objects/Tree.gd
parentc8a316e4b8987dad963656a34665fa0e23dedcb1 (diff)
update
Diffstat (limited to 'Scenes/Entities/Objects/Tree.gd')
-rw-r--r--Scenes/Entities/Objects/Tree.gd48
1 files changed, 48 insertions, 0 deletions
diff --git a/Scenes/Entities/Objects/Tree.gd b/Scenes/Entities/Objects/Tree.gd
new file mode 100644
index 0000000..3d8d669
--- /dev/null
+++ b/Scenes/Entities/Objects/Tree.gd
@@ -0,0 +1,48 @@
+extends StaticBody2D
+
+
+@export_enum("up", "down", "left", "right") var fall_direction: String
+@onready var map: TileMap = get_parent().get_parent().get_node("TileMap")
+
+
+func _ready():
+ add_to_group("breakables")
+
+ 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():
+ var direction = Vector2(0, 0)
+
+ if fall_direction == "up":
+ position.y -= 5
+ direction = Vector2(0, -1)
+ elif fall_direction == "down":
+ rotate(deg_to_rad(180))
+ position.y += 5
+ direction = Vector2(0, 1)
+ elif fall_direction == "left":
+ rotate(deg_to_rad(-90))
+ position.x -= 5
+ direction = Vector2(-1, 0)
+ elif fall_direction == "right":
+ rotate(deg_to_rad(90))
+ position.x += 5
+ direction = Vector2(1, 0)
+
+ for r in range(3):
+ var vec = map.local_to_map(self.position + direction*16*r)
+ map.set_cell(
+ 0,
+ vec,
+ 6,
+ map.get_cell_atlas_coords(0, vec),
+ map.get_cell_alternative_tile(0, vec)
+ )
+
+ $Edges.process_mode = Node.PROCESS_MODE_INHERIT
+ $CollisionShape2D.disabled = true
+ $SpriteStanding.visible = false
+ $SpriteFallen.visible = true