added dog distractions
This commit is contained in:
parent
4834ebdda8
commit
51af0ea751
11 changed files with 117 additions and 5 deletions
|
|
@ -4,11 +4,13 @@ class_name BeeSpawner
|
|||
var bee = preload("res://entities/Bee.tscn")
|
||||
|
||||
@onready var beehive = get_node("../Beehive")
|
||||
@onready var bee_sound = get_node("BigBeeSound")
|
||||
|
||||
var bee_count = 0
|
||||
var max_bees = 100
|
||||
var spawn_interval = 0.5
|
||||
var spawn_timer = 0.0
|
||||
var bee_sound_timer = 0.0
|
||||
|
||||
func spawn_bee():
|
||||
var bee_instance = bee.instantiate()
|
||||
|
|
@ -17,9 +19,16 @@ func spawn_bee():
|
|||
|
||||
func _process(delta):
|
||||
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))
|
||||
|
||||
func _physics_process(delta):
|
||||
bee_sound_timer += delta
|
||||
if bee_sound_timer > 1.0:
|
||||
bee_sound_timer = 0.0
|
||||
if randf() > 0.9:
|
||||
bee_sound.play()
|
||||
|
|
@ -5,6 +5,7 @@ class_name Dog
|
|||
|
||||
var acquired_target : Bee = null
|
||||
var target_timer : float = 0.0
|
||||
var distracted : bool = false
|
||||
|
||||
func _ready():
|
||||
death_box.connect("body_entered", Callable(self, "_on_body_entered"))
|
||||
|
|
@ -26,14 +27,23 @@ func _process(delta):
|
|||
|
||||
|
||||
func _on_body_entered(area):
|
||||
if area.is_in_group("bee"):
|
||||
if area.is_in_group("bee") and distracted == false:
|
||||
if !acquired_target:
|
||||
Log.pr("Acquired target")
|
||||
target_timer = 0.0
|
||||
acquired_target = area
|
||||
|
||||
if area.is_in_group("distractor"):
|
||||
Log.pr("Distracted")
|
||||
acquired_target = null
|
||||
distracted = true
|
||||
|
||||
func _on_body_exited(area):
|
||||
if area == acquired_target:
|
||||
Log.pr("Lost target")
|
||||
acquired_target = null
|
||||
target_timer = 0.0
|
||||
|
||||
if area.is_in_group("distractor"):
|
||||
Log.pr("No longer distracted")
|
||||
distracted = false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue