pollen-not-included/entities/bee/states/bee_gather.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

36 lines
1.1 KiB
GDScript

extends State
class_name BeeGathering
@export var animator : AnimationPlayer
@onready var bee : 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 : Dictionary = {}) -> void:
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) -> void:
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 += GameState.flower_nectar_level # Add nectar to the bee based on current flower nectar level
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)