des trucs

This commit is contained in:
2024-09-04 20:04:20 +02:00
parent fc4be1f695
commit e20ad3db95
33 changed files with 470 additions and 55 deletions

View File

@@ -14,8 +14,8 @@ func _ready():
func _on_area_2d_area_entered(area: Area2D) -> void:
var plant = area.get_parent()
if plant is Plant and not is_liberated:
plant.grown.connect(tracked_plant_grew)
plant.died.connect(tracked_plant_died)
plant.grown.connect(tracked_plant_grew)
plant.died.connect(tracked_plant_died)
func tracked_plant_grew():
if is_liberated:

View File

@@ -37,6 +37,11 @@ func update_mouse_position(mouse_position):
and mouse_position.x < GameTerrain.TERRAIN_SIZE.x * GameTerrain.MAP_RATIO
and mouse_position.y < GameTerrain.TERRAIN_SIZE.y * GameTerrain.MAP_RATIO
):
waterNeeds.set_cursor(GameTerrain.get_color(mouse_position).r)
fertilityNeeds.set_cursor(GameTerrain.get_color(mouse_position).g)
populationNeeds.set_cursor(GameTerrain.get_color(mouse_position).b)
var next_seed_param := planter.get_plant_from_queue()
var needs := GameTerrain.get_levels(mouse_position)
var meet_water: bool = needs.x >= next_seed_param.water_need[0] and needs.x <= next_seed_param.water_need[1]
waterNeeds.set_cursor(GameTerrain.get_color(mouse_position).r, meet_water)
var meet_fert: bool = needs.y >= next_seed_param.fertility_need[0] and needs.y <= next_seed_param.fertility_need[1]
fertilityNeeds.set_cursor(GameTerrain.get_color(mouse_position).g, meet_fert)
var meet_pop: bool = needs.z + GameTerrain.LEVELS_NUMBER / 2 >= next_seed_param.presence_need[0] and needs.z + GameTerrain.LEVELS_NUMBER / 2 <= next_seed_param.presence_need[1]
populationNeeds.set_cursor(GameTerrain.get_color(mouse_position).b, meet_pop)

View File

@@ -4,6 +4,8 @@ extends CenterContainer
@export var gradient : GradientTexture1D
const CURSOR_WIDTH = 0.04
const VALID_COLOR := Color(0.1, 0.9, 0.85, 1.0)
const NOT_VALID_COLOR := Color(1.0, 0.0, 0.3, 1.0)
# Called when the node enters the scene tree for the first time.
func _ready():
@@ -29,7 +31,7 @@ func set_area(need : Array):
$Zone.texture = texture
func set_cursor(color_value):
func set_cursor(color_value, is_valid: bool):
var zone_grad := Gradient.new()
zone_grad.interpolation_mode = Gradient.GRADIENT_INTERPOLATE_CONSTANT
@@ -37,8 +39,13 @@ func set_cursor(color_value):
zone_grad.set_color(0, Color(1,1,1,0))
zone_grad.set_color(1, Color(1,1,1,0))
zone_grad.add_point(max(color_value - CURSOR_WIDTH/2, 0.0), Color(1,1,1,1))
zone_grad.add_point(min(color_value + CURSOR_WIDTH/2, 1.0), Color(1,1,1,0))
var color := NOT_VALID_COLOR
if is_valid:
color = VALID_COLOR
zone_grad.add_point(max(color_value - CURSOR_WIDTH/2, 0.0), color)
color.a = 0
zone_grad.add_point(min(color_value + CURSOR_WIDTH/2, 1.0), color)
var texture := GradientTexture1D.new()

View File

@@ -35,6 +35,10 @@ func _on_need_checker_timeout() -> void:
can_grow = check_terrain_viability()
growing_timer.paused = not can_grow and state == PlantState.SAPLING
reproduction.paused = not can_grow
if can_grow:
sprite_node.frame = 1
else:
sprite_node.frame = 0
func check_terrain_viability() -> bool:
var water := GameTerrain.get_stat(position, GameTerrain.Stats.WATER)
@@ -86,16 +90,19 @@ func grow():
state = PlantState.GROWN
sapling_count_down.stop()
growing_timer.start(parameter.dying_time)
GameTerrain.modify_zone(position,
GameTerrain.modify_zone_falloff(position,
parameter.distance_prod,
parameter.distance_prod_falloff,
GameTerrain.Stats.WATER,
parameter.water_prod)
GameTerrain.modify_zone(position,
GameTerrain.modify_zone_falloff(position,
parameter.distance_prod,
parameter.distance_prod_falloff,
GameTerrain.Stats.FERTILITY,
parameter.fertility_prod)
GameTerrain.modify_zone(position,
GameTerrain.modify_zone_falloff(position,
parameter.distance_prod,
parameter.distance_prod_falloff,
GameTerrain.Stats.PRESENCE,
parameter.presence_prod)
@@ -109,16 +116,19 @@ func grow():
func die():
state = PlantState.DEAD
# remove alive prod and add dead prod
GameTerrain.modify_zone(position,
GameTerrain.modify_zone_falloff(position,
parameter.distance_prod,
parameter.distance_prod_falloff,
GameTerrain.Stats.WATER,
-parameter.water_prod + parameter.dead_water_prod)
GameTerrain.modify_zone(position,
GameTerrain.modify_zone_falloff(position,
parameter.distance_prod,
parameter.distance_prod_falloff,
GameTerrain.Stats.FERTILITY,
-parameter.fertility_prod + parameter.dead_fertility_prod)
GameTerrain.modify_zone(position,
GameTerrain.modify_zone_falloff(position,
parameter.distance_prod,
parameter.distance_prod_falloff,
GameTerrain.Stats.PRESENCE,
-parameter.presence_prod)
growing_timer.start(parameter.dead_time)
@@ -128,12 +138,14 @@ func die():
func remove(was_dead: bool = true):
if was_dead:
GameTerrain.modify_zone(position,
GameTerrain.modify_zone_falloff(position,
parameter.distance_prod,
parameter.distance_prod_falloff,
GameTerrain.Stats.WATER,
-parameter.dead_water_prod)
GameTerrain.modify_zone(position,
GameTerrain.modify_zone_falloff(position,
parameter.distance_prod,
parameter.distance_prod_falloff,
GameTerrain.Stats.FERTILITY,
-parameter.dead_fertility_prod)
queue_free()

View File

@@ -24,3 +24,4 @@ extends Resource
@export var dead_fertility_prod := 1
@export var distance_prod := 50
@export var distance_prod_falloff := 10

View File

@@ -122,6 +122,29 @@ func modify_zone(
)
update_texture()
func modify_zone_falloff(
center: Vector2,
radius: float,
falloff_extraradius: float,
stat : Stats,
modification: int
):
var pixel_center := map_to_pixel(center)
var pixel_radius := int(radius / MAP_RATIO)
var pixel_falloff_radius := int(falloff_extraradius / MAP_RATIO)
for x in range(pixel_center.x - pixel_radius - pixel_falloff_radius, pixel_center.x + pixel_radius + pixel_falloff_radius + 1) :
for y in range(pixel_center.y - pixel_radius - pixel_falloff_radius, pixel_center.y + pixel_radius + pixel_falloff_radius + 1):
if not is_on_map_image(Vector2i(x, y)):
continue
var pos := Vector2i(x, y)
var dist_to_center := pos.distance_to(pixel_center)
if dist_to_center <= pixel_radius:
modify_pixel(pos, stat, modification)
elif modification > 1 and dist_to_center <= pixel_radius + falloff_extraradius:
var new_modif = lerp(modification, 1, (dist_to_center - pixel_radius) / pixel_falloff_radius)
modify_pixel(pos, stat, new_modif)
update_texture()
func modify_rect(
pos: Vector2,
size: Vector2,
@@ -145,14 +168,19 @@ func get_color(
var pixel_pos = map_to_pixel(pos)
return image.get_pixelv(pixel_pos)
func get_levels(
pos: Vector2,
) -> Vector3i:
if not is_on_map_real(pos):
return Vector3i()
var pixel_pos = map_to_pixel(pos)
return color_to_levels(image.get_pixelv(pixel_pos))
func get_stat(
pos: Vector2,
stat : Stats
) -> int:
if not is_on_map_real(pos):
return 0
var pixel_pos = map_to_pixel(pos)
var levels = color_to_levels(image.get_pixelv(pixel_pos))
var levels = get_levels(pos)
match stat:
Stats.WATER:
return levels.x

View File

@@ -2,7 +2,7 @@ extends Control
var texts = [
"Hi there !",
"Welcome to GJ 238 b, it was a nice and hospitable exoplanet, but the humans settled in and ruined this place.",
"Welcome to MJ 166 b, it was a nice and hospitable exoplanet, but the humans settled in and ruined this place.",
"Now nothing grows, and the animals won't show up !",
"You got to help me with this, I prepared a lot of seeds, you just have to click and I'll plant.",
"The problem is that the place is quite inhospitable, each plant needs a special amount of water, a certain quality of ground (the fertility), and more or less space (population).",