pollen-not-included/entities/bee/states/bee_travelling.gd
Dan 2a9e78b52e Refactor: Added explicit typing and void return types
- Introduced explicit typing to variables and functions across multiple scripts for better code clarity.
- Specified 'void' as the return type for functions that do not return a value.
- Removed redundant code in some scripts.
2024-05-15 10:42:16 +01:00

52 lines
1.5 KiB
GDScript

extends State
class_name BeeTravelling
@export var target : Drone = null
@onready var bee : Bee = get_parent().get_parent() as Bee # I think this is bad but I dont care it works
var return_to_hive : bool = false
var moving_to : Vector2 = Vector2(0,0)
func enter(_msg : Dictionary = {}) -> void:
return_to_hive = false
## Get the next target location from the bee
if bee.just_gathering:
target = bee.get_current_director() # We want to go back the way we came
if !target:
Log.pr("No director around, returning to hive")
## If there is no other director, just go straight back home
state_transition.emit(self, "Returning")
bee.just_gathering = false
else:
target = bee.get_next_target()
# If we have no target, we are returning to the hive
if !target:
return_to_hive = true
else:
moving_to = target.get_global_position()
bee.bee_position_animation.play("Flying")
func update(_delta : float) -> void:
if return_to_hive:
state_transition.emit(self, "Returning")
return
func physics_update(delta : float) -> void:
if target:
if bee.position.distance_to(target.position) > 3:
bee.velocity = (moving_to - bee.position).normalized() * bee.speed * delta
bee.move_and_collide(bee.velocity)
bee.bee_body.look_at(target.position)
else:
# Bee has arrived at location, if its the hive or a collector drone do the things
if(target.name == "CollectorDrone"):
state_transition.emit(self, "Gathering")
else:
state_transition.emit(self, "Idle")