From 81cc6f1d22677dd4a60aa9377c91b291bf10e523 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 27 Apr 2024 20:06:49 +0200 Subject: update --- Scenes/Entities/Objects/Tree.gd | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Scenes/Entities/Objects/Tree.gd (limited to 'Scenes/Entities/Objects/Tree.gd') 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 -- cgit v1.2.3