pollen-not-included/entities/bee/states/bee_gather.gd
Dan Baker 513b0c92a7 Refactor bee gather state and update game state
Removed unused code in the bee gathering function, enhancing readability. Also added a new boolean variable 'spawn_snails' in the game state reset function to control snail spawning.
2024-05-14 18:47:28 +01:00

36 lines
961 B
GDScript

extends State
class_name BeeGathering
@export var animator : AnimationPlayer
@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
var target : Vector2 = Vector2.ZERO
func enter(_msg := {}):
bee.just_gathering = true
Log.pr("Gathering now...")
randomize()
target = bee.get_global_position() + Vector2(randi_range(-100, 100), randi_range(-100, 100))
func update(_delta : float):
if bee.in_range_of_flowers:
#animator.play("Gathering")
time_at_patch += _delta
if time_at_patch > 5.0:
Log.pr("Gathered nectar!")
bee.nectar += 1
state_transition.emit(self, "Idle")
else:
state_transition.emit(self, "Idle")
func physics_update(delta : float) -> void:
if target:
if bee.position.distance_to(target) > 2:
bee.velocity = (target - bee.position).normalized() * bee.speed / 2 * delta
bee.move_and_collide(bee.velocity)
bee.bee_body.look_at(target)