Dimensions for constructibles
This commit is contained in:
parent
d37c4ec858
commit
6f56fffb59
18 changed files with 135 additions and 25 deletions
|
@ -6,8 +6,6 @@ extends Marker2D
|
|||
|
||||
class_name BuildZone
|
||||
|
||||
const GRID_SIZE : Vector2 = Vector2(16,16)
|
||||
|
||||
## Rect that used for bounds check and conversions
|
||||
@export var building_rect : Rect2:
|
||||
set(value):
|
||||
|
@ -17,6 +15,8 @@ const GRID_SIZE : Vector2 = Vector2(16,16)
|
|||
get:
|
||||
return building_rect
|
||||
|
||||
@export var entity_holder : EntityHolder
|
||||
|
||||
func _ready() -> void:
|
||||
if not Engine.is_editor_hint():
|
||||
Registry.build_zones.append(self)
|
||||
|
@ -37,7 +37,7 @@ func is_global_point_in_zone(point: Vector2) -> bool:
|
|||
func indexify_point(point : Vector2) -> int:
|
||||
if is_point_in_zone(point) == false:
|
||||
return -1
|
||||
return int(point.x) / int(GRID_SIZE.x) + int(building_rect.size.x/GRID_SIZE.x)*(int(point.y) / int(GRID_SIZE.y))
|
||||
return int(point.x) / int(Globals.GRID_SIZE.x) + int(building_rect.size.x/Globals.GRID_SIZE.x)*(int(point.y) / int(Globals.GRID_SIZE.y))
|
||||
|
||||
## Returns index of point (global coordinates) to be used in array
|
||||
func indexify_global_point(point : Vector2) -> int:
|
||||
|
@ -45,7 +45,7 @@ func indexify_global_point(point : Vector2) -> int:
|
|||
|
||||
## Inverses indexification of point, returning snapped position
|
||||
func inverse_index(index: int) -> Vector2:
|
||||
return to_global(Vector2(index%int(building_rect.size.x/GRID_SIZE.x)*GRID_SIZE.x,index / int(building_rect.size.x/GRID_SIZE.x) * GRID_SIZE.y))
|
||||
return to_global(Vector2(index%int(building_rect.size.x/Globals.GRID_SIZE.x)*Globals.GRID_SIZE.x,index / int(building_rect.size.x/Globals.GRID_SIZE.x) * Globals.GRID_SIZE.y))
|
||||
|
||||
## Returns snapped position of point (global coordinates).
|
||||
## Equivalent of [code]
|
||||
|
@ -54,8 +54,8 @@ func inverse_index(index: int) -> Vector2:
|
|||
func get_placement_position(point : Vector2) -> Vector2:
|
||||
if is_global_point_in_zone(point) == false:
|
||||
return Vector2.ZERO
|
||||
return to_global((to_local(point) / GRID_SIZE).floor()*GRID_SIZE + GRID_SIZE/2.0)
|
||||
return to_global((to_local(point) / Globals.GRID_SIZE).floor()*Globals.GRID_SIZE + Globals.GRID_SIZE/2.0)
|
||||
|
||||
## Returns capacity of building zone to be used in the array
|
||||
func get_capacity() -> int:
|
||||
return int(building_rect.size.x/GRID_SIZE.x)*int(building_rect.size.y/GRID_SIZE.y)
|
||||
return int(building_rect.size.x/Globals.GRID_SIZE.x)*int(building_rect.size.y/Globals.GRID_SIZE.y)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue