ajout de la plant champ et suppression de la texture planted (ajout de la graine à la place) #55

This commit is contained in:
2025-09-12 12:13:29 +02:00
parent 65385c2b16
commit 4fd29db291
21 changed files with 174 additions and 74 deletions

View File

@@ -1,18 +1,42 @@
extends Node2D
class_name PlantSprite
const PLANTED_SEED_CROP_WIDTH = 50
const PLANTED_SEED_POS_Y = -50
signal harvest_animation_finished
@onready var sprite = $Sprite2D
func apply_texture_to_sprite(texture, with_animation = true):
func update_plant_sprite(plant : Plant, with_animation = false):
if with_animation:
$AnimationPlayer.play("bump")
await $AnimationPlayer.animation_finished
sprite.texture = texture
sprite.flip_h = true if randi()%2 == 0 else false
%Sprite.flip_h = true if randi()%2 == 0 else false
%Sprite.texture = get_state_texture(plant.state, plant.plant_type)
%PlantedSeed.visible = plant.state == Plant.State.PLANTED
%PlantedSeed.texture = plant.plant_type.seed_texture
%PlantedSeed.region_rect = Rect2(
0,
PLANTED_SEED_POS_Y,
plant.plant_type.seed_texture.get_width(),
plant.plant_type.seed_texture.get_height() - PLANTED_SEED_CROP_WIDTH + -1 * PLANTED_SEED_POS_Y,
)
func get_state_texture(s: Plant.State, plant_type : PlantType) -> Texture2D:
match s:
Plant.State.PLANTED:
return null
Plant.State.GROWING:
return plant_type.growing_texture
Plant.State.MATURE:
return plant_type.mature_texture
return null
func start_harvest_animation():
$AnimationPlayer.play("harvest")
await $AnimationPlayer.animation_finished
harvest_animation_finished.emit()
harvest_animation_finished.emit()