plant type and spawner

This commit is contained in:
2024-08-31 16:22:45 +02:00
parent d1d3e48c38
commit ecb77e0535
9 changed files with 207 additions and 54 deletions

17
scenes/Planter.gd Normal file
View File

@@ -0,0 +1,17 @@
class_name Planter
extends Node2D
@export var plants: Array[PlantType]
@onready var plant_scene = preload("res://objects/plant.tscn")
func _input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.pressed:
if event.button_index == MOUSE_BUTTON_LEFT:
var chosen_type: PlantType = plants[randi_range(0, plants.size() - 1)]
var plant = plant_scene.instantiate()
add_child(plant)
plant.init(chosen_type, event.position)
plant.plant(event.position)

11
scenes/TestMapV.tscn Normal file
View File

@@ -0,0 +1,11 @@
[gd_scene load_steps=6 format=3 uid="uid://bus7qrxwn2ck1"]
[ext_resource type="Script" path="res://scenes/Planter.gd" id="1_l04h8"]
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="2_6g58k"]
[ext_resource type="Resource" uid="uid://bgi2lo7kb3d2v" path="res://objects/plant_types/chardon.tres" id="3_vfbum"]
[ext_resource type="Resource" uid="uid://dnahox31xqy6l" path="res://objects/plant_types/peuplier.tres" id="4_aqqqx"]
[ext_resource type="Resource" uid="uid://b6ufxuqdcgwmx" path="res://objects/plant_types/chene.tres" id="5_n7xs7"]
[node name="TestMap" type="Node2D"]
script = ExtResource("1_l04h8")
plants = Array[ExtResource("2_6g58k")]([ExtResource("3_vfbum"), ExtResource("4_aqqqx"), ExtResource("5_n7xs7")])