74 lines
1.8 KiB
GDScript
74 lines
1.8 KiB
GDScript
extends Resource
|
|
class_name TerrainData
|
|
|
|
const TERRAIN_IMAGE_GAME_FACTOR = 50
|
|
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE = 500
|
|
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE = 100
|
|
|
|
signal terrain_updated
|
|
|
|
@export var terrainSize : Vector2 = Vector2(1500,1500)
|
|
|
|
@export var contamination : Image = null
|
|
|
|
func generate_default_contamination(
|
|
central_zone_max_size : int = DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE,
|
|
central_zone_min_size : int = DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE,
|
|
):
|
|
var noise: Noise = FastNoiseLite.new()
|
|
noise.seed = randi()
|
|
noise.noise_type = FastNoiseLite.TYPE_CELLULAR
|
|
noise.frequency = 0.005 * TERRAIN_IMAGE_GAME_FACTOR
|
|
|
|
var imageSize = terrainSize / TERRAIN_IMAGE_GAME_FACTOR;
|
|
|
|
var noise_image = noise.get_image(
|
|
imageSize.x,
|
|
imageSize.y,
|
|
1.0
|
|
)
|
|
|
|
ImageTools.draw_gradient(
|
|
noise_image,
|
|
imageSize/2,
|
|
central_zone_min_size / TERRAIN_IMAGE_GAME_FACTOR
|
|
)
|
|
|
|
ImageTools.draw_gradient(
|
|
noise_image,
|
|
imageSize/2,
|
|
central_zone_max_size / TERRAIN_IMAGE_GAME_FACTOR,
|
|
Color.BLACK,
|
|
true
|
|
)
|
|
|
|
|
|
ImageTools.flatten(noise_image, 0.5)
|
|
|
|
contamination = Image.create(
|
|
imageSize.x,
|
|
imageSize.y,
|
|
false,
|
|
Image.Format.FORMAT_L8
|
|
)
|
|
|
|
contamination.copy_from(noise_image)
|
|
|
|
func impact_contamination(position : Vector2, impact_radius : int, to_value : float = 1.):
|
|
ImageTools.draw_circle(
|
|
contamination,
|
|
position / TERRAIN_IMAGE_GAME_FACTOR,
|
|
impact_radius / TERRAIN_IMAGE_GAME_FACTOR,
|
|
Color(1., 1., 1., to_value)
|
|
)
|
|
|
|
func get_contamination(point : Vector2) -> float:
|
|
var pixel_point : Vector2 = Vector2(point) / float(TERRAIN_IMAGE_GAME_FACTOR)
|
|
return contamination.get_pixel(
|
|
int(round(pixel_point.x)),
|
|
int(round(pixel_point.y))
|
|
).r
|
|
|
|
func get_decontamination_coverage() -> float:
|
|
return ImageTools.get_color_coverage(contamination)
|