Added building structure
Created harvester building added harvester particles added nearest resource func
This commit is contained in:
@@ -4,6 +4,8 @@ const GRID_SIZE := 64
|
||||
var world_grid: TileMap
|
||||
var world_data: Dictionary = {}
|
||||
|
||||
var res_locations := {}
|
||||
|
||||
func init(grid: TileMap) -> void:
|
||||
world_grid = grid
|
||||
|
||||
@@ -37,6 +39,19 @@ func get_location_data(pos: Vector2i) -> CellData:
|
||||
func change_location_resource(pos: Vector2i, data: GameResource) -> void:
|
||||
world_data[pos].change_resource(data)
|
||||
world_grid.set_cell(Constants.TilemapLayers.ENVIRONMENT, pos, 0, data.atlas_location)
|
||||
if not res_locations.has(data):
|
||||
res_locations[data] = []
|
||||
res_locations[data].append(Grid.grid_to_world_center(pos))
|
||||
|
||||
func get_nearest_resource(pos: Vector2, data: GameResource) -> Vector2:
|
||||
var distance: float = 9999
|
||||
var nearest: Vector2
|
||||
for location: Vector2 in res_locations[data]:
|
||||
var _dist = pos.distance_to(location)
|
||||
if _dist < distance:
|
||||
distance = _dist
|
||||
nearest = location
|
||||
return nearest
|
||||
|
||||
func change_location_building(pos: Vector2i, data: BuildingBase) -> void:
|
||||
world_data[pos].change_building(data)
|
||||
|
||||
Reference in New Issue
Block a user