#14 ajout de la notion de terrain, de planète et de zone contaminée
This commit is contained in:
BIN
stages/terrain/planet/assets/textures/sol_gamejam_normal.png
Normal file
BIN
stages/terrain/planet/assets/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://bnrjnvceprxfn"
|
||||
path="res://.godot/imported/sol_gamejam_normal.png-a8a63b9f57f727b96585445cbd74ba15.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://stages/terrain/planet/assets/textures/sol_gamejam_normal.png"
|
||||
dest_files=["res://.godot/imported/sol_gamejam_normal.png-a8a63b9f57f727b96585445cbd74ba15.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
|
||||
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
|
||||
Reference in New Issue
Block a user