#14 ajout de la notion de terrain, de planète et de zone contaminée
This commit is contained in:
parent
a0f17df7c6
commit
25d81d57a5
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
|
||||
52
common/tools/scripts/image_tools.gd
Normal file
52
common/tools/scripts/image_tools.gd
Normal file
@ -0,0 +1,52 @@
|
||||
class_name ImageTools
|
||||
|
||||
static func draw_circle(image: Image, center: Vector2i, length: int, color: Color = Color.WHITE):
|
||||
for x in range(image.get_width()):
|
||||
for y in range(image.get_height()):
|
||||
var center_distance = Vector2i(x, y).distance_to(center)
|
||||
|
||||
if (center_distance <= length):
|
||||
image.set_pixel(x, y, color)
|
||||
|
||||
|
||||
static func draw_gradient(image: Image, center: Vector2i, length: int, color: Color = Color.WHITE, inverse := false):
|
||||
for x in range(image.get_width()):
|
||||
for y in range(image.get_height()):
|
||||
var original_pixel_color = image.get_pixel(x, y)
|
||||
var center_distance = Vector2i(x, y).distance_to(center)
|
||||
|
||||
if (center_distance == 0):
|
||||
if not inverse:
|
||||
image.set_pixel(x, y, original_pixel_color.blend(color))
|
||||
else:
|
||||
var color_to_add = Color(color, 1 / (center_distance / length)) if not inverse else Color(color, center_distance / length)
|
||||
image.set_pixel(
|
||||
x,
|
||||
y,
|
||||
original_pixel_color.blend(color_to_add)
|
||||
)
|
||||
|
||||
static func flatten(image: Image, threshold := 0.5):
|
||||
for x in range(image.get_width()):
|
||||
for y in range(image.get_height()):
|
||||
var original_pixel_color = image.get_pixel(x, y)
|
||||
|
||||
if original_pixel_color.r > threshold:
|
||||
image.set_pixel(
|
||||
x,
|
||||
y,
|
||||
Color.WHITE
|
||||
)
|
||||
else:
|
||||
image.set_pixel(
|
||||
x,
|
||||
y,
|
||||
Color.BLACK
|
||||
)
|
||||
|
||||
static func copy(from: Image, to : Image):
|
||||
for x in range(from.get_width()):
|
||||
for y in range(from.get_height()):
|
||||
to.set_pixel(x, y, from.get_pixel(x, y))
|
||||
|
||||
|
||||
1
common/tools/scripts/image_tools.gd.uid
Normal file
1
common/tools/scripts/image_tools.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://b05d3may5qqtv
|
||||
@ -5,7 +5,10 @@ const LERP_WEIGHT = 0.9
|
||||
|
||||
@export var following : Node2D
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
func _ready():
|
||||
if following:
|
||||
global_position = following.global_position
|
||||
|
||||
func _process(_delta):
|
||||
if following:
|
||||
global_position = following.global_position.lerp(global_position, LERP_WEIGHT)
|
||||
|
||||
@ -3,6 +3,7 @@ class_name Player
|
||||
|
||||
signal player_stats_updated(player : Player)
|
||||
|
||||
var planet : Planet # mis à jour par la classe Planet
|
||||
@export var speed = 400
|
||||
|
||||
var energy : int = 10 :
|
||||
|
||||
@ -19,7 +19,7 @@ config/icon="res://icon.svg"
|
||||
|
||||
move_right={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
@ -50,3 +50,4 @@ interact={
|
||||
[rendering]
|
||||
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
environment/defaults/default_clear_color=Color(0.0617213, 0.0605653, 0.169189, 1)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://c5bruelvqbm1k"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://12nak7amd1uq" path="res://gui/root_gui.tscn" id="1_jnlp7"]
|
||||
[ext_resource type="PackedScene" uid="uid://tsi5j1uxppa4" path="res://stages/planet/planet.tscn" id="1_pyidc"]
|
||||
[ext_resource type="PackedScene" uid="uid://tsi5j1uxppa4" path="res://stages/terrain/planet/planet.tscn" id="1_pyidc"]
|
||||
[ext_resource type="PackedScene" uid="uid://bgvbgeq46wee2" path="res://entities/player/player.tscn" id="2_vvh5c"]
|
||||
[ext_resource type="PackedScene" uid="uid://dj7gp3crtg2yt" path="res://entities/camera/camera.tscn" id="3_vvh5c"]
|
||||
[ext_resource type="PackedScene" uid="uid://clpcqkdlj3d8e" path="res://entities/interactables/plants/default_plant.tscn" id="4_28aoi"]
|
||||
@ -47,7 +47,8 @@ position = Vector2(98, 90)
|
||||
[node name="DefaultPlant10" parent="Entities" instance=ExtResource("4_28aoi")]
|
||||
position = Vector2(-269, 1)
|
||||
|
||||
[node name="Planet" parent="." instance=ExtResource("1_pyidc")]
|
||||
[node name="Planet" parent="." node_paths=PackedStringArray("import_entities_from_node") instance=ExtResource("1_pyidc")]
|
||||
import_entities_from_node = NodePath("../Entities")
|
||||
|
||||
[node name="Camera" parent="." node_paths=PackedStringArray("following") instance=ExtResource("3_vvh5c")]
|
||||
position = Vector2(2.22, 0)
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://tsi5j1uxppa4"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bnrjnvceprxfn" path="res://stages/planet/assets/textures/sol_gamejam_normal.png" id="1_wb4p4"]
|
||||
|
||||
[node name="Planet" type="Node2D"]
|
||||
|
||||
[node name="SolGamejamNormal" type="Sprite2D" parent="."]
|
||||
z_index = -1
|
||||
texture = ExtResource("1_wb4p4")
|
||||
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
@ -3,15 +3,15 @@
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bnrjnvceprxfn"
|
||||
path="res://.godot/imported/sol_gamejam_normal.png-a56c3648b71b32f03d2bec4e03abf9bc.ctex"
|
||||
path="res://.godot/imported/sol_gamejam_normal.png-a8a63b9f57f727b96585445cbd74ba15.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://stages/planet/assets/textures/sol_gamejam_normal.png"
|
||||
dest_files=["res://.godot/imported/sol_gamejam_normal.png-a56c3648b71b32f03d2bec4e03abf9bc.ctex"]
|
||||
source_file="res://stages/terrain/planet/assets/textures/sol_gamejam_normal.png"
|
||||
dest_files=["res://.godot/imported/sol_gamejam_normal.png-a8a63b9f57f727b96585445cbd74ba15.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
10
stages/terrain/planet/planet.tscn
Normal file
10
stages/terrain/planet/planet.tscn
Normal file
@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://tsi5j1uxppa4"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://d1mp5sguc0b6u" path="res://stages/terrain/planet/scripts/planet.gd" id="1_y7d8a"]
|
||||
[ext_resource type="Material" uid="uid://ljvaj1vab53a" path="res://stages/terrain/planet/resources/materials/ground_contamination.tres" id="2_02xai"]
|
||||
[ext_resource type="Texture2D" uid="uid://bhs47ar83jfmr" path="res://stages/terrain/planet/resources/textures/sol_gamejam_normal.png" id="2_6qoee"]
|
||||
|
||||
[node name="Planet" type="Node2D"]
|
||||
script = ExtResource("1_y7d8a")
|
||||
background_texture = ExtResource("2_6qoee")
|
||||
contamination_material = ExtResource("2_02xai")
|
||||
@ -0,0 +1,26 @@
|
||||
[gd_resource type="ShaderMaterial" load_steps=7 format=3 uid="uid://ljvaj1vab53a"]
|
||||
|
||||
[ext_resource type="Shader" uid="uid://bglep64ppn74p" path="res://stages/terrain/planet/resources/materials/shaders/textures_data_filter.gdshader" id="1_ye8oh"]
|
||||
[ext_resource type="Texture2D" uid="uid://dcn4cq53h1qiy" path="res://stages/terrain/planet/resources/textures/sol_gamejam_fleurs_transp.png" id="3_j3avn"]
|
||||
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_6hswu"]
|
||||
frequency = 0.0109
|
||||
|
||||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_j3avn"]
|
||||
noise = SubResource("FastNoiseLite_6hswu")
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_r7pv0"]
|
||||
offsets = PackedFloat32Array(0)
|
||||
colors = PackedColorArray(0, 0, 0, 0.12549)
|
||||
|
||||
[sub_resource type="GradientTexture1D" id="GradientTexture1D_6hswu"]
|
||||
gradient = SubResource("Gradient_r7pv0")
|
||||
|
||||
[resource]
|
||||
shader = ExtResource("1_ye8oh")
|
||||
shader_parameter/data_texture = SubResource("NoiseTexture2D_j3avn")
|
||||
shader_parameter/data_texture_size = Vector2(1000, 1000)
|
||||
shader_parameter/data_texture_threshold = 0.5
|
||||
shader_parameter/texture_0 = SubResource("GradientTexture1D_6hswu")
|
||||
shader_parameter/texture_1 = ExtResource("3_j3avn")
|
||||
shader_parameter/texture_scale = 5.0
|
||||
@ -0,0 +1,35 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
#define pow2(x) (x * x)
|
||||
#define iResolution 1.0/SCREEN_PIXEL_SIZE
|
||||
|
||||
uniform sampler2D data_texture;
|
||||
uniform vec2 data_texture_size;
|
||||
uniform float data_texture_threshold = 0.5;
|
||||
uniform sampler2D texture_0 : filter_nearest, repeat_enable;
|
||||
uniform sampler2D texture_1 : filter_nearest, repeat_enable;
|
||||
|
||||
uniform float texture_scale = 10.;
|
||||
|
||||
//uniform float smooth_change_range = 0.15;
|
||||
|
||||
varying vec2 vert;
|
||||
|
||||
void vertex() {
|
||||
vert = VERTEX;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec4 pixel_color = texture(data_texture, vert/data_texture_size);
|
||||
float value = pixel_color.x;
|
||||
|
||||
vec2 texture_0_size = vec2(float(textureSize(texture_0, 0).x), float(textureSize(texture_0, 0).y)) / texture_scale;
|
||||
vec2 texture_1_size = vec2(float(textureSize(texture_1, 0).x), float(textureSize(texture_1, 0).y)) / texture_scale;
|
||||
|
||||
vec4 color = texture(texture_0, vert/texture_0_size);
|
||||
|
||||
if (value > data_texture_threshold)
|
||||
color = texture(texture_1, vert / texture_1_size);
|
||||
|
||||
COLOR = color;
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://bglep64ppn74p
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 931 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dcn4cq53h1qiy"
|
||||
path="res://.godot/imported/sol_gamejam_fleurs_transp.png-9f83431996765c9ee6ae75623dc9a6ca.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://stages/terrain/planet/resources/textures/sol_gamejam_fleurs_transp.png"
|
||||
dest_files=["res://.godot/imported/sol_gamejam_fleurs_transp.png-9f83431996765c9ee6ae75623dc9a6ca.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
stages/terrain/planet/resources/textures/sol_gamejam_normal.png
Normal file
BIN
stages/terrain/planet/resources/textures/sol_gamejam_normal.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 114 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bhs47ar83jfmr"
|
||||
path="res://.godot/imported/sol_gamejam_normal.png-026e1b07759fe660eb66a9c8a302cb82.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://stages/terrain/planet/resources/textures/sol_gamejam_normal.png"
|
||||
dest_files=["res://.godot/imported/sol_gamejam_normal.png-026e1b07759fe660eb66a9c8a302cb82.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 653 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://73topi3k4iia"
|
||||
path="res://.godot/imported/sol_gamejam_pollution_transparent.png-e0f6a469ee35256b6f08efb9025c9a38.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://stages/terrain/planet/resources/textures/sol_gamejam_pollution_transparent.png"
|
||||
dest_files=["res://.godot/imported/sol_gamejam_pollution_transparent.png-e0f6a469ee35256b6f08efb9025c9a38.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
70
stages/terrain/planet/scripts/planet.gd
Normal file
70
stages/terrain/planet/scripts/planet.gd
Normal file
@ -0,0 +1,70 @@
|
||||
extends Terrain
|
||||
class_name Planet
|
||||
|
||||
const PLANET_TEXTURE_SCALE : float = 5.0
|
||||
|
||||
@export var background_texture : Texture2D
|
||||
@export var contamination_material : ShaderMaterial
|
||||
|
||||
|
||||
@onready var background_sprite : Polygon2D = generate_background_sprite()
|
||||
@onready var contamination_sprite : Polygon2D = generate_contamination_terrain_sprite()
|
||||
var contamination_texture : ImageTexture
|
||||
|
||||
func add_entity(e : Node2D, container : Node2D):
|
||||
if e.get_parent():
|
||||
e.get_parent().remove_child(e)
|
||||
|
||||
if e is Player:
|
||||
e.planet = self
|
||||
|
||||
container.add_child(e)
|
||||
|
||||
func generate_polygon_sprite(order : int = 0) -> Polygon2D:
|
||||
var sprite = Polygon2D.new()
|
||||
var size = terrainData.terrainSize
|
||||
sprite.polygon = PackedVector2Array([
|
||||
Vector2(0,0),
|
||||
Vector2(size.x, 0),
|
||||
Vector2(size.x, size.y),
|
||||
Vector2(0, size.y),
|
||||
])
|
||||
|
||||
sprite.z_index = -100 + order
|
||||
|
||||
add_child(sprite)
|
||||
|
||||
return sprite
|
||||
|
||||
func generate_background_sprite() -> Polygon2D:
|
||||
var sprite : Polygon2D = generate_polygon_sprite(0)
|
||||
|
||||
sprite.texture = background_texture
|
||||
sprite.texture_repeat = CanvasItem.TEXTURE_REPEAT_ENABLED
|
||||
sprite.texture_scale = Vector2.ONE * PLANET_TEXTURE_SCALE
|
||||
|
||||
return sprite
|
||||
|
||||
func generate_contamination_terrain_sprite() -> Polygon2D:
|
||||
if not terrainData.contamination:
|
||||
terrainData.generate_default_contamination()
|
||||
|
||||
var sprite :Polygon2D = generate_polygon_sprite(1)
|
||||
|
||||
contamination_texture = ImageTexture.create_from_image(terrainData.contamination)
|
||||
|
||||
contamination_material.set_shader_parameter("data_texture", contamination_texture)
|
||||
contamination_material.set_shader_parameter("data_texture_size", terrainData.terrainSize)
|
||||
contamination_material.set_shader_parameter("texture_scale", PLANET_TEXTURE_SCALE)
|
||||
|
||||
sprite.material = contamination_material
|
||||
|
||||
return sprite
|
||||
|
||||
func impact_contamination(impact_position : Vector2, impact_radius : int, contamination : bool = false):
|
||||
terrainData.impact_contamination(impact_position, impact_radius, 0. if contamination else 1.)
|
||||
if contamination_texture:
|
||||
contamination_texture.update(terrainData.contamination)
|
||||
|
||||
func is_there_contamination(point : Vector2) -> bool:
|
||||
return terrainData.get_contamination(point) < 0.5
|
||||
1
stages/terrain/planet/scripts/planet.gd.uid
Normal file
1
stages/terrain/planet/scripts/planet.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://d1mp5sguc0b6u
|
||||
57
stages/terrain/scripts/terrain.gd
Normal file
57
stages/terrain/scripts/terrain.gd
Normal file
@ -0,0 +1,57 @@
|
||||
extends Node2D
|
||||
class_name Terrain
|
||||
|
||||
const BORDER_WIDTH = 100
|
||||
|
||||
@export var import_entities_from_node : Node2D = null
|
||||
|
||||
@export var terrainData : TerrainData
|
||||
|
||||
@onready var borderLimit : StaticBody2D = create_border_limit()
|
||||
@onready var entityContainer : Node2D = create_entity_container()
|
||||
|
||||
func _init():
|
||||
if not terrainData:
|
||||
terrainData = TerrainData.new()
|
||||
|
||||
func add_entity(e : Node2D, container : Node2D):
|
||||
if e.get_parent():
|
||||
e.get_parent().remove_child(e)
|
||||
|
||||
container.add_child(e)
|
||||
|
||||
func create_entity_container() -> Node2D:
|
||||
var container = Node2D.new()
|
||||
container.y_sort_enabled = true
|
||||
container.position = terrainData.terrainSize/2
|
||||
|
||||
add_child(container)
|
||||
|
||||
if import_entities_from_node:
|
||||
for child in import_entities_from_node.get_children():
|
||||
add_entity(child, container)
|
||||
|
||||
return container
|
||||
|
||||
func create_border_limit() -> StaticBody2D:
|
||||
var staticBody = StaticBody2D.new()
|
||||
var staticBodyCollision = CollisionPolygon2D.new()
|
||||
|
||||
add_child(staticBody)
|
||||
staticBody.add_child(staticBodyCollision)
|
||||
|
||||
var size = terrainData.terrainSize
|
||||
staticBodyCollision.polygon = PackedVector2Array([
|
||||
Vector2(0,0),
|
||||
Vector2(0, size.y),
|
||||
Vector2(size.x, size.y),
|
||||
Vector2(size.x, 0),
|
||||
Vector2(0,0),
|
||||
Vector2(-BORDER_WIDTH, -BORDER_WIDTH),
|
||||
Vector2(size.x + BORDER_WIDTH, -BORDER_WIDTH),
|
||||
Vector2(size.x + BORDER_WIDTH, size.y + BORDER_WIDTH),
|
||||
Vector2(- BORDER_WIDTH, size.y + BORDER_WIDTH),
|
||||
Vector2(-BORDER_WIDTH, -BORDER_WIDTH)
|
||||
])
|
||||
|
||||
return staticBody
|
||||
1
stages/terrain/scripts/terrain.gd.uid
Normal file
1
stages/terrain/scripts/terrain.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dfl1ijmbmw57r
|
||||
Loading…
Reference in New Issue
Block a user