plant needs and adds

This commit was merged in pull request #5.
This commit is contained in:
2024-08-31 18:18:34 +02:00
parent 5f8052f0a3
commit 7949eb6489
19 changed files with 235 additions and 74 deletions

15
objects/Planter.tscn Normal file
View File

@@ -0,0 +1,15 @@
[gd_scene load_steps=6 format=3 uid="uid://qpdlnll5pihe"]
[ext_resource type="Script" path="res://scripts/planter.gd" id="1_l7lry"]
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="2_7h3ga"]
[ext_resource type="Resource" uid="uid://bgi2lo7kb3d2v" path="res://objects/plant_types/chardon.tres" id="3_lgbrc"]
[ext_resource type="Resource" uid="uid://dnahox31xqy6l" path="res://objects/plant_types/peuplier.tres" id="4_tmfl1"]
[ext_resource type="Resource" uid="uid://b6ufxuqdcgwmx" path="res://objects/plant_types/chene.tres" id="5_j34av"]
[node name="Planter" type="Node"]
script = ExtResource("1_l7lry")
plants = Array[ExtResource("2_7h3ga")]([ExtResource("3_lgbrc"), ExtResource("4_tmfl1"), ExtResource("5_j34av")])
[node name="Timer" type="Timer" parent="."]
wait_time = 0.2
one_shot = true

View File

View File

@@ -1,6 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://c4doyvo3mqgvl"]
[ext_resource type="Texture2D" uid="uid://biekl11dvnhgw" path="res://Victor_carre.jpg" id="1_x6d3i"]
[gd_scene load_steps=3 format=3 uid="uid://x4kv2y5f52cm"]
[sub_resource type="GDScript" id="GDScript_x3g5o"]
script/source = "class_name Plant
@@ -14,14 +12,39 @@ signal died
@onready var growing_timer: Timer = $Growing
@onready var sprite_node: AnimatedSprite2D = $AnimatedSprite2D
@onready var need_checker: Timer = $NeedChecker
const NEEDCHECKPERIOD := 1.0
var parameter: PlantType
var state := PlantState.SAPLING
var can_grow := true
func init(plant_parameter: PlantType):
parameter = plant_parameter
sprite_node.sprite_frames = parameter.sprite_frames
need_checker.start(NEEDCHECKPERIOD)
func _on_need_checker_timeout() -> void:
can_grow = check_terrain_viability()
growing_timer.paused = not can_grow
func check_terrain_viability() -> bool:
var water := GameTerrain.get_stat(position, GameTerrain.Stats.WATER)
if water < parameter.water_need[0] or water > parameter.water_need[1]:
return false
var fertility := GameTerrain.get_stat(position, GameTerrain.Stats.FERTILITY)
if fertility < parameter.fertility_need[0] or fertility > parameter.fertility_need[1]:
return false
var presence := GameTerrain.get_stat(position, GameTerrain.Stats.PRESENCE)
presence += GameTerrain.LEVELS_NUMBER / 2
if presence < parameter.presence_need[0] or parameter.presence_need[1]:
return false
return true
func _on_growing_timeout() -> void:
@@ -47,6 +70,18 @@ func grow():
return
state = PlantState.GROWN
growing_timer.start(parameter.dying_time)
GameTerrain.modify_zone(position,
parameter.distance_prod,
GameTerrain.Stats.WATER,
parameter.water_prod)
GameTerrain.modify_zone(position,
parameter.distance_prod,
GameTerrain.Stats.FERTILITY,
parameter.fertility_prod)
GameTerrain.modify_zone(position,
parameter.distance_prod,
GameTerrain.Stats.PRESENCE,
parameter.presence_prod)
grown.emit()
sprite_node.play(\"GROWN\")
@@ -60,10 +95,7 @@ func die():
[sub_resource type="SpriteFrames" id="SpriteFrames_667un"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_x6d3i")
}],
"frames": [],
"loop": true,
"name": &"SEED",
"speed": 5.0
@@ -73,10 +105,14 @@ animations = [{
script = SubResource("GDScript_x3g5o")
[node name="Growing" type="Timer" parent="."]
one_shot = true
[node name="NeedChecker" type="Timer" parent="."]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
scale = Vector2(0.0378561, 0.0378561)
scale = Vector2(0.2, 0.2)
sprite_frames = SubResource("SpriteFrames_667un")
animation = &"SEED"
[connection signal="timeout" from="Growing" to="." method="_on_growing_timeout"]
[connection signal="timeout" from="NeedChecker" to="." method="_on_need_checker_timeout"]

View File

@@ -1,26 +1,41 @@
[gd_resource type="Resource" script_class="PlantType" load_steps=4 format=3 uid="uid://bgi2lo7kb3d2v"]
[gd_resource type="Resource" script_class="PlantType" load_steps=7 format=3 uid="uid://bgi2lo7kb3d2v"]
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="1_i8xe4"]
[ext_resource type="Texture2D" uid="uid://b11jyrkhw7ebp" path="res://icon.svg" id="1_t42om"]
[ext_resource type="Texture2D" uid="uid://r1bq2tgt1yxf" path="res://assets/gamejam_plantes_props1.png" id="2_gaemm"]
[sub_resource type="AtlasTexture" id="AtlasTexture_fxqnu"]
atlas = ExtResource("2_gaemm")
region = Rect2(1920, 1620, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_sjq1e"]
atlas = ExtResource("2_gaemm")
region = Rect2(320, 1080, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_jsm3j"]
atlas = ExtResource("2_gaemm")
region = Rect2(0, 1080, 320, 540)
[sub_resource type="SpriteFrames" id="SpriteFrames_fxtnk"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_t42om")
"texture": SubResource("AtlasTexture_fxqnu")
}],
"loop": true,
"name": &"DEAD",
"speed": 5.0
}, {
"frames": [],
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_sjq1e")
}],
"loop": true,
"name": &"GROWN",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_t42om")
"texture": SubResource("AtlasTexture_jsm3j")
}],
"loop": true,
"name": &"SAPLING",
@@ -33,11 +48,12 @@ type = "Chardon"
sprite_frames = SubResource("SpriteFrames_fxtnk")
growing_time = 0.5
dying_time = 10.0
water_need = 5
soil_need = 0
distance_needed = 0.1
water_prod = 0
soil_prod = 0
water_need = [0, 0]
fertility_need = [0, 0]
presence_need = [0, 0]
water_prod = 1
fertility_prod = -1
presence_prod = 1
dead_water_prod = 0
dead_soil_prod = 1
distance_prod = 0.1
dead_fertility_prod = 1
distance_prod = 50

View File

@@ -1,24 +1,42 @@
[gd_resource type="Resource" script_class="PlantType" load_steps=4 format=3 uid="uid://b6ufxuqdcgwmx"]
[gd_resource type="Resource" script_class="PlantType" load_steps=7 format=3 uid="uid://b6ufxuqdcgwmx"]
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="1_meppe"]
[ext_resource type="Texture2D" uid="uid://b11jyrkhw7ebp" path="res://icon.svg" id="3_14y3x"]
[ext_resource type="Texture2D" uid="uid://r1bq2tgt1yxf" path="res://assets/gamejam_plantes_props1.png" id="2_jkmk8"]
[sub_resource type="AtlasTexture" id="AtlasTexture_vmgwa"]
atlas = ExtResource("2_jkmk8")
region = Rect2(2880, 1080, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_7r8et"]
atlas = ExtResource("2_jkmk8")
region = Rect2(2880, 540, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_oy8ng"]
atlas = ExtResource("2_jkmk8")
region = Rect2(3200, 0, 320, 540)
[sub_resource type="SpriteFrames" id="SpriteFrames_shufc"]
animations = [{
"frames": [],
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_vmgwa")
}],
"loop": true,
"name": &"DEAD",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("3_14y3x")
"texture": SubResource("AtlasTexture_7r8et")
}],
"loop": true,
"name": &"GROWN",
"speed": 5.0
}, {
"frames": [],
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_oy8ng")
}],
"loop": true,
"name": &"SAPLING",
"speed": 5.0
@@ -30,11 +48,12 @@ type = "Chene"
sprite_frames = SubResource("SpriteFrames_shufc")
growing_time = 50.0
dying_time = 100.0
water_need = 1
soil_need = 1
distance_needed = 0.1
water_need = [0, 0]
fertility_need = [0, 0]
presence_need = [0, 0]
water_prod = 1
soil_prod = 1
fertility_prod = 2
presence_prod = 1
dead_water_prod = 0
dead_soil_prod = 1
distance_prod = 0.1
dead_fertility_prod = 1
distance_prod = 50.0

View File

@@ -1,23 +1,41 @@
[gd_resource type="Resource" script_class="PlantType" load_steps=4 format=3 uid="uid://dnahox31xqy6l"]
[gd_resource type="Resource" script_class="PlantType" load_steps=7 format=3 uid="uid://dnahox31xqy6l"]
[ext_resource type="Texture2D" uid="uid://b11jyrkhw7ebp" path="res://icon.svg" id="1_b2cb6"]
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="1_mhtmv"]
[ext_resource type="Texture2D" uid="uid://r1bq2tgt1yxf" path="res://assets/gamejam_plantes_props1.png" id="2_gcjog"]
[sub_resource type="AtlasTexture" id="AtlasTexture_ncq3n"]
atlas = ExtResource("2_gcjog")
region = Rect2(0, 540, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_slfxf"]
atlas = ExtResource("2_gcjog")
region = Rect2(1280, 1080, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_gsxj4"]
atlas = ExtResource("2_gcjog")
region = Rect2(2240, 0, 320, 540)
[sub_resource type="SpriteFrames" id="SpriteFrames_d15np"]
animations = [{
"frames": [],
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_ncq3n")
}],
"loop": true,
"name": &"DEAD",
"speed": 5.0
}, {
"frames": [],
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_slfxf")
}],
"loop": true,
"name": &"GROWN",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_b2cb6")
"texture": SubResource("AtlasTexture_gsxj4")
}],
"loop": true,
"name": &"SAPLING",
@@ -30,11 +48,12 @@ type = "Peuplier"
sprite_frames = SubResource("SpriteFrames_d15np")
growing_time = 2.0
dying_time = 2.0
water_need = 0
soil_need = 0
distance_needed = 0.1
water_prod = 0
soil_prod = 0
water_need = [0, 0]
fertility_need = [0, 0]
presence_need = [0, 0]
water_prod = 2
fertility_prod = 2
presence_prod = 1
dead_water_prod = 0
dead_soil_prod = 1
distance_prod = 0.1
dead_fertility_prod = 1
distance_prod = 25.0