99 lines
2.1 KiB
Plaintext
99 lines
2.1 KiB
Plaintext
[gd_scene load_steps=2 format=3 uid="uid://c4dct5rm3sob2"]
|
|
|
|
[sub_resource type="GDScript" id="GDScript_x3g5o"]
|
|
script/source = "class_name Plant
|
|
|
|
extends StaticBody2D
|
|
|
|
enum PlantState { SEED, SAPLING, GROWN, DEAD}
|
|
|
|
signal grown
|
|
signal died
|
|
|
|
@onready var growing_timer: Timer = $Growing
|
|
|
|
@export var type: String
|
|
|
|
@export var sprites: Array[AnimatedSprite2D]
|
|
|
|
@export var state := PlantState.SEED
|
|
@export var growing_time := 1.0
|
|
@export var dying_time := 30.0
|
|
|
|
@export var water_need := 0
|
|
@export var soil_need := 0
|
|
@export var distance_needed := 0.1
|
|
|
|
@export var water_prod := 0:
|
|
get:
|
|
if state == PlantState.GROWN:
|
|
return water_prod
|
|
if state == PlantState.DEAD:
|
|
return dead_water_prod
|
|
return 0
|
|
|
|
@export var soil_prod := 0:
|
|
get:
|
|
if state == PlantState.GROWN:
|
|
return soil_prod
|
|
if state == PlantState.DEAD:
|
|
return dead_soil_prod
|
|
return 0
|
|
|
|
@export var dead_water_prod := 0
|
|
@export var dead_soil_prod := 1
|
|
@export var distance_prod := 0.1
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|
|
|
|
|
|
func _on_growing_timeout() -> void:
|
|
match state:
|
|
PlantState.SEED:
|
|
push_error(\"Not possible to timeout while a seed\")
|
|
PlantState.SAPLING:
|
|
grow()
|
|
PlantState.GROWN:
|
|
die()
|
|
PlantState.DEAD:
|
|
push_error(\"Already dead\")
|
|
|
|
|
|
func plant(new_position: Vector2):
|
|
if state != PlantState.SEED:
|
|
push_error(\"Tried to plant \" + type + \", but was not at seed state\")
|
|
return
|
|
position = new_position
|
|
state = PlantState.SAPLING
|
|
growing_timer.start(growing_time)
|
|
|
|
|
|
func grow():
|
|
if state != PlantState.SAPLING:
|
|
push_error(\"Tried to grow \" + type + \", but was not at sapling state\")
|
|
return
|
|
state = PlantState.GROWN
|
|
growing_timer.start(dying_time)
|
|
grown.emit()
|
|
|
|
|
|
func die():
|
|
state = PlantState.DEAD
|
|
died.emit()
|
|
|
|
"
|
|
|
|
[node name="Plant" type="StaticBody2D"]
|
|
script = SubResource("GDScript_x3g5o")
|
|
|
|
[node name="Growing" type="Timer" parent="."]
|
|
|
|
[connection signal="timeout" from="Growing" to="." method="_on_growing_timeout"]
|