#24 et #21 ajout d'une plante générique, et d'un cycle de recharge du robot avec croissance des plantes
This commit is contained in:
@@ -22,12 +22,12 @@ void 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);
|
||||
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
extends Terrain
|
||||
class_name Planet
|
||||
|
||||
signal planet_stats_updated(day : int)
|
||||
|
||||
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):
|
||||
var contamination_texture : ImageTexture
|
||||
var day : int = 0 :
|
||||
set(v):
|
||||
emit_signal("planet_stats_updated", v)
|
||||
day = v
|
||||
|
||||
func _ready():
|
||||
emit_signal("planet_stats_updated", day)
|
||||
|
||||
#region ------------------ Generation ------------------
|
||||
|
||||
func add_entity(e : Node2D, container : Node2D = entityContainer):
|
||||
if e.get_parent():
|
||||
e.get_parent().remove_child(e)
|
||||
|
||||
@@ -20,6 +31,7 @@ func add_entity(e : Node2D, container : Node2D):
|
||||
|
||||
container.add_child(e)
|
||||
|
||||
|
||||
func generate_polygon_sprite(order : int = 0) -> Polygon2D:
|
||||
var sprite = Polygon2D.new()
|
||||
var size = terrainData.terrainSize
|
||||
@@ -61,10 +73,40 @@ func generate_contamination_terrain_sprite() -> Polygon2D:
|
||||
|
||||
return sprite
|
||||
|
||||
#endregion
|
||||
|
||||
#region ------------------ Usage ------------------
|
||||
|
||||
func plant(
|
||||
type : PlantType,
|
||||
plant_position : Vector2,
|
||||
) -> bool:
|
||||
if is_there_contamination(plant_position):
|
||||
return false
|
||||
|
||||
var new_plant = Plant.new(
|
||||
type,
|
||||
self
|
||||
)
|
||||
add_entity(new_plant)
|
||||
new_plant.global_position = plant_position
|
||||
return true
|
||||
|
||||
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
|
||||
return terrainData.get_contamination(point) < 0.5
|
||||
|
||||
func pass_day():
|
||||
for e : Node2D in entityContainer.get_children():
|
||||
if e.has_method("pass_day"):
|
||||
e.pass_day()
|
||||
day += 1
|
||||
|
||||
#endregion
|
||||
|
||||
func _on_root_gui_day_pass_proceed():
|
||||
pass_day()
|
||||
Reference in New Issue
Block a user