seed queue + seed card + distant spawn + reproduction
This commit is contained in:
12
scripts/game.gd
Normal file
12
scripts/game.gd
Normal file
@@ -0,0 +1,12 @@
|
||||
extends Node2D
|
||||
|
||||
@onready var gui: Gui = $Interface/Gui
|
||||
@onready var planter: Planter = $Planter
|
||||
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
|
||||
func _on_planter_seed_list_updated() -> void:
|
||||
pass # Replace with function body.
|
||||
@@ -3,5 +3,20 @@ extends Control
|
||||
|
||||
signal scanner_selected
|
||||
|
||||
@onready var seed_queue: Control = $MarginContainer/SeedQueue
|
||||
@onready var seed_card: Control = $MarginContainer/SeedCard
|
||||
|
||||
@export var planter: Planter
|
||||
|
||||
func _ready() -> void:
|
||||
seed_queue.planter = planter
|
||||
seed_card.planter = planter
|
||||
|
||||
|
||||
func _on_scanner_modes_scanner_selected(type : Scanners.Type):
|
||||
emit_signal("scanner_selected", type)
|
||||
|
||||
|
||||
func _on_planter_seed_list_updated() -> void:
|
||||
seed_queue.update_queue()
|
||||
seed_card.update_card()
|
||||
|
||||
15
scripts/gui/seed_card.gd
Normal file
15
scripts/gui/seed_card.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
extends Control
|
||||
|
||||
@onready var nom: Label = $Card/MarginContainer/VBoxContainer/Nom
|
||||
@onready var image: TextureRect = $Card/MarginContainer/VBoxContainer/Image
|
||||
@onready var besoins: Label = $Card/MarginContainer/VBoxContainer/Besoins
|
||||
@onready var apports: Label = $Card/MarginContainer/VBoxContainer/Apports
|
||||
|
||||
var planter: Planter
|
||||
|
||||
func update_card():
|
||||
var next_seed_param := planter.get_plant_from_queue()
|
||||
nom.text = next_seed_param.type
|
||||
image.texture = next_seed_param.sprite_frames.get_frame_texture("GROWN", 0)
|
||||
besoins.text = "w: [" + str(next_seed_param.water_need[0]) + ", " + str(next_seed_param.water_need[1]) + "]\nf: [" + str(next_seed_param.fertility_need[0]) + ", " + str(next_seed_param.fertility_need[1]) + "]"
|
||||
apports.text = "w: " + str(next_seed_param.water_prod) + "\nf: " + str(next_seed_param.fertility_prod)
|
||||
15
scripts/gui/seed_queue.gd
Normal file
15
scripts/gui/seed_queue.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
extends Control
|
||||
|
||||
@onready var next_seed: TextureRect = $HBoxContainer/NextSeed
|
||||
@onready var queue: HBoxContainer = $HBoxContainer/Queue
|
||||
|
||||
var planter: Planter
|
||||
|
||||
func update_queue():
|
||||
var next_seed_param := planter.get_plant_from_queue()
|
||||
next_seed.texture = next_seed_param.seed_sprite
|
||||
var index := 0
|
||||
for child in queue.get_children():
|
||||
var seed_param := planter.get_plant_from_queue(index)
|
||||
child.texture = seed_param.seed_sprite
|
||||
index += 1
|
||||
@@ -4,14 +4,17 @@ extends Resource
|
||||
|
||||
@export var type: String
|
||||
|
||||
@export var seed_sprite: AtlasTexture
|
||||
@export var sprite_frames: SpriteFrames
|
||||
|
||||
@export var growing_time := 1.0
|
||||
@export var dying_time := 30.0
|
||||
@export var offspring_per_lifetime := 1
|
||||
@export var dying_time := 30.0 # time to die
|
||||
@export var dead_time := 10.0 # time being dead
|
||||
|
||||
@export var water_need := [0, 0] # min max
|
||||
@export var fertility_need := [0, 0] # min max
|
||||
@export var presence_need := [0, 0] # min max
|
||||
@export var water_need := [-5, 5] # min max
|
||||
@export var fertility_need := [-5, 5] # min max
|
||||
@export var presence_need := [0, 10] # min max
|
||||
|
||||
@export var water_prod := 0
|
||||
@export var fertility_prod := 0
|
||||
@@ -19,4 +22,5 @@ extends Resource
|
||||
|
||||
@export var dead_water_prod := 0
|
||||
@export var dead_fertility_prod := 1
|
||||
|
||||
@export var distance_prod := 50
|
||||
|
||||
@@ -1,18 +1,50 @@
|
||||
class_name Planter
|
||||
|
||||
extends Node
|
||||
extends Node2D
|
||||
|
||||
@export var plants: Array[PlantType]
|
||||
signal seed_list_updated
|
||||
|
||||
const QUEUE_LENGTH := 6 # ENORME
|
||||
|
||||
@onready var plant_scene = preload("res://objects/Plant.tscn")
|
||||
@onready var timer: Timer = $Timer
|
||||
|
||||
@export var plants: Array[PlantType]
|
||||
|
||||
@export var camera: Camera2D
|
||||
|
||||
# index of the PlantType in plants
|
||||
var seed_queue: Array[int]
|
||||
var can_plant := true
|
||||
|
||||
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)]
|
||||
func get_plant_from_queue(index: int = -1) -> PlantType:
|
||||
if index == -1:
|
||||
return plants[seed_queue.back()]
|
||||
return plants[seed_queue[index]]
|
||||
|
||||
func _ready() -> void:
|
||||
for i in range(QUEUE_LENGTH):
|
||||
seed_queue.push_front(randi_range(0, plants.size() - 1))
|
||||
seed_list_updated.emit()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var space := get_world_2d().direct_space_state
|
||||
var parameters = PhysicsPointQueryParameters2D.new()
|
||||
parameters.position = camera.get_global_mouse_position()
|
||||
parameters.collide_with_areas = true
|
||||
parameters.collide_with_bodies = false
|
||||
var result := space.intersect_point(parameters, 1)
|
||||
can_plant = result.size() == 0
|
||||
|
||||
func take_next_seed() -> PlantType:
|
||||
var plant_ind: int = seed_queue.pop_back()
|
||||
seed_queue.push_front(randi_range(0, plants.size() - 1))
|
||||
seed_list_updated.emit()
|
||||
return plants[plant_ind]
|
||||
|
||||
func _unhandled_input(_event: InputEvent) -> void:
|
||||
if can_plant and Input.is_action_just_pressed("plant") and timer.is_stopped():
|
||||
var chosen_type: PlantType = take_next_seed()
|
||||
var plant = plant_scene.instantiate()
|
||||
add_child(plant)
|
||||
plant.init(chosen_type)
|
||||
|
||||
Reference in New Issue
Block a user