TinyAdventure/objects/grass.gd

43 lines
1.1 KiB
GDScript
Raw Normal View History

@tool
extends Node3D
2024-11-01 18:07:23 +01:00
@export var seed_drop_rate:float = 1.0
@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
# 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)
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
is_chopped = true
grow_timer.start()
2024-11-01 18:07:23 +01:00
item_spawner.spawn()
func _on_grow_timer_timeout() -> void:
if is_chopped:
is_chopped = false