ajout de la plant champ et suppression de la texture planted (ajout de la graine à la place) #55
This commit is contained in:
@@ -32,17 +32,14 @@ func inspector_info() -> Inspector.Info:
|
||||
return Inspector.Info.new(
|
||||
pointer_text(),
|
||||
plant_type.description,
|
||||
get_state_texture(State.MATURE)
|
||||
plant_type.mature_texture
|
||||
)
|
||||
|
||||
func generate_sprite() -> PlantSprite:
|
||||
var spriteObject : PlantSprite = SPRITE_SCENE.instantiate()
|
||||
|
||||
add_child(spriteObject)
|
||||
spriteObject.apply_texture_to_sprite(
|
||||
get_state_texture(state),
|
||||
false
|
||||
)
|
||||
spriteObject.update_plant_sprite(self)
|
||||
|
||||
return spriteObject
|
||||
|
||||
@@ -61,6 +58,9 @@ func _pass_day():
|
||||
await get_tree().create_timer(randf_range(0., RANDOM_MAX_GROW_INTERVAL)).timeout
|
||||
day += 1
|
||||
|
||||
if state == State.MATURE and plant_type.cyclic_effect:
|
||||
plant_type.cyclic_effect.effect(self)
|
||||
|
||||
func set_day(d):
|
||||
day = d
|
||||
if day == 0:
|
||||
@@ -78,19 +78,7 @@ func change_state(_state: State):
|
||||
if state == State.MATURE and plant_type.mature_effect:
|
||||
plant_type.mature_effect.effect(self)
|
||||
|
||||
plant_sprite.apply_texture_to_sprite(
|
||||
get_state_texture(state)
|
||||
)
|
||||
|
||||
func get_state_texture(s: State) -> Texture2D:
|
||||
match s:
|
||||
State.PLANTED:
|
||||
return plant_type.planted_texture
|
||||
State.GROWING:
|
||||
return plant_type.growing_texture
|
||||
State.MATURE:
|
||||
return plant_type.mature_texture
|
||||
return null
|
||||
plant_sprite.update_plant_sprite(self, true)
|
||||
|
||||
func harvest():
|
||||
if state == State.MATURE:
|
||||
@@ -99,21 +87,24 @@ func harvest():
|
||||
var seed_plant_type : PlantType = plant_type
|
||||
if len(plant_type.harvest_types_path):
|
||||
seed_plant_type = load(plant_type.harvest_types_path.pick_random())
|
||||
var item_object = planet.drop_item(
|
||||
Seed.new(seed_plant_type),
|
||||
global_position
|
||||
)
|
||||
var tween : Tween = get_tree().create_tween()
|
||||
tween.tween_property(
|
||||
item_object,
|
||||
"position",
|
||||
Vector2(
|
||||
item_object.position.x + randi()%HARVESTED_SEED_POSITION_RANGE,
|
||||
item_object.position.y + randi()%HARVESTED_SEED_POSITION_RANGE
|
||||
),
|
||||
0.2
|
||||
)
|
||||
loot_seed(seed_plant_type)
|
||||
|
||||
plant_sprite.start_harvest_animation()
|
||||
await plant_sprite.harvest_animation_finished
|
||||
queue_free()
|
||||
|
||||
func loot_seed(type : PlantType):
|
||||
var item_object = planet.drop_item(
|
||||
Seed.new(type),
|
||||
global_position
|
||||
)
|
||||
var tween : Tween = get_tree().create_tween()
|
||||
tween.tween_property(
|
||||
item_object,
|
||||
"position",
|
||||
Vector2(
|
||||
item_object.position.x + randi()%HARVESTED_SEED_POSITION_RANGE,
|
||||
item_object.position.y + randi()%HARVESTED_SEED_POSITION_RANGE
|
||||
),
|
||||
0.2
|
||||
)
|
||||
|
||||
11
entities/plants/scripts/plant_effects/produce_seeds.gd
Normal file
11
entities/plants/scripts/plant_effects/produce_seeds.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
extends PlantEffect
|
||||
class_name ProduceSeedsEffect
|
||||
|
||||
@export_file var produce_types_path : Array[String] = []
|
||||
@export var produce_number : Array[int] = [1]
|
||||
|
||||
func effect(plant):
|
||||
for _i in range(produce_number.pick_random()):
|
||||
if len(produce_types_path):
|
||||
var seed_plant_type = load(produce_types_path.pick_random())
|
||||
plant.loot_seed(seed_plant_type)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ceqx5va1ormau
|
||||
@@ -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()
|
||||
|
||||
@@ -7,11 +7,11 @@ class_name PlantType
|
||||
@export var growing_time : int
|
||||
|
||||
@export var seed_texture : Texture
|
||||
@export var planted_texture : Texture
|
||||
@export var growing_texture : Texture
|
||||
@export var mature_texture : Texture
|
||||
|
||||
@export var mature_effect : PlantEffect
|
||||
@export var cyclic_effect : PlantEffect
|
||||
|
||||
@export_file var harvest_types_path : Array[String] = []
|
||||
@export var harvest_number : Array[int] = [1,2]
|
||||
|
||||
Reference in New Issue
Block a user