2024-11-01 11:51:59 +01:00
|
|
|
@tool
|
|
|
|
extends Node3D
|
|
|
|
|
2024-11-01 18:07:23 +01:00
|
|
|
@export var seed_drop_rate:float = 1.0
|
2024-11-01 11:51:59 +01:00
|
|
|
@export var is_chopped:bool = true:
|
|
|
|
get:
|
|
|
|
return is_chopped
|
|
|
|
set(value):
|
|
|
|
if value != is_chopped:
|
|
|
|
is_chopped = value
|
|
|
|
|
|
|
|
_update_geometry()
|
|
|
|
|
|
|
|
@onready var grass_large: Node3D = %grassLarge
|
|
|
|
@onready var grow_timer: Timer = %GrowTimer
|
2024-11-01 18:07:23 +01:00
|
|
|
@onready var item_spawner: ItemSpawner = %ItemSpawner
|
2024-11-01 11:51:59 +01:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready() -> void:
|
|
|
|
_update_geometry()
|
2024-11-01 18:07:23 +01:00
|
|
|
grow_timer.wait_time = grow_timer.wait_time + grow_timer.wait_time * 0.2 * (randf() - 0.5)
|
2024-11-01 11:51:59 +01:00
|
|
|
|
|
|
|
func _update_geometry() -> void:
|
|
|
|
if grass_large == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
if is_chopped:
|
|
|
|
grass_large.transform = Transform3D(Basis.IDENTITY, grass_large.position)
|
|
|
|
else:
|
|
|
|
grass_large.transform = Transform3D(Basis.IDENTITY.scaled(Vector3(1, 3, 1)), grass_large.position)
|
|
|
|
|
2024-11-01 18:07:23 +01:00
|
|
|
func _on_hitbox_area_shape_entered(_area_rid: RID, _area: Area3D, _area_shape_index: int, _local_shape_index: int) -> void:
|
|
|
|
if is_chopped:
|
|
|
|
return
|
|
|
|
|
2024-11-01 11:51:59 +01:00
|
|
|
is_chopped = true
|
|
|
|
grow_timer.start()
|
2024-11-01 18:07:23 +01:00
|
|
|
item_spawner.spawn()
|
2024-11-01 11:51:59 +01:00
|
|
|
|
|
|
|
func _on_grow_timer_timeout() -> void:
|
|
|
|
if is_chopped:
|
|
|
|
is_chopped = false
|