plant tester + shado assets
This commit is contained in:
@@ -1,20 +1,71 @@
|
||||
extends Node
|
||||
|
||||
@export var n_plants_to_generate: int
|
||||
@export var n_plants_to_generate: int = 1
|
||||
@export var n_plants_per_row: int = 0
|
||||
@export var n_mutation_per_plant: int
|
||||
@export var space_between_plants: float
|
||||
@export var randomize_pos: bool
|
||||
@export var random_pos_offset: float
|
||||
|
||||
func _ready():
|
||||
%ZoomLevel.value = %Camera2D.zoom.x
|
||||
%NPlants.value = n_plants_to_generate
|
||||
%NMutationsPerPlant.value = n_mutation_per_plant
|
||||
%RandomizePos.button_pressed = randomize_pos
|
||||
%RandomizeOffset.value = random_pos_offset
|
||||
generate_plants();
|
||||
|
||||
func _input(_event) -> void:
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
%Camera2D.position += 1 / %Camera2D.zoom.x * 10 * input_dir
|
||||
|
||||
|
||||
func generate_plants():
|
||||
for child in %Plants.get_children():
|
||||
child.free()
|
||||
|
||||
for i in n_plants_to_generate:
|
||||
print("Generate plant")
|
||||
var plant_position := Vector2(i * space_between_plants, 0)
|
||||
var plant_pos_x = (i % n_plants_per_row) * space_between_plants
|
||||
@warning_ignore("integer_division")
|
||||
var plant_pos_y = (i / n_plants_per_row) * space_between_plants
|
||||
var plant_position := Vector2(plant_pos_x, plant_pos_y)
|
||||
if randomize_pos:
|
||||
plant_position += randf_range(0, random_pos_offset) * Vector2.ONE.rotated(randf_range(0, 2 * PI))
|
||||
var plant_data: PlantData = PlantData.new(plant_position)
|
||||
plant_data.day = plant_data.get_growing_time()
|
||||
plant_data.mutations.append(plant_data.archetype.available_mutations.pick_random())
|
||||
plant_data.mutations.append(plant_data.archetype.available_mutations.pick_random())
|
||||
plant_data.mutations.append(plant_data.archetype.available_mutations.pick_random())
|
||||
for j in n_mutation_per_plant:
|
||||
plant_data.mutations.append(plant_data.archetype.available_mutations.pick_random())
|
||||
var plant: Plant = Plant.new(plant_data)
|
||||
add_child(plant)
|
||||
%Plants.add_child(plant)
|
||||
plant.set_owner(self )
|
||||
plant.global_position = plant_position
|
||||
|
||||
|
||||
func _on_generate_plants_pressed() -> void:
|
||||
generate_plants()
|
||||
|
||||
|
||||
func _on_zoom_level_value_changed(value: float) -> void:
|
||||
%Camera2D.zoom = Vector2.ONE * value
|
||||
|
||||
|
||||
func _on_reset_zoom_pressed() -> void:
|
||||
%Camera2D.zoom = Vector2.ONE
|
||||
%ZoomLevel.value = 1
|
||||
|
||||
|
||||
func _on_n_plants_value_changed(value: float) -> void:
|
||||
n_plants_to_generate = int(value)
|
||||
|
||||
func _on_n_plants_per_row_value_changed(value: float) -> void:
|
||||
n_plants_per_row = int(value)
|
||||
|
||||
func _on_n_mutations_per_plant_value_changed(value: float) -> void:
|
||||
n_mutation_per_plant = int(value)
|
||||
|
||||
func _on_randomize_pos_toggled(toggled_on: bool) -> void:
|
||||
randomize_pos = toggled_on
|
||||
|
||||
func _on_randomize_offset_value_changed(value: float) -> void:
|
||||
random_pos_offset = value
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extends Resource
|
||||
class_name PlantAttach
|
||||
|
||||
enum AttachType {ORANGE_ATTACH, BLUE_ATTACH, PINK_ATTACH}
|
||||
enum AttachType {ORANGE_ATTACH, PURPLE_ATTACH, BLUE_ATTACH, PINK_ATTACH}
|
||||
|
||||
@export var position: Vector2
|
||||
@export var attach_types: Array[AttachType]
|
||||
|
||||
@@ -27,6 +27,7 @@ func load_resource():
|
||||
for i in maxi(attaches_children.size(), plant_part.attaches.size()):
|
||||
if i < attaches_children.size() && i < plant_part.attaches.size():
|
||||
attaches_children[i].position = plant_part.attaches[i].position
|
||||
attaches_children[i].attach_types = plant_part.attaches[i].attach_types
|
||||
elif i >= attaches_children.size():
|
||||
var new_child = PlantAttachBuilder.new()
|
||||
new_child.name = "attach" + str(i)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extends Node
|
||||
|
||||
const IMAGE_WIDTH := 1000
|
||||
const IMAGE_HEIGHT := 2000
|
||||
const IMAGE_WIDTH := 1024
|
||||
const IMAGE_HEIGHT := 2048
|
||||
|
||||
const PLACEHOLDER_SEED_TEXTURE: Texture = preload("res://entities/plants/assets/sprites/default/seed.png")
|
||||
const PLACEHOLDER_MATURE_TEXTURE: Texture = preload("res://entities/plants/assets/sprites/default/mature.png")
|
||||
@@ -12,6 +12,7 @@ const PLACEHOLDER_GROWING_TEXTURE: Texture = preload("res://entities/plants/asse
|
||||
@export var baby_bases: Array[PlantPart]
|
||||
@export var branches: Array[PlantPart]
|
||||
@export var n_branches: int = 2
|
||||
@export var base_leaves: Array[PlantPart]
|
||||
@export var parts_mutation_associations: Dictionary[String, PartMutationAssociation]
|
||||
|
||||
var rng := RandomNumberGenerator.new()
|
||||
@@ -47,7 +48,7 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
|
||||
match plant_data.get_state():
|
||||
PlantData.State.MATURE:
|
||||
print("Build mature texture")
|
||||
# print("Build mature texture")
|
||||
# var plant_archetype := plant_data.archetype
|
||||
if bases.size() == 0:
|
||||
printerr("No base in archetype")
|
||||
@@ -67,7 +68,7 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
parts_to_place.append(pick_random(branches))
|
||||
|
||||
for m in plant_data.mutations:
|
||||
print("mutations: ", m.id)
|
||||
# print("mutations: ", m.id)
|
||||
var association: PartMutationAssociation = parts_mutation_associations[m.id]
|
||||
var mutation_possible_parts := association.parts
|
||||
for p in association.part_amount:
|
||||
@@ -75,7 +76,7 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
|
||||
|
||||
PlantData.State.GROWING:
|
||||
print("Build growing texture")
|
||||
# print("Build growing texture")
|
||||
# var plant_archetype := plant_data.archetype
|
||||
if baby_bases.size() == 0:
|
||||
printerr("No baby base in archetype")
|
||||
@@ -89,7 +90,7 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
mature_image.blend_rect(base_image, Rect2i(Vector2i.ZERO, base_image.get_size()), base_image_coord - base_image_center)
|
||||
|
||||
for m in plant_data.mutations:
|
||||
print("mutations: ", m.id)
|
||||
# print("mutations: ", m.id)
|
||||
var association: PartMutationAssociation = parts_mutation_associations[m.id]
|
||||
var mutation_possible_parts := association.parts
|
||||
for p in ceil(0.5 * association.part_amount):
|
||||
@@ -103,13 +104,14 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
parent_image_coords.fill(base_image_coord)
|
||||
|
||||
for part: PlantPart in parts_to_place:
|
||||
print("Add part : ", part.resource_name)
|
||||
# print("Add part : ", part.resource_name)
|
||||
var ind := find_random_matching_attach_ind(part.root, available_attaches)
|
||||
if ind == -1:
|
||||
printerr("No attach found")
|
||||
continue
|
||||
|
||||
var attach: PlantAttach = available_attaches.pop_at(ind)
|
||||
|
||||
var parent_image_coord: Vector2i = parent_image_coords.pop_at(ind)
|
||||
|
||||
var part_image: Image = part.texture.get_image()
|
||||
@@ -128,4 +130,7 @@ func build_plant_texture(plant_data: PlantData) -> Texture:
|
||||
func find_random_matching_attach_ind(attach_to_match: PlantAttach, array: Array[PlantAttach]) -> int:
|
||||
var indices: Array = range(array.size())
|
||||
shuffle(indices)
|
||||
return indices.find_custom(func(i): return array[i].attach_types.any(func(type): return attach_to_match.attach_types.has(type)))
|
||||
for i in indices:
|
||||
if array[i].attach_types.any(func(type): return attach_to_match.attach_types.has(type)):
|
||||
return i
|
||||
return -1
|
||||
|
||||
Reference in New Issue
Block a user