Building code cleanup
This commit is contained in:
parent
8e9f7723d9
commit
c73dd1dbd6
2 changed files with 7 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue