Contours des plantes et collisions

* nouveaux sprites avec contours pour les plantes
* les sprites de plantes peuvent être aléatoirement flips
* ajout de collisions aux portes
This commit is contained in:
Altaezio
2026-03-21 12:32:56 +01:00
parent 4b16d52740
commit cdb8926d88
127 changed files with 2169 additions and 1111 deletions

View File

@@ -154,6 +154,9 @@ func update_nearby_plant():
data.nearby_plant_updated.emit()
func update_decontamination_area_factor():
if not region:
return
var factor = 0.
var full_decontaminated = true

View File

@@ -62,4 +62,8 @@ func set_display_lifetime_sprite(d := display_lifetime_sprite):
func set_sprite_modulate(c := sprite_modulate):
sprite_modulate = c
if is_node_ready():
%Sprite.modulate = c
%Sprite.modulate = c
func _on_body_entered(body: Node2D) -> void:
if body is Player && $AnimationPlayer.current_animation != "player_move":
$AnimationPlayer.play("player_move");

View File

@@ -1,7 +1,7 @@
extends Node
@export var n_to_generate: int = 5
@export var n_per_row: int = 5
@export var n_to_generate: int = 40
@export var n_per_row: int = 10
@export var n_mutation_per_plant: int
@export var space_between_plants: float
@export var randomize_pos: bool

View File

@@ -129,8 +129,11 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
parts_to_place[OriginType.MUTATION_ORIGIN].append(parts_mutation_associations[mutation.id].parts)
mutation_weights.append(mutation_weight_base)
var base_image_coord = blend_part(image_center, -base_part.root.position, base_part)
populate_part(parts_to_place, weight_per_origin_type, mutation_weights, base_part, base_image_coord)
var flipped: bool = rng.randi() % 2 == 0
flipped = false
var base_image_coord = blend_part(image_center, -base_part.root.position, base_part, flipped)
populate_part(parts_to_place, weight_per_origin_type, mutation_weights, base_part, base_image_coord, flipped)
texture = ImageTexture.create_from_image(image)
image.fill(Color.TRANSPARENT)
@@ -145,27 +148,33 @@ func find_random_matching_attach_ind(attach_to_match: PlantAttach, array: Array[
return i
return -1
func populate_part(all_parts: Dictionary[OriginType, Array], weight_per_origin_type: Array[int], mutation_weights: Array[int], parent_part: PlantPart, parent_image_coord: Vector2i):
var part_placed: Array[PlantPart] # same ind as their corresponding attach
func populate_part(all_parts: Dictionary[OriginType, Array], weight_per_origin_type: Array[int], mutation_weights: Array[int], parent_part: PlantPart, parent_image_coord: Vector2i, parent_is_flipped: bool):
var placed_parts: Array[PlantPart] # same ind as their corresponding attach
var part_image_coords: Array[Vector2i] # idem
var part_is_flipped: Array[bool]
# first find and blend parts per attach
for attach in parent_part.attaches:
# get part to place
var part_to_place := get_part(all_parts, weight_per_origin_type, mutation_weights, attach)
part_placed.append(part_to_place)
placed_parts.append(part_to_place)
part_is_flipped.append(rng.randi() % 2 == 0)
var attach_position := attach.position
if parent_is_flipped:
attach_position *= Vector2(-1, 1)
# blend part
if part_to_place:
var part_image_coord := blend_part(parent_image_coord, attach.position, part_to_place)
var part_image_coord := blend_part(parent_image_coord, attach_position, part_to_place, part_is_flipped.back())
part_image_coords.append(part_image_coord)
else:
part_image_coords.append(Vector2i.ZERO)
# then populate them
for i in range(part_placed.size()):
if part_placed[i] != null:
populate_part(all_parts, weight_per_origin_type, mutation_weights, part_placed[i], part_image_coords[i])
for i in range(placed_parts.size()):
if placed_parts[i] != null:
populate_part(all_parts, weight_per_origin_type, mutation_weights, placed_parts[i], part_image_coords[i], part_is_flipped[i])
func get_part(all_parts: Dictionary[OriginType, Array], weight_per_origin_type: Array[int], mutation_weights: Array[int], attach: PlantAttach) -> PlantPart:
@@ -199,11 +208,15 @@ func get_part(all_parts: Dictionary[OriginType, Array], weight_per_origin_type:
return parts_per_mutations[mutation_parts_ind][ind]
return null
func blend_part(parent_image_coord: Vector2i, attach_position: Vector2, part_to_blend: PlantPart) -> Vector2i:
var part_image: Image = part_to_blend.image
func blend_part(parent_image_coord: Vector2i, attach_position: Vector2, part_to_blend: PlantPart, is_flipped: bool) -> Vector2i:
var part_image := Image.create_from_data(part_to_blend.image.get_width(), part_to_blend.image.get_height(), false, Image.FORMAT_RGBA8, part_to_blend.image.get_data())
var part_root_position := part_to_blend.root.position
if is_flipped:
part_image.flip_x()
part_root_position *= Vector2(-1, 1)
var part_image_center: Vector2i = 0.5 * part_image.get_size()
var part_image_coord: Vector2i = parent_image_coord + Vector2i(attach_position - part_to_blend.root.position)
image.blend_rect(part_image, Rect2i(Vector2i.ZERO, part_to_blend.image.get_size()), part_image_coord - part_image_center)
var part_image_coord: Vector2i = parent_image_coord + Vector2i(attach_position - part_root_position)
image.blend_rect(part_image, Rect2i(Vector2i.ZERO, part_image.get_size()), part_image_coord - part_image_center)
return part_image_coord
func modulate_image(i: Image, color: Color):