2023-01-07 22:56:57 +00:00
|
|
|
extends Node3D
|
2023-01-08 11:29:41 +00:00
|
|
|
class_name CropTile
|
2023-01-07 22:56:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
signal on_planted()
|
|
|
|
signal on_complete()
|
|
|
|
|
|
|
|
|
|
|
|
@onready var growth_timer: Timer = $GrowthTimer
|
|
|
|
@onready var sprout_mesh: MeshInstance3D = $Plant/Sprout
|
2023-01-08 06:41:28 +00:00
|
|
|
@onready var pop_sound: AudioStreamPlayer3D = $Pop
|
2023-01-08 09:01:13 +00:00
|
|
|
@onready var producer: Node3D = $Producer
|
2023-01-08 23:28:39 +00:00
|
|
|
@onready var plant_shape: CollisionShape3D = $Plant/PlantableArea
|
2023-01-08 09:01:13 +00:00
|
|
|
|
|
|
|
@export var produce_scene: PackedScene = preload("res://island/Pineapple.tscn")
|
|
|
|
|
2023-01-07 23:15:11 +00:00
|
|
|
@export var debug_growth: bool = false
|
2023-01-08 06:41:28 +00:00
|
|
|
@export var debug_growth_offset: float = 0.0;
|
2023-01-07 22:56:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
func plant():
|
2023-01-07 23:12:24 +00:00
|
|
|
if growth_timer.is_stopped():
|
|
|
|
growth_timer.start()
|
|
|
|
emit_signal("on_planted")
|
2023-01-07 22:56:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
func complete():
|
2023-01-08 12:09:34 +00:00
|
|
|
pop_sound.play_with_random_pitch()
|
|
|
|
producer.produce_with_random_force()
|
|
|
|
emit_signal("on_complete")
|
2023-01-07 23:15:11 +00:00
|
|
|
if debug_growth:
|
|
|
|
plant()
|
2023-01-08 23:28:39 +00:00
|
|
|
else:
|
|
|
|
plant_shape.disabled = true
|
|
|
|
await get_tree().create_timer(1).timeout
|
|
|
|
queue_free()
|
2023-01-07 22:56:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _process(_delta):
|
2023-01-08 12:09:34 +00:00
|
|
|
var scale_factor = 0
|
|
|
|
if not growth_timer.is_stopped():
|
2023-01-09 01:05:14 +00:00
|
|
|
scale_factor = 0.10 + 0.90 * (1 - growth_timer.time_left / growth_timer.wait_time)
|
2023-01-07 22:56:57 +00:00
|
|
|
sprout_mesh.scale = Vector3(scale_factor, scale_factor, scale_factor)
|
2023-01-07 23:15:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
if debug_growth:
|
2023-01-08 06:41:28 +00:00
|
|
|
growth_timer.start(growth_timer.wait_time - debug_growth_offset)
|