pollen-not-included/scenes/scripts/bee_spawner.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

38 lines
1.1 KiB
GDScript

extends Node2D
class_name BeeSpawner
var bee : Resource = preload("res://entities/Bee.tscn")
@onready var beehive : Beehive = get_node("../Beehive")
@onready var bee_sound : AudioStreamPlayer = get_node("BigBeeSound")
@onready var small_bee_sound : AudioStreamPlayer = get_node("BeeSound")
var bee_count : int = 0
var max_bees : int = 100
var spawn_interval : float = 0.5
var spawn_timer : float = 0.0
var bee_sound_timer : float = 0.0
func spawn_bee() -> void:
var bee_instance : Bee = bee.instantiate()
add_child(bee_instance)
bee_instance.position = beehive.global_position
func _process(delta : float) -> void:
spawn_timer += delta
if spawn_timer > spawn_interval and bee_count < max_bees and beehive.dancer_in_range:
spawn_bee()
spawn_timer = 0.0
bee_count += 1
Log.pr("Bee count: " + str(bee_count))
if bee_count > 0 and small_bee_sound.playing == false:
small_bee_sound.play()
func _physics_process(delta : float) -> void:
bee_sound_timer += delta
if bee_sound_timer > 1.0 and bee_count > 0:
bee_sound_timer = 0.0
if randf() > 0.9 and bee_sound.playing == false:
bee_sound.play()