plant type and spawner
This commit is contained in:
parent
d1d3e48c38
commit
ecb77e0535
@ -1,6 +1,4 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://c43sp458ssgj0"]
|
[gd_scene load_steps=3 format=3 uid="uid://d3srnfkpx01we"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Souris.gd" id="1_gdeo1"]
|
|
||||||
|
|
||||||
[sub_resource type="Gradient" id="Gradient_vr3vq"]
|
[sub_resource type="Gradient" id="Gradient_vr3vq"]
|
||||||
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 1)
|
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 1)
|
||||||
@ -11,7 +9,6 @@ gradient = SubResource("Gradient_vr3vq")
|
|||||||
[node name="Game" type="Node2D"]
|
[node name="Game" type="Node2D"]
|
||||||
|
|
||||||
[node name="Souris" type="Node2D" parent="."]
|
[node name="Souris" type="Node2D" parent="."]
|
||||||
script = ExtResource("1_gdeo1")
|
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="Souris"]
|
[node name="Sprite2D" type="Sprite2D" parent="Souris"]
|
||||||
scale = Vector2(0.0859375, 23)
|
scale = Vector2(0.0859375, 23)
|
||||||
|
|||||||
Binary file not shown.
@ -1,63 +1,31 @@
|
|||||||
[gd_scene load_steps=2 format=3 uid="uid://c4dct5rm3sob2"]
|
[gd_scene load_steps=4 format=3 uid="uid://c4doyvo3mqgvl"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://biekl11dvnhgw" path="res://Victor_carre.jpg" id="1_x6d3i"]
|
||||||
|
|
||||||
[sub_resource type="GDScript" id="GDScript_x3g5o"]
|
[sub_resource type="GDScript" id="GDScript_x3g5o"]
|
||||||
script/source = "class_name Plant
|
script/source = "class_name Plant
|
||||||
|
|
||||||
extends StaticBody2D
|
extends Node2D
|
||||||
|
|
||||||
enum PlantState { SEED, SAPLING, GROWN, DEAD}
|
enum PlantState { SAPLING, GROWN, DEAD}
|
||||||
|
|
||||||
signal grown
|
signal grown
|
||||||
signal died
|
signal died
|
||||||
|
|
||||||
@onready var growing_timer: Timer = $Growing
|
@onready var growing_timer: Timer = $Growing
|
||||||
|
@onready var sprite_node: AnimatedSprite2D = $AnimatedSprite2D
|
||||||
|
|
||||||
@export var type: String
|
var parameter: PlantType
|
||||||
|
var state := PlantState.SAPLING
|
||||||
@export var sprites: Array[AnimatedSprite2D]
|
|
||||||
|
|
||||||
@export var state := PlantState.SEED
|
|
||||||
@export var growing_time := 1.0
|
|
||||||
@export var dying_time := 30.0
|
|
||||||
|
|
||||||
@export var water_need := 0
|
|
||||||
@export var soil_need := 0
|
|
||||||
@export var distance_needed := 0.1
|
|
||||||
|
|
||||||
@export var water_prod := 0:
|
|
||||||
get:
|
|
||||||
if state == PlantState.GROWN:
|
|
||||||
return water_prod
|
|
||||||
if state == PlantState.DEAD:
|
|
||||||
return dead_water_prod
|
|
||||||
return 0
|
|
||||||
|
|
||||||
@export var soil_prod := 0:
|
|
||||||
get:
|
|
||||||
if state == PlantState.GROWN:
|
|
||||||
return soil_prod
|
|
||||||
if state == PlantState.DEAD:
|
|
||||||
return dead_soil_prod
|
|
||||||
return 0
|
|
||||||
|
|
||||||
@export var dead_water_prod := 0
|
|
||||||
@export var dead_soil_prod := 1
|
|
||||||
@export var distance_prod := 0.1
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready() -> void:
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
func init(plant_parameter: PlantType):
|
||||||
func _process(delta: float) -> void:
|
parameter = plant_parameter
|
||||||
pass
|
sprite_node.sprite_frames = parameter.sprite_frames
|
||||||
|
|
||||||
|
|
||||||
func _on_growing_timeout() -> void:
|
func _on_growing_timeout() -> void:
|
||||||
match state:
|
match state:
|
||||||
PlantState.SEED:
|
|
||||||
push_error(\"Not possible to timeout while a seed\")
|
|
||||||
PlantState.SAPLING:
|
PlantState.SAPLING:
|
||||||
grow()
|
grow()
|
||||||
PlantState.GROWN:
|
PlantState.GROWN:
|
||||||
@ -67,32 +35,48 @@ func _on_growing_timeout() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func plant(new_position: Vector2):
|
func plant(new_position: Vector2):
|
||||||
if state != PlantState.SEED:
|
|
||||||
push_error(\"Tried to plant \" + type + \", but was not at seed state\")
|
|
||||||
return
|
|
||||||
position = new_position
|
position = new_position
|
||||||
state = PlantState.SAPLING
|
state = PlantState.SAPLING
|
||||||
growing_timer.start(growing_time)
|
growing_timer.start(parameter.growing_time)
|
||||||
|
sprite_node.play(\"SAPLING\")
|
||||||
|
|
||||||
|
|
||||||
func grow():
|
func grow():
|
||||||
if state != PlantState.SAPLING:
|
if state != PlantState.SAPLING:
|
||||||
push_error(\"Tried to grow \" + type + \", but was not at sapling state\")
|
push_error(\"Tried to grow \" + parameter.type + \", but was not at sapling state\")
|
||||||
return
|
return
|
||||||
state = PlantState.GROWN
|
state = PlantState.GROWN
|
||||||
growing_timer.start(dying_time)
|
growing_timer.start(parameter.dying_time)
|
||||||
grown.emit()
|
grown.emit()
|
||||||
|
sprite_node.play(\"GROWN\")
|
||||||
|
|
||||||
|
|
||||||
func die():
|
func die():
|
||||||
state = PlantState.DEAD
|
state = PlantState.DEAD
|
||||||
died.emit()
|
died.emit()
|
||||||
|
sprite_node.play(\"DEAD\")
|
||||||
|
|
||||||
"
|
"
|
||||||
|
|
||||||
[node name="Plant" type="StaticBody2D"]
|
[sub_resource type="SpriteFrames" id="SpriteFrames_667un"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("1_x6d3i")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"SEED",
|
||||||
|
"speed": 5.0
|
||||||
|
}]
|
||||||
|
|
||||||
|
[node name="Plant" type="Node2D"]
|
||||||
script = SubResource("GDScript_x3g5o")
|
script = SubResource("GDScript_x3g5o")
|
||||||
|
|
||||||
[node name="Growing" type="Timer" parent="."]
|
[node name="Growing" type="Timer" parent="."]
|
||||||
|
|
||||||
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
|
scale = Vector2(0.0378561, 0.0378561)
|
||||||
|
sprite_frames = SubResource("SpriteFrames_667un")
|
||||||
|
animation = &"SEED"
|
||||||
|
|
||||||
[connection signal="timeout" from="Growing" to="." method="_on_growing_timeout"]
|
[connection signal="timeout" from="Growing" to="." method="_on_growing_timeout"]
|
||||||
|
|||||||
43
objects/plant_types/chardon.tres
Normal file
43
objects/plant_types/chardon.tres
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
[gd_resource type="Resource" script_class="PlantType" load_steps=4 format=3 uid="uid://bgi2lo7kb3d2v"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="1_i8xe4"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b11jyrkhw7ebp" path="res://icon.svg" id="1_t42om"]
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_fxtnk"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("1_t42om")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"DEAD",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"GROWN",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("1_t42om")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"SAPLING",
|
||||||
|
"speed": 5.0
|
||||||
|
}]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_i8xe4")
|
||||||
|
type = "Chardon"
|
||||||
|
sprite_frames = SubResource("SpriteFrames_fxtnk")
|
||||||
|
growing_time = 0.5
|
||||||
|
dying_time = 10.0
|
||||||
|
water_need = 5
|
||||||
|
soil_need = 0
|
||||||
|
distance_needed = 0.1
|
||||||
|
water_prod = 0
|
||||||
|
soil_prod = 0
|
||||||
|
dead_water_prod = 0
|
||||||
|
dead_soil_prod = 1
|
||||||
|
distance_prod = 0.1
|
||||||
40
objects/plant_types/chene.tres
Normal file
40
objects/plant_types/chene.tres
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
[gd_resource type="Resource" script_class="PlantType" load_steps=4 format=3 uid="uid://b6ufxuqdcgwmx"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="1_meppe"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b11jyrkhw7ebp" path="res://icon.svg" id="3_14y3x"]
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_shufc"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"DEAD",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("3_14y3x")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"GROWN",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"SAPLING",
|
||||||
|
"speed": 5.0
|
||||||
|
}]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_meppe")
|
||||||
|
type = "Chene"
|
||||||
|
sprite_frames = SubResource("SpriteFrames_shufc")
|
||||||
|
growing_time = 50.0
|
||||||
|
dying_time = 100.0
|
||||||
|
water_need = 1
|
||||||
|
soil_need = 1
|
||||||
|
distance_needed = 0.1
|
||||||
|
water_prod = 1
|
||||||
|
soil_prod = 1
|
||||||
|
dead_water_prod = 0
|
||||||
|
dead_soil_prod = 1
|
||||||
|
distance_prod = 0.1
|
||||||
40
objects/plant_types/peuplier.tres
Normal file
40
objects/plant_types/peuplier.tres
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
[gd_resource type="Resource" script_class="PlantType" load_steps=4 format=3 uid="uid://dnahox31xqy6l"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b11jyrkhw7ebp" path="res://icon.svg" id="1_b2cb6"]
|
||||||
|
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="1_mhtmv"]
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_d15np"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"DEAD",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"GROWN",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("1_b2cb6")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"SAPLING",
|
||||||
|
"speed": 5.0
|
||||||
|
}]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_mhtmv")
|
||||||
|
type = "Peuplier"
|
||||||
|
sprite_frames = SubResource("SpriteFrames_d15np")
|
||||||
|
growing_time = 2.0
|
||||||
|
dying_time = 2.0
|
||||||
|
water_need = 0
|
||||||
|
soil_need = 0
|
||||||
|
distance_needed = 0.1
|
||||||
|
water_prod = 0
|
||||||
|
soil_prod = 0
|
||||||
|
dead_water_prod = 0
|
||||||
|
dead_soil_prod = 1
|
||||||
|
distance_prod = 0.1
|
||||||
17
scenes/Planter.gd
Normal file
17
scenes/Planter.gd
Normal 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
11
scenes/TestMapV.tscn
Normal 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")])
|
||||||
21
scripts/plant_type.gd
Normal file
21
scripts/plant_type.gd
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
class_name PlantType
|
||||||
|
|
||||||
|
extends Resource
|
||||||
|
|
||||||
|
@export var type: String
|
||||||
|
|
||||||
|
@export var sprite_frames: SpriteFrames
|
||||||
|
|
||||||
|
@export var growing_time := 1.0
|
||||||
|
@export var dying_time := 30.0
|
||||||
|
|
||||||
|
@export var water_need := 0
|
||||||
|
@export var soil_need := 0
|
||||||
|
@export var distance_needed := 0.1
|
||||||
|
|
||||||
|
@export var water_prod := 0
|
||||||
|
@export var soil_prod := 0
|
||||||
|
|
||||||
|
@export var dead_water_prod := 0
|
||||||
|
@export var dead_soil_prod := 1
|
||||||
|
@export var distance_prod := 0.1
|
||||||
Loading…
Reference in New Issue
Block a user