pollen-not-included/entities/bee/states/bee_travelling.gd
2024-05-04 15:13:59 +01:00

49 lines
1.3 KiB
GDScript

extends State
class_name BeeTravelling
@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
var return_to_hive : bool = false
func enter(_msg := {}):
Log.pr("I am on the move!")
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
bee.just_gathering = false
else:
target = bee.get_next_target()
Log.pr(bee, target)
# If we have no target, we are returning to the hive
if !target:
Log.pr("No more drones to visit, going to go back to the hive")
return_to_hive = true
bee.animation_player.play("Flying")
func update(delta : float) -> void:
if return_to_hive:
state_transition.emit(self, "Returning")
return
if target:
if bee.position.distance_to(target.position) > 3:
bee.velocity = (target.get_global_position() - bee.position).normalized() * bee.speed * delta
bee.move_and_collide(bee.velocity)
bee.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")