#20 #26 ajout d'une autre plante et de la mécanique de récolte, avec plusieurs graines possibles

This commit is contained in:
2025-08-20 09:31:40 +02:00
parent 1f301815be
commit 9de869b7af
20 changed files with 414 additions and 42 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dwr3c6r6piwaa"
path="res://.godot/imported/growing.png-7b76a9f596f5cec79fdd8685670b16b5.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://entities/plants/assets/sprites/maias/growing.png"
dest_files=["res://.godot/imported/growing.png-7b76a9f596f5cec79fdd8685670b16b5.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://d3apfwbqsg5ha"
path="res://.godot/imported/mature.png-8766aea5da569488db27850c55c8418b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://entities/plants/assets/sprites/maias/mature.png"
dest_files=["res://.godot/imported/mature.png-8766aea5da569488db27850c55c8418b.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cpx7bkrvttasr"
path="res://.godot/imported/planted.png-4bf3c8ff7d8aae08d7e3691f7e49cab2.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://entities/plants/assets/sprites/maias/planted.png"
dest_files=["res://.godot/imported/planted.png-4bf3c8ff7d8aae08d7e3691f7e49cab2.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -0,0 +1,130 @@
[gd_scene load_steps=7 format=3 uid="uid://2hrg6yjk0yt0"]
[ext_resource type="Script" uid="uid://bmjjpk4lvijws" path="res://entities/plants/scripts/plant_sprite.gd" id="1_pq8o7"]
[ext_resource type="Texture2D" uid="uid://b3wom2xu26g43" path="res://entities/plants/assets/sprites/default_plant_glowing.png" id="2_hyinx"]
[sub_resource type="Animation" id="Animation_rbgiq"]
resource_name = "harvest"
length = 0.2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:skew")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [0.0, -0.698132, 0.698132]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite2D:modulate")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0.133333, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0)]
}
[sub_resource type="Animation" id="Animation_j6jm5"]
resource_name = "bump"
length = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:scale")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.233333, 0.5),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector2(0.15, 0.15), Vector2(0.15, 0.075), Vector2(0.15, 0.15)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite2D:position")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.233333, 0.5),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector2(0, 0), Vector2(0, 17.475), Vector2(0, 0)]
}
[sub_resource type="Animation" id="Animation_wyuub"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0.15, 0.15)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Sprite2D:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0, 0)]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("Sprite2D:skew")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [0.0]
}
tracks/3/type = "value"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("Sprite2D:modulate")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_8eofq"]
_data = {
&"RESET": SubResource("Animation_wyuub"),
&"bump": SubResource("Animation_j6jm5"),
&"harvest": SubResource("Animation_rbgiq")
}
[node name="PlantSprite" type="Node2D"]
script = ExtResource("1_pq8o7")
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.15, 0.15)
texture = ExtResource("2_hyinx")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_8eofq")
}

View File

@@ -26,4 +26,6 @@ planted_texture = ExtResource("4_2s6re")
growing_texture = ExtResource("1_fp5j6")
mature_texture = ExtResource("3_ffarr")
mature_effect = SubResource("Resource_q68uy")
harvest_types_path = Array[String]([])
harvest_number = Array[int]([1, 2])
metadata/_custom_type_script = "uid://jnye5pe1bgqw"

View File

@@ -0,0 +1,24 @@
[gd_resource type="Resource" script_class="PlantType" load_steps=7 format=3 uid="uid://dsctivn1vrem2"]
[ext_resource type="Script" uid="uid://jnye5pe1bgqw" path="res://entities/plants/scripts/plant_type.gd" id="1_eqtut"]
[ext_resource type="Texture2D" uid="uid://dwr3c6r6piwaa" path="res://entities/plants/assets/sprites/maias/growing.png" id="1_vyplc"]
[ext_resource type="Texture2D" uid="uid://d3apfwbqsg5ha" path="res://entities/plants/assets/sprites/maias/mature.png" id="3_pi4ie"]
[ext_resource type="Texture2D" uid="uid://cpx7bkrvttasr" path="res://entities/plants/assets/sprites/maias/planted.png" id="4_iqcy2"]
[ext_resource type="Texture2D" uid="uid://pltmnkqd5ut2" path="res://entities/plants/assets/sprites/seeds/grille_seeds.png" id="6_mwrj8"]
[sub_resource type="AtlasTexture" id="AtlasTexture_sri3b"]
atlas = ExtResource("6_mwrj8")
region = Rect2(1697, 331, 125, 158)
[resource]
script = ExtResource("1_eqtut")
name = "Maias"
description = "This gorgeous flower has no effect, but produce a lot of seeds."
growing_time = 2
seed_texture = SubResource("AtlasTexture_sri3b")
planted_texture = ExtResource("4_iqcy2")
growing_texture = ExtResource("1_vyplc")
mature_texture = ExtResource("3_pi4ie")
harvest_types_path = Array[String](["uid://b04vho33bl52b", "uid://dsctivn1vrem2"])
harvest_number = Array[int]([3, 4])
metadata/_custom_type_script = "uid://jnye5pe1bgqw"

View File

@@ -3,31 +3,37 @@ class_name Plant
const PLANT_AREA_WIDTH = 10
const PLANT_SPRITE_SCALE = 0.15
const HARVESTED_SEED_POSITION_RANGE = 100
const RANDOM_MAX_GROW_INTERVAL = 0.4
const SPRITE_SCENE : PackedScene = preload("res://entities/plants/plant_sprite.tscn")
enum State {PLANTED, GROWING, MATURE}
@export var plant_type : PlantType
@export var planet : Planet
@export var plant_type: PlantType
@export var planet: Planet
var state : State = State.PLANTED : set = change_state
var day : int = 0
var state: State = State.PLANTED: set = change_state
@export var day: int = 0 : set = set_day
@onready var plant_sprite : Sprite2D = generate_sprite()
@onready var collision_shape : CollisionShape2D = generate_collision_shape()
@onready var plant_sprite: PlantSprite = generate_sprite()
@onready var collision_shape: CollisionShape2D = generate_collision_shape()
func _init(_plant_type = null, _planet = null):
plant_type = _plant_type
planet = _planet
func generate_sprite() -> Sprite2D:
var sprite = Sprite2D.new()
func generate_sprite() -> PlantSprite:
var spriteObject : PlantSprite = SPRITE_SCENE.instantiate()
add_child(sprite)
sprite.texture = get_state_texture(state)
sprite.scale = Vector2.ONE * PLANT_SPRITE_SCALE
sprite.offset
add_child(spriteObject)
spriteObject.apply_texture_to_sprite(
get_state_texture(state),
false
)
return sprite
return spriteObject
func generate_collision_shape() -> CollisionShape2D:
var collision = CollisionShape2D.new()
@@ -40,20 +46,29 @@ func generate_collision_shape() -> CollisionShape2D:
return collision
func pass_day():
await get_tree().create_timer(randf_range(0., RANDOM_MAX_GROW_INTERVAL)).timeout
day += 1
func set_day(d):
day = d
if day == 0:
change_state(State.PLANTED)
if day > plant_type.growing_time:
change_state(State.MATURE)
else:
change_state(State.GROWING)
func change_state(_state : State):
func change_state(_state: State):
state = _state
plant_sprite.texture = get_state_texture(state)
if state == State.MATURE and plant_type.mature_effect:
plant_type.mature_effect.effect(self)
func get_state_texture(s : State) -> Texture2D:
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
@@ -64,8 +79,27 @@ func get_state_texture(s : State) -> Texture2D:
return null
func harvest():
day += 1
if day > plant_type.growing_time:
change_state(State.MATURE)
else:
change_state(State.GROWING)
if state == State.MATURE:
var seed_number = plant_type.harvest_number.pick_random()
for i in range(seed_number):
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
)
plant_sprite.start_harvest_animation()
await plant_sprite.harvest_animation_finished
queue_free()

View File

@@ -0,0 +1,17 @@
extends Node2D
class_name PlantSprite
signal harvest_animation_finished
@onready var sprite = $Sprite2D
func apply_texture_to_sprite(texture, with_animation = true):
if with_animation:
$AnimationPlayer.play("bump")
await $AnimationPlayer.animation_finished
sprite.texture = texture
func start_harvest_animation():
$AnimationPlayer.play("harvest")
await $AnimationPlayer.animation_finished
harvest_animation_finished.emit()

View File

@@ -0,0 +1 @@
uid://bmjjpk4lvijws

View File

@@ -11,4 +11,7 @@ class_name PlantType
@export var growing_texture : Texture
@export var mature_texture : Texture
@export var mature_effect : PlantEffect
@export var mature_effect : PlantEffect
@export_file var harvest_types_path : Array[String] = []
@export var harvest_number : Array[int] = [1,2]