From c73dd1dbd6503a408596e324655db3ca93f234a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melvin=20Wei=C3=9F?= Date: Fri, 3 Oct 2025 11:30:45 +0200 Subject: [PATCH] Building code cleanup --- buildings/building.gd | 11 ++--------- world/grid.gd | 5 +++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/buildings/building.gd b/buildings/building.gd index c5b3809..0f5b019 100644 --- a/buildings/building.gd +++ b/buildings/building.gd @@ -13,9 +13,7 @@ var destroyed = false # also make sure that the buildings are instantiated as children of the grid func _ready() -> void: assert(grid != null) - var angle = location.x * TAU / grid.num_collumns; # currently assumes anchor is bottom left - var height = grid.ground_radius + location.y * grid.cell_height; - position = height * Vector2.from_angle(angle) + position = grid.get_world_position(location) if blocks_area: grid.buildings.append(self) @@ -27,17 +25,12 @@ func _ready() -> void: for enemy in enemies: var oldpos = enemy.position; - enemy.position = get_world_position(oldpos) + enemy.position = grid.get_world_position(oldpos) if enemy is Platform or enemy is Trap or enemy is Item: objects.append(enemy) if "building" in enemy: enemy.building = self if(enemy.has_method("init_at_horizontal_distortion")): enemy.init_at_horizontal_distortion(enemy.position.length() / grid.ground_radius) - -func get_world_position (local_position: Vector2) -> Vector2: - var height = grid.ground_radius + location.y * grid.cell_height - local_position.y - var angle = (location.x + local_position.x / grid.cell_height) * TAU / grid.num_collumns - return height * Vector2.from_angle(angle) func overlaps(other : Building): # heights don't overlap diff --git a/world/grid.gd b/world/grid.gd index cd12343..4e55172 100644 --- a/world/grid.gd +++ b/world/grid.gd @@ -40,6 +40,11 @@ func add_building_to_collumn(building : Building, collumn : int): add_child(building) return true +func get_world_position (location: Vector2, offset: Vector2 = Vector2.ZERO) -> Vector2: + var height = ground_radius + location.y * cell_height - offset.y # currently assumes anchor is bottom left + var angle = (location.x + offset.x / cell_height) * TAU / num_collumns + return height * Vector2.from_angle(angle) + # for testing #func _ready() -> void: #