#14 ajout de la notion de terrain, de planète et de zone contaminée
This commit is contained in:
5
common/game_data/scripts/game_data.gd
Normal file
5
common/game_data/scripts/game_data.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
extends Resource
|
||||
class_name GameData
|
||||
|
||||
@export var currentTerrainData : TerrainData
|
||||
|
||||
1
common/game_data/scripts/game_data.gd.uid
Normal file
1
common/game_data/scripts/game_data.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://73gftrlwnuhu
|
||||
70
common/game_data/scripts/terrain_data.gd
Normal file
70
common/game_data/scripts/terrain_data.gd
Normal file
@@ -0,0 +1,70 @@
|
||||
extends Resource
|
||||
class_name TerrainData
|
||||
|
||||
const TERRAIN_IMAGE_GAME_FACTOR = 50
|
||||
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MAX_SIZE = 1000
|
||||
const DEFAULT_CONTAMINATION_CENTRAL_ZONE_MIN_SIZE = 200
|
||||
|
||||
signal terrain_updated
|
||||
|
||||
@export var terrainSize : Vector2 = Vector2(2000,2000)
|
||||
|
||||
@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
|
||||
1
common/game_data/scripts/terrain_data.gd.uid
Normal file
1
common/game_data/scripts/terrain_data.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cx30nvq8b34lj
|
||||
Reference in New Issue
Block a user