Bee flying animation, dancing drone
This commit is contained in:
parent
7c3bca07f9
commit
bce75a9a97
13 changed files with 154 additions and 21 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=8 format=3 uid="uid://deek6uv574xas"]
|
[gd_scene load_steps=13 format=3 uid="uid://deek6uv574xas"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://entities/scripts/bee.gd" id="1_pnu7x"]
|
[ext_resource type="Script" path="res://entities/scripts/bee.gd" id="1_pnu7x"]
|
||||||
[ext_resource type="Script" path="res://entities/scripts/finite_state_machine.gd" id="1_t3s5d"]
|
[ext_resource type="Script" path="res://entities/scripts/finite_state_machine.gd" id="1_t3s5d"]
|
||||||
|
|
@ -6,14 +6,64 @@
|
||||||
[ext_resource type="Script" path="res://entities/bee/states/bee_gather.gd" id="5_4vs4l"]
|
[ext_resource type="Script" path="res://entities/bee/states/bee_gather.gd" id="5_4vs4l"]
|
||||||
[ext_resource type="Script" path="res://entities/scripts/bee_hit_box.gd" id="5_agq38"]
|
[ext_resource type="Script" path="res://entities/scripts/bee_hit_box.gd" id="5_agq38"]
|
||||||
[ext_resource type="Script" path="res://entities/bee/states/bee_travelling.gd" id="5_qtx0r"]
|
[ext_resource type="Script" path="res://entities/bee/states/bee_travelling.gd" id="5_qtx0r"]
|
||||||
|
[ext_resource type="Script" path="res://entities/bee/states/bee_sleeping.gd" id="7_6qlbu"]
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_t75ra"]
|
||||||
|
resource_name = "Idle"
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_iys4n"]
|
||||||
|
resource_name = "Flying"
|
||||||
|
length = 5.0
|
||||||
|
loop_mode = 1
|
||||||
|
step = 0.5
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Polygon2D:position")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 1.5, 2.5, 3.5, 5),
|
||||||
|
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
|
||||||
|
"update": 0,
|
||||||
|
"values": [Vector2(0, 0), Vector2(0, 10), Vector2(0, -10), Vector2(0, 10), Vector2(0, 0)]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_0encb"]
|
||||||
|
length = 0.001
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Polygon2D:position")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 0,
|
||||||
|
"values": [Vector2(0, 0)]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_m27po"]
|
||||||
|
_data = {
|
||||||
|
"Flying": SubResource("Animation_iys4n"),
|
||||||
|
"Idle": SubResource("Animation_t75ra"),
|
||||||
|
"RESET": SubResource("Animation_0encb")
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_86nxf"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_86nxf"]
|
||||||
radius = 22.0907
|
radius = 22.0907
|
||||||
|
|
||||||
[node name="Bee" type="CharacterBody2D"]
|
[node name="Bee" type="CharacterBody2D"]
|
||||||
|
z_index = 99
|
||||||
collision_mask = 0
|
collision_mask = 0
|
||||||
script = ExtResource("1_pnu7x")
|
script = ExtResource("1_pnu7x")
|
||||||
|
|
||||||
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||||
|
libraries = {
|
||||||
|
"": SubResource("AnimationLibrary_m27po")
|
||||||
|
}
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
light_mask = 0
|
light_mask = 0
|
||||||
shape = SubResource("CircleShape2D_86nxf")
|
shape = SubResource("CircleShape2D_86nxf")
|
||||||
|
|
@ -40,9 +90,16 @@ script = ExtResource("5_qtx0r")
|
||||||
[node name="Gathering" type="Node" parent="StateMachine"]
|
[node name="Gathering" type="Node" parent="StateMachine"]
|
||||||
script = ExtResource("5_4vs4l")
|
script = ExtResource("5_4vs4l")
|
||||||
|
|
||||||
|
[node name="Sleeping" type="Node" parent="StateMachine"]
|
||||||
|
script = ExtResource("7_6qlbu")
|
||||||
|
|
||||||
[node name="Polygon2D" type="Polygon2D" parent="."]
|
[node name="Polygon2D" type="Polygon2D" parent="."]
|
||||||
color = Color(1, 1, 0.0745098, 1)
|
color = Color(1, 1, 0.0745098, 1)
|
||||||
polygon = PackedVector2Array(-18, -11, -6, -21, 17, -19, 23, 1, 3, 12, -18, 7)
|
polygon = PackedVector2Array(-18, -11, -6, -21, 17, -19, 23, 1, 3, 12, -18, 7)
|
||||||
|
|
||||||
|
[node name="CPUParticles2D" type="CPUParticles2D" parent="Polygon2D"]
|
||||||
|
position = Vector2(0, 2.46663)
|
||||||
|
gravity = Vector2(0, 0)
|
||||||
|
|
||||||
[connection signal="area_entered" from="HitBox" to="HitBox" method="_on_area_entered"]
|
[connection signal="area_entered" from="HitBox" to="HitBox" method="_on_area_entered"]
|
||||||
[connection signal="area_exited" from="HitBox" to="HitBox" method="_on_area_exited"]
|
[connection signal="area_exited" from="HitBox" to="HitBox" method="_on_area_exited"]
|
||||||
|
|
|
||||||
22
entities/Beehive.tscn
Normal file
22
entities/Beehive.tscn
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://dyu4mucawjlu6"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://entities/scripts/beehive.gd" id="1_ej1r1"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_h6wmc"]
|
||||||
|
radius = 250.0
|
||||||
|
|
||||||
|
[node name="Beehive" type="Node2D"]
|
||||||
|
script = ExtResource("1_ej1r1")
|
||||||
|
|
||||||
|
[node name="BeehivePlaceholder" type="Polygon2D" parent="."]
|
||||||
|
position = Vector2(1, 0)
|
||||||
|
color = Color(0.588235, 0.423529, 0.423529, 1)
|
||||||
|
polygon = PackedVector2Array(-58, -56, 80, -30, 60, 78, -51, 108)
|
||||||
|
|
||||||
|
[node name="Area2D" type="Area2D" parent="."]
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||||
|
shape = SubResource("CircleShape2D_h6wmc")
|
||||||
|
|
||||||
|
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]
|
||||||
|
[connection signal="area_exited" from="Area2D" to="." method="_on_area_2d_area_exited"]
|
||||||
|
|
@ -1,11 +1,19 @@
|
||||||
[gd_scene load_steps=2 format=3 uid="uid://cx7cunaspu08a"]
|
[gd_scene load_steps=3 format=3 uid="uid://cx7cunaspu08a"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://entities/scripts/dancer_drone.gd" id="1_44a5b"]
|
[ext_resource type="Script" path="res://entities/scripts/dancer_drone.gd" id="1_44a5b"]
|
||||||
|
|
||||||
[node name="DancerDrone" type="Node2D"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_xfqbx"]
|
||||||
|
radius = 25.0
|
||||||
|
|
||||||
|
[node name="DancerDrone" type="Node2D" groups=["dancer"]]
|
||||||
script = ExtResource("1_44a5b")
|
script = ExtResource("1_44a5b")
|
||||||
|
|
||||||
[node name="Polygon2D" type="Polygon2D" parent="."]
|
[node name="Polygon2D" type="Polygon2D" parent="."]
|
||||||
position = Vector2(1, -1)
|
position = Vector2(1, -1)
|
||||||
color = Color(0.354435, 0.719091, 0.745333, 1)
|
color = Color(0.354435, 0.719091, 0.745333, 1)
|
||||||
polygon = PackedVector2Array(-28, -25, 25, -28, 26, 33, -32, 19)
|
polygon = PackedVector2Array(-28, -25, 25, -28, 26, 33, -32, 19)
|
||||||
|
|
||||||
|
[node name="HitBox" type="Area2D" parent="." groups=["dancer"]]
|
||||||
|
|
||||||
|
[node name="HitBoxShape" type="CollisionShape2D" parent="HitBox"]
|
||||||
|
shape = SubResource("CircleShape2D_xfqbx")
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ var time_at_patch : float = 0.0
|
||||||
|
|
||||||
func enter(_msg := {}):
|
func enter(_msg := {}):
|
||||||
Log.pr("I am going to attempt to gather some stuff!")
|
Log.pr("I am going to attempt to gather some stuff!")
|
||||||
|
bee.just_gathering = true
|
||||||
#animator.play("Idle")
|
#animator.play("Idle")
|
||||||
|
|
||||||
#if !bee.in_range_of_flowers:
|
#if !bee.in_range_of_flowers:
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ class_name BeeIdle
|
||||||
|
|
||||||
@export var animator : AnimationPlayer
|
@export var animator : AnimationPlayer
|
||||||
|
|
||||||
@onready var bee = get_parent().get_parent() # I think this is bad but I dont care it works
|
@onready var bee = get_parent().get_parent() as Bee # I think this is bad but I dont care it works
|
||||||
|
|
||||||
var idle_time : float = 0.0
|
var idle_time : float = 0.0
|
||||||
|
|
||||||
|
|
|
||||||
17
entities/bee/states/bee_sleeping.gd
Normal file
17
entities/bee/states/bee_sleeping.gd
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
extends State
|
||||||
|
class_name BeeSleeping
|
||||||
|
|
||||||
|
@onready var bee = get_parent().get_parent() as Bee # I think this is bad but I dont care it works
|
||||||
|
|
||||||
|
var time_at_patch : float = 0.0
|
||||||
|
|
||||||
|
func enter(_msg := {}):
|
||||||
|
Log.pr("BuzzzZZZzzzZZZZzzz (Sleeping)!")
|
||||||
|
#animator.play("Idle")
|
||||||
|
|
||||||
|
func update(_delta : float):
|
||||||
|
|
||||||
|
# If there is a dancing bee in range of the hive then
|
||||||
|
# we have a chance to wake up the bee...
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
extends State
|
extends State
|
||||||
class_name BeeTravelling
|
class_name BeeTravelling
|
||||||
|
|
||||||
@export var animator : AnimationPlayer
|
|
||||||
|
|
||||||
@export var target : Drone = null
|
@export var target : Drone = null
|
||||||
|
|
||||||
@onready var bee = get_parent().get_parent() as Bee # I think this is bad but I dont care it works
|
@onready var bee = get_parent().get_parent() as Bee # I think this is bad but I dont care it works
|
||||||
|
|
@ -12,13 +10,17 @@ var t = 0
|
||||||
func enter(_msg := {}):
|
func enter(_msg := {}):
|
||||||
Log.pr("I am on the move!")
|
Log.pr("I am on the move!")
|
||||||
## Get the next target location from the bee
|
## Get the next target location from the bee
|
||||||
target = bee.get_next_target()
|
if bee.just_gathering:
|
||||||
|
target = bee.get_current_director() # We want to go back the way we came
|
||||||
|
bee.just_gathering = false
|
||||||
|
else:
|
||||||
|
target = bee.get_next_target()
|
||||||
|
|
||||||
#animator.play("Idle")
|
bee.animation_player.play("Flying")
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func update(delta : float):
|
func update(delta : float) -> void:
|
||||||
|
|
||||||
if target:
|
if target:
|
||||||
if bee.position.distance_to(target.position) > 3:
|
if bee.position.distance_to(target.position) > 3:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ class_name Bee
|
||||||
|
|
||||||
@onready var fsm = $StateMachine as FiniteStateMachine
|
@onready var fsm = $StateMachine as FiniteStateMachine
|
||||||
@onready var drone_manager = get_tree().get_first_node_in_group("dronemanager") as DroneManager
|
@onready var drone_manager = get_tree().get_first_node_in_group("dronemanager") as DroneManager
|
||||||
|
@onready var animation_player = $AnimationPlayer as AnimationPlayer
|
||||||
|
|
||||||
@export var nectar : int = 0
|
@export var nectar : int = 0
|
||||||
@export var speed : int = 30
|
@export var speed : int = 30
|
||||||
|
|
@ -10,13 +11,20 @@ class_name Bee
|
||||||
var latest_target_director : int = 0
|
var latest_target_director : int = 0
|
||||||
|
|
||||||
# This is updated when the bee enters or exits a flower patch
|
# This is updated when the bee enters or exits a flower patch
|
||||||
var in_range_of_flowers : bool = false
|
var in_range_of_flowers : bool = false
|
||||||
|
var just_gathering : bool = false # Used to check if the bee has just been gathering to return to their previous director
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
|
||||||
|
speed = randi_range(35,55) # Randomise the bee speed a bit
|
||||||
|
|
||||||
Log.pr("I have never bee-n so ready!")
|
Log.pr("I have never bee-n so ready!")
|
||||||
|
|
||||||
Log.pr(fsm.current_state.name)
|
Log.pr(fsm.current_state.name)
|
||||||
|
|
||||||
|
func get_current_director():
|
||||||
|
return drone_manager.get_director(latest_target_director)
|
||||||
|
|
||||||
## Get the next target to move to
|
## Get the next target to move to
|
||||||
## If we have no nectar, we need to go up the director list
|
## If we have no nectar, we need to go up the director list
|
||||||
## If we have nectar, we need to go down the director list
|
## If we have nectar, we need to go down the director list
|
||||||
|
|
|
||||||
18
entities/scripts/beehive.gd
Normal file
18
entities/scripts/beehive.gd
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
extends Node2D
|
||||||
|
class_name Beehive
|
||||||
|
|
||||||
|
var dancer_in_range : bool = false
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
Log.pr("Beehive has joined the party")
|
||||||
|
|
||||||
|
func _on_area_2d_area_entered(area:Area2D):
|
||||||
|
Log.pr("Beehive: Area entered", area)
|
||||||
|
if area.is_in_group("dancer"):
|
||||||
|
dancer_in_range = true
|
||||||
|
print("Dancer in range")
|
||||||
|
|
||||||
|
func _on_area_2d_area_exited(area:Area2D):
|
||||||
|
if area.is_in_group("dancer"):
|
||||||
|
dancer_in_range = false
|
||||||
|
print("Dancer out of range")
|
||||||
|
|
@ -19,7 +19,6 @@ config/icon="res://icon.svg"
|
||||||
|
|
||||||
window/size/viewport_width=1280
|
window/size/viewport_width=1280
|
||||||
window/size/viewport_height=720
|
window/size/viewport_height=720
|
||||||
window/vsync/vsync_mode=0
|
|
||||||
|
|
||||||
[editor_plugins]
|
[editor_plugins]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,13 @@ func _ready():
|
||||||
func spawn_bee():
|
func spawn_bee():
|
||||||
var bee_instance = bee.instantiate()
|
var bee_instance = bee.instantiate()
|
||||||
add_child(bee_instance)
|
add_child(bee_instance)
|
||||||
bee_instance.position = beehive.position
|
bee_instance.position = beehive.global_position
|
||||||
# bee_instance.connect("bee_died", self, "bee_died")
|
# bee_instance.connect("bee_died", self, "bee_died")
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
spawn_timer += delta
|
spawn_timer += delta
|
||||||
|
|
||||||
if spawn_timer > spawn_interval and bee_count < max_bees:
|
if spawn_timer > spawn_interval and bee_count < max_bees and beehive.dancer_in_range:
|
||||||
spawn_bee()
|
spawn_bee()
|
||||||
spawn_timer = 0.0
|
spawn_timer = 0.0
|
||||||
bee_count += 1
|
bee_count += 1
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,12 @@ func update_director_drone_list():
|
||||||
|
|
||||||
Log.pr(director_drones.size())
|
Log.pr(director_drones.size())
|
||||||
|
|
||||||
|
func get_director(drone_number : int) -> DirectorDrone:
|
||||||
|
for drone in director_drones:
|
||||||
|
if drone.visit_order == drone_number:
|
||||||
|
return drone
|
||||||
|
return null
|
||||||
|
|
||||||
func get_next_director(current_director_number : int) -> DirectorDrone:
|
func get_next_director(current_director_number : int) -> DirectorDrone:
|
||||||
for drone in director_drones:
|
for drone in director_drones:
|
||||||
if drone.visit_order == current_director_number + 1:
|
if drone.visit_order == current_director_number + 1:
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
[gd_scene load_steps=7 format=3 uid="uid://mk5n0hrwk4yi"]
|
[gd_scene load_steps=7 format=3 uid="uid://mk5n0hrwk4yi"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scenes/scripts/test_level.gd" id="1_lgt1m"]
|
[ext_resource type="Script" path="res://scenes/scripts/test_level.gd" id="1_lgt1m"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dyu4mucawjlu6" path="res://entities/Beehive.tscn" id="2_5ueyo"]
|
||||||
[ext_resource type="Script" path="res://scenes/scripts/drone_manager.gd" id="2_474nc"]
|
[ext_resource type="Script" path="res://scenes/scripts/drone_manager.gd" id="2_474nc"]
|
||||||
[ext_resource type="Script" path="res://scenes/scripts/bee_spawner.gd" id="2_qqqq4"]
|
[ext_resource type="Script" path="res://scenes/scripts/bee_spawner.gd" id="2_qqqq4"]
|
||||||
[ext_resource type="Script" path="res://scenes/scripts/drone_controls.gd" id="3_rqkyv"]
|
[ext_resource type="Script" path="res://scenes/scripts/drone_controls.gd" id="3_rqkyv"]
|
||||||
[ext_resource type="PackedScene" uid="uid://deek6uv574xas" path="res://entities/Bee.tscn" id="4_336fp"]
|
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_usqp5"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_usqp5"]
|
||||||
radius = 142.316
|
radius = 142.316
|
||||||
|
|
@ -17,10 +17,8 @@ position = Vector2(52, -26)
|
||||||
color = Color(0.329412, 0.494118, 0.392157, 1)
|
color = Color(0.329412, 0.494118, 0.392157, 1)
|
||||||
polygon = PackedVector2Array(-141, -86, 1456, -97, 1337, 753, -193, 771)
|
polygon = PackedVector2Array(-141, -86, 1456, -97, 1337, 753, -193, 771)
|
||||||
|
|
||||||
[node name="Beehive" type="Polygon2D" parent="."]
|
[node name="Beehive" parent="." instance=ExtResource("2_5ueyo")]
|
||||||
position = Vector2(-37, 87)
|
position = Vector2(163, 489)
|
||||||
color = Color(0.588235, 0.423529, 0.423529, 1)
|
|
||||||
polygon = PackedVector2Array(95, 146, 203, 134, 186, 274, 78, 287)
|
|
||||||
|
|
||||||
[node name="Flower" type="Polygon2D" parent="."]
|
[node name="Flower" type="Polygon2D" parent="."]
|
||||||
position = Vector2(278, -97)
|
position = Vector2(278, -97)
|
||||||
|
|
@ -112,9 +110,6 @@ layout_mode = 2
|
||||||
tooltip_text = "Spawn a dancing drone that will encourage bees to leave the hive. Best to put this near to the hive. "
|
tooltip_text = "Spawn a dancing drone that will encourage bees to leave the hive. Best to put this near to the hive. "
|
||||||
text = "Dancer"
|
text = "Dancer"
|
||||||
|
|
||||||
[node name="Bee" parent="." instance=ExtResource("4_336fp")]
|
|
||||||
position = Vector2(704, 196)
|
|
||||||
|
|
||||||
[connection signal="pressed" from="DroneManager/Control/MarginContainer/DroneControls/SpawnDirector" to="DroneManager" method="_on_spawn_director_pressed"]
|
[connection signal="pressed" from="DroneManager/Control/MarginContainer/DroneControls/SpawnDirector" to="DroneManager" method="_on_spawn_director_pressed"]
|
||||||
[connection signal="pressed" from="DroneManager/Control/MarginContainer/DroneControls/SpawnCollector" to="DroneManager" method="_on_spawn_collector_pressed"]
|
[connection signal="pressed" from="DroneManager/Control/MarginContainer/DroneControls/SpawnCollector" to="DroneManager" method="_on_spawn_collector_pressed"]
|
||||||
[connection signal="pressed" from="DroneManager/Control/MarginContainer/DroneControls/SpawnDistractor" to="DroneManager" method="_on_spawn_distractor_pressed"]
|
[connection signal="pressed" from="DroneManager/Control/MarginContainer/DroneControls/SpawnDistractor" to="DroneManager" method="_on_spawn_distractor_pressed"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue