robot wanderer and liberation only once #6
@ -1,10 +1,11 @@
|
|||||||
[gd_scene load_steps=6 format=3 uid="uid://qpdlnll5pihe"]
|
[gd_scene load_steps=7 format=3 uid="uid://qpdlnll5pihe"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/planter.gd" id="1_l7lry"]
|
[ext_resource type="Script" path="res://scripts/planter.gd" id="1_l7lry"]
|
||||||
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="2_7h3ga"]
|
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="2_7h3ga"]
|
||||||
[ext_resource type="Resource" uid="uid://bgi2lo7kb3d2v" path="res://objects/plant_types/chardon.tres" id="3_lgbrc"]
|
[ext_resource type="Resource" uid="uid://bgi2lo7kb3d2v" path="res://objects/plant_types/chardon.tres" id="3_lgbrc"]
|
||||||
[ext_resource type="Resource" uid="uid://dnahox31xqy6l" path="res://objects/plant_types/peuplier.tres" id="4_tmfl1"]
|
[ext_resource type="Resource" uid="uid://dnahox31xqy6l" path="res://objects/plant_types/peuplier.tres" id="4_tmfl1"]
|
||||||
[ext_resource type="Resource" uid="uid://b6ufxuqdcgwmx" path="res://objects/plant_types/chene.tres" id="5_j34av"]
|
[ext_resource type="Resource" uid="uid://b6ufxuqdcgwmx" path="res://objects/plant_types/chene.tres" id="5_j34av"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://bp3c63qgkmi6o" path="res://objects/Robot.tscn" id="6_of7ri"]
|
||||||
|
|
||||||
[node name="Planter" type="Node2D"]
|
[node name="Planter" type="Node2D"]
|
||||||
y_sort_enabled = true
|
y_sort_enabled = true
|
||||||
@ -14,3 +15,12 @@ plants = Array[ExtResource("2_7h3ga")]([ExtResource("3_lgbrc"), ExtResource("4_t
|
|||||||
[node name="Timer" type="Timer" parent="."]
|
[node name="Timer" type="Timer" parent="."]
|
||||||
wait_time = 0.2
|
wait_time = 0.2
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
|
[node name="Robot" parent="." instance=ExtResource("6_of7ri")]
|
||||||
|
position = Vector2(0, -64)
|
||||||
|
|
||||||
|
[node name="RobotSeed" type="Sprite2D" parent="Robot"]
|
||||||
|
position = Vector2(0, 63)
|
||||||
|
scale = Vector2(0.5, 0.5)
|
||||||
|
|
||||||
|
[connection signal="Planted" from="Robot" to="." method="_on_robot_planted"]
|
||||||
|
|||||||
31
objects/Robot.tscn
Normal file
31
objects/Robot.tscn
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
[gd_scene load_steps=5 format=3 uid="uid://bp3c63qgkmi6o"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/robot.gd" id="1_4eix8"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b11jyrkhw7ebp" path="res://icon.svg" id="2_8ulyj"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dyuqq8v1tckrv" path="res://objects/Wanderer.tscn" id="2_mhqh4"]
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_jlahh"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("2_8ulyj")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"Walk",
|
||||||
|
"speed": 5.0
|
||||||
|
}]
|
||||||
|
|
||||||
|
[node name="Robot" type="Node2D"]
|
||||||
|
script = ExtResource("1_4eix8")
|
||||||
|
|
||||||
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
|
sprite_frames = SubResource("SpriteFrames_jlahh")
|
||||||
|
animation = &"Walk"
|
||||||
|
|
||||||
|
[node name="Planting" type="Timer" parent="."]
|
||||||
|
one_shot = true
|
||||||
|
|
||||||
|
[node name="Wanderer" parent="." node_paths=PackedStringArray("node_to_move") instance=ExtResource("2_mhqh4")]
|
||||||
|
node_to_move = NodePath("..")
|
||||||
|
|
||||||
|
[connection signal="timeout" from="Planting" to="." method="_on_planting_timeout"]
|
||||||
12
objects/Wanderer.tscn
Normal file
12
objects/Wanderer.tscn
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://dyuqq8v1tckrv"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/wanderer.gd" id="1_53svd"]
|
||||||
|
|
||||||
|
[node name="Wanderer" type="Node"]
|
||||||
|
script = ExtResource("1_53svd")
|
||||||
|
|
||||||
|
[node name="NewTarget" type="Timer" parent="."]
|
||||||
|
one_shot = true
|
||||||
|
autostart = true
|
||||||
|
|
||||||
|
[connection signal="timeout" from="NewTarget" to="." method="_on_new_target_timeout"]
|
||||||
@ -4,7 +4,7 @@
|
|||||||
[ext_resource type="Theme" uid="uid://dnebunkx13tbr" path="res://assets/gui/Text.tres" id="2_n5opx"]
|
[ext_resource type="Theme" uid="uid://dnebunkx13tbr" path="res://assets/gui/Text.tres" id="2_n5opx"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dpfe11wn04ntd" path="res://assets/gui/icons/watering-soil.svg" id="3_4sryb"]
|
[ext_resource type="Texture2D" uid="uid://dpfe11wn04ntd" path="res://assets/gui/icons/watering-soil.svg" id="3_4sryb"]
|
||||||
[ext_resource type="Texture2D" uid="uid://be2uusaqcpcpd" path="res://assets/gradients/Fertility.tres" id="4_5omu3"]
|
[ext_resource type="Texture2D" uid="uid://be2uusaqcpcpd" path="res://assets/gradients/Fertility.tres" id="4_5omu3"]
|
||||||
[ext_resource type="PackedScene" uid="uid://qjwtbyq2c87m" path="res://objects/gui/Stats_area.tscn" id="4_wwqbk"]
|
[ext_resource type="PackedScene" path="res://objects/gui/Stats_area.tscn" id="4_wwqbk"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cwowpvsoo3dey" path="res://assets/gradients/Water.tres" id="5_hwfmn"]
|
[ext_resource type="Texture2D" uid="uid://cwowpvsoo3dey" path="res://assets/gradients/Water.tres" id="5_hwfmn"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dgo81cisfryi1" path="res://assets/gui/icons/soil-alt.svg" id="6_4k6c3"]
|
[ext_resource type="Texture2D" uid="uid://dgo81cisfryi1" path="res://assets/gui/icons/soil-alt.svg" id="6_4k6c3"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bdg3ep75da6xd" path="res://assets/gui/icons/tree.svg" id="8_i3l01"]
|
[ext_resource type="Texture2D" uid="uid://bdg3ep75da6xd" path="res://assets/gui/icons/tree.svg" id="8_i3l01"]
|
||||||
|
|||||||
@ -68,7 +68,8 @@ color = Color(1, 1, 1, 0)
|
|||||||
texture_scale = Vector2(5, 5)
|
texture_scale = Vector2(5, 5)
|
||||||
polygon = PackedVector2Array(27, 788, 54, 1452, 1715, 1163, 1439, -501, -416, -340)
|
polygon = PackedVector2Array(27, 788, 54, 1452, 1715, 1163, 1439, -501, -416, -340)
|
||||||
|
|
||||||
[node name="Animals" type="Node" parent="."]
|
[node name="Animals" type="Node2D" parent="."]
|
||||||
|
y_sort_enabled = true
|
||||||
|
|
||||||
[node name="Animal" parent="Animals" instance=ExtResource("4_pkphc")]
|
[node name="Animal" parent="Animals" instance=ExtResource("4_pkphc")]
|
||||||
position = Vector2(2121, 394)
|
position = Vector2(2121, 394)
|
||||||
|
|||||||
@ -3,13 +3,16 @@ extends Node2D
|
|||||||
signal liberated
|
signal liberated
|
||||||
|
|
||||||
@export var plant_need: String
|
@export var plant_need: String
|
||||||
|
var libarated := false
|
||||||
|
|
||||||
func _on_area_2d_area_entered(area: Area2D) -> void:
|
func _on_area_2d_area_entered(area: Area2D) -> void:
|
||||||
var plant = area.get_parent()
|
var plant = area.get_parent()
|
||||||
if plant is Plant:
|
if plant is Plant and not liberated:
|
||||||
if plant_need == plant.parameter.type:
|
if plant_need == plant.parameter.type:
|
||||||
plant.grown.connect(tracked_plant_grew)
|
plant.grown.connect(tracked_plant_grew)
|
||||||
|
|
||||||
func tracked_plant_grew():
|
func tracked_plant_grew():
|
||||||
|
if liberated:
|
||||||
|
return
|
||||||
print("Liberated !!")
|
print("Liberated !!")
|
||||||
liberated.emit()
|
liberated.emit()
|
||||||
|
|||||||
@ -8,6 +8,8 @@ const QUEUE_LENGTH := 6 # ENORME
|
|||||||
|
|
||||||
@onready var plant_scene = preload("res://objects/Plant.tscn")
|
@onready var plant_scene = preload("res://objects/Plant.tscn")
|
||||||
@onready var timer: Timer = $Timer
|
@onready var timer: Timer = $Timer
|
||||||
|
@onready var robot: Robot = $Robot
|
||||||
|
@onready var robot_seed: Sprite2D = $Robot/RobotSeed
|
||||||
|
|
||||||
@export var plants: Array[PlantType]
|
@export var plants: Array[PlantType]
|
||||||
|
|
||||||
@ -44,15 +46,21 @@ func take_next_seed() -> PlantType:
|
|||||||
return plants[plant_ind]
|
return plants[plant_ind]
|
||||||
|
|
||||||
func _unhandled_input(_event: InputEvent) -> void:
|
func _unhandled_input(_event: InputEvent) -> void:
|
||||||
|
|
||||||
if Input.is_action_just_pressed("plant") :
|
if Input.is_action_just_pressed("plant") :
|
||||||
var mouse_pos = camera.get_global_mouse_position()
|
var mouse_pos = camera.get_global_mouse_position()
|
||||||
var click_on_map = GameTerrain.is_on_map(mouse_pos)
|
var click_on_map = GameTerrain.is_on_map(mouse_pos)
|
||||||
|
|
||||||
if can_plant and click_on_map and timer.is_stopped():
|
if can_plant and click_on_map and robot.state == robot.MoveState.IDLE:
|
||||||
var chosen_type: PlantType = take_next_seed()
|
var next_plant := plants[seed_queue.back()]
|
||||||
var plant = plant_scene.instantiate()
|
robot_seed.texture = next_plant.seed_sprite
|
||||||
add_child(plant)
|
robot.go_to(mouse_pos)
|
||||||
plant.init(chosen_type)
|
|
||||||
plant.plant(mouse_pos)
|
|
||||||
timer.start()
|
func _on_robot_planted() -> void:
|
||||||
|
var chosen_type: PlantType = take_next_seed()
|
||||||
|
var plant = plant_scene.instantiate()
|
||||||
|
add_child(plant)
|
||||||
|
plant.init(chosen_type)
|
||||||
|
plant.plant(robot.position)
|
||||||
|
timer.start()
|
||||||
|
robot_seed.texture = null
|
||||||
|
|||||||
47
scripts/robot.gd
Normal file
47
scripts/robot.gd
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
class_name Robot
|
||||||
|
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
enum MoveState { IDLE, MOVING, PLANTING }
|
||||||
|
|
||||||
|
const IDLE_SPEED := 75
|
||||||
|
const MOVE_SPEED := 500
|
||||||
|
const PLANTING_TIME := 1
|
||||||
|
const DIST_TO_PLANT_SQR := 100
|
||||||
|
|
||||||
|
signal Planted
|
||||||
|
|
||||||
|
@onready var wanderer: Wanderer = $Wanderer
|
||||||
|
@onready var planting: Timer = $Planting
|
||||||
|
|
||||||
|
var target_pos := Vector2()
|
||||||
|
|
||||||
|
var state := MoveState.IDLE
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
wanderer.speed = IDLE_SPEED
|
||||||
|
wanderer.move = false
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
match state:
|
||||||
|
MoveState.IDLE:
|
||||||
|
wanderer.move = true
|
||||||
|
MoveState.MOVING:
|
||||||
|
wanderer.move = false
|
||||||
|
position += position.direction_to(target_pos) * MOVE_SPEED * delta
|
||||||
|
if position.distance_squared_to(target_pos) < DIST_TO_PLANT_SQR:
|
||||||
|
state = MoveState.PLANTING
|
||||||
|
planting.start(PLANTING_TIME)
|
||||||
|
MoveState.PLANTING:
|
||||||
|
wanderer.move = false
|
||||||
|
|
||||||
|
|
||||||
|
func go_to(new_target_pos: Vector2):
|
||||||
|
state = MoveState.MOVING
|
||||||
|
target_pos = new_target_pos
|
||||||
|
|
||||||
|
|
||||||
|
func _on_planting_timeout() -> void:
|
||||||
|
Planted.emit()
|
||||||
|
state = MoveState.IDLE
|
||||||
22
scripts/wanderer.gd
Normal file
22
scripts/wanderer.gd
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
class_name Wanderer
|
||||||
|
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
const DIST_FROM_MOUSE := 1000.0
|
||||||
|
|
||||||
|
@onready var new_target: Timer = $NewTarget
|
||||||
|
|
||||||
|
@export var node_to_move: Node2D
|
||||||
|
@export var speed := 75
|
||||||
|
@export var move := false
|
||||||
|
@export var wait_time_min := 1.0
|
||||||
|
@export var wait_time_max := 2.0
|
||||||
|
var target_pos := Vector2()
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
if move:
|
||||||
|
node_to_move.position += node_to_move.position.direction_to(target_pos) * speed * delta
|
||||||
|
|
||||||
|
func _on_new_target_timeout() -> void:
|
||||||
|
target_pos = get_viewport().get_camera_2d().get_global_mouse_position() + (Vector2.RIGHT * DIST_FROM_MOUSE).rotated(randf_range(0, PI))
|
||||||
|
new_target.start(randf_range(wait_time_min, wait_time_max))
|
||||||
Loading…
Reference in New Issue
Block a user