#2 Collects resources

#8 Generates resources based on resource data
#10 Shows total resources and adjusts for new resources
This commit is contained in:
2024-02-07 09:22:14 -06:00
parent 7c81a2229e
commit 84de7fa6f1
10 changed files with 157 additions and 39 deletions

View File

@@ -1,6 +1,6 @@
class_name World extends Node2D
@export var resoure_quantity = 0.4
@export var game_resources: Array[GameResource]
var terrain_noise := FastNoiseLite.new()
var resource_noise: Noise = FastNoiseLite.new()
@@ -9,8 +9,8 @@ var temp_size = 150
var temp_noise_val = []
var temp_noise_reg = []
var noise_regions = [-999,10,150,200,999]
var atlas_regions = [Vector2i(0,1),Vector2i(0,0),Vector2i(2,0),Vector2i(0,2)]
var noise_regions := [-999,0,999]
var atlas_regions := [Vector2i(0,1),Vector2i(0,0)]
var world_data: Dictionary = {}
@@ -19,8 +19,12 @@ var world_data: Dictionary = {}
func get_noise_value(x: int, y: int):
return terrain_noise.get_noise_2d(x,y) * 500
func is_resource_tile(x: int, y: int) -> bool:
return resource_noise.get_noise_2d(x, y) > resoure_quantity
func is_resource_tile(x: int, y: int) -> GameResource:
for res: GameResource in game_resources:
var noise = resource_noise.get_noise_2d(x, y)
if res.spawn_region_min < noise and noise < res.spawn_region_max:
return res
return null
func get_noise_region(x,y):
var noise_val = get_noise_value(x,y)
@@ -35,8 +39,9 @@ func _ready():
for x in range(-temp_size, temp_size):
for y in range(-temp_size, temp_size):
change_location_data(Vector2i(x,y), Constants.TilemapLayers.GROUND, atlas_regions[get_noise_region(x,y)])
if is_resource_tile(x,y):
change_location_data(Vector2i(x,y), Constants.TilemapLayers.ENVIRONMENT, Vector2i(5,6))
var tile_res := is_resource_tile(x,y)
if tile_res:
change_location_resource(Vector2i(x,y), tile_res)
temp_noise_val.append(get_noise_value(x,y))
temp_noise_reg.append(get_noise_region(x,y))
prints(temp_noise_val.min(), temp_noise_val.max())
@@ -49,9 +54,9 @@ func _process(delta):
world_grid.set_cell(Constants.TilemapLayers.CURSOR, mouse_pos,0,Vector2i(0,7))
func corrupt_location(loc: Vector2i):
world_data[loc].change_layer(Constants.TilemapLayers.CORRUPTION, true)
var corrupted_cells := world_data.values().filter(func(cell: CellData): return cell.is_corrupted()).map(func(cell: CellData) -> Vector2i: return cell._pos)
world_grid.set_cells_terrain_connect(Constants.TilemapLayers.CORRUPTION, corrupted_cells, 0, 0)
if world_data[loc].change_layer(Constants.TilemapLayers.CORRUPTION, true):
var corrupted_cells := world_data.values().filter(func(cell: CellData): return cell.is_corrupted()).map(func(cell: CellData) -> Vector2i: return cell._pos)
world_grid.set_cells_terrain_connect(Constants.TilemapLayers.CORRUPTION, corrupted_cells, 0, 0)
func grid_location(global_pos: Vector2) -> Vector2i:
return world_grid.local_to_map(global_pos)
@@ -61,3 +66,10 @@ func change_location_data(pos: Vector2i, layer: int, data: Vector2i) -> void:
world_data[pos] = CellData.new(pos)
world_data[pos].change_layer(layer, data)
world_grid.set_cell(layer, pos, 0, data)
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)
func get_corrupted_resources() -> Array:
return world_data.values().filter(func(cell: CellData): return cell.is_corrupted() and cell.has_layer(Constants.TilemapLayers.ENVIRONMENT))