minijam-166/scripts/planter.gd
2024-08-31 19:16:11 +02:00

21 lines
542 B
GDScript

class_name Planter
extends Node
@export var plants: Array[PlantType]
@onready var plant_scene = preload("res://objects/Plant.tscn")
@onready var timer: Timer = $Timer
@export var camera: Camera2D
func _unhandled_input(event: InputEvent) -> void:
if Input.is_action_just_pressed("plant") and timer.is_stopped():
var chosen_type: PlantType = plants[randi_range(0, plants.size() - 1)]
var plant = plant_scene.instantiate()
add_child(plant)
plant.init(chosen_type)
plant.plant(camera.get_global_mouse_position())
timer.start()