make aphids spawn honeydew and make anthill spawn a start ant

This commit is contained in:
2024-10-08 04:29:33 +10:00
parent 024bc2b7d9
commit f144e79ea5
9 changed files with 98 additions and 28 deletions

View File

@@ -5,12 +5,38 @@ enum AphidState {
WANDERING,
}
const HONEYDEW_INTERVAL_MIN: float = 5
const HONEYDEW_INTERVAL_MAX: float = 60
const HONEYDEW_SPAWN_SPREAD: float = 0.5
const HONEYDEWS_MAX: int = 5
var state: AphidState = AphidState.WANDERING
var honeydew_spawn_timer: float = 0
var spawned_honeydews: Dictionary = {}
var honeydew_scene := preload("res://scenes/items/honeydew.tscn")
@onready var holder: Node = $/root/World/Items/Honeydew
func _ready() -> void:
assert(holder != null, "holder missing!")
super._ready()
_set_spawn_timer()
func _process(delta: float) -> void:
super._process(delta)
_handle_wandering(delta)
_handle_honeydew_spawn(delta)
func erase_honeydew(item: Honeydew) -> void:
var item_id := item.get_instance_id()
if not spawned_honeydews.keys().has(item_id):
return
spawned_honeydews.erase(item_id)
func _handle_wandering(delta: float) -> void:
@@ -18,3 +44,39 @@ func _handle_wandering(delta: float) -> void:
return
_wander(delta)
func _handle_honeydew_spawn(delta: float) -> void:
if spawned_honeydews.size() >= HONEYDEWS_MAX:
return
if honeydew_spawn_timer >= 0:
honeydew_spawn_timer -= delta
return
var new_honeydew := honeydew_scene.instantiate() as Honeydew
new_honeydew.set_aphid(self)
var new_pos := Vector3(
randf_range(-HONEYDEW_SPAWN_SPREAD, HONEYDEW_SPAWN_SPREAD),
new_honeydew.HEIGHT_OFFSET,
randf_range(-HONEYDEW_SPAWN_SPREAD, HONEYDEW_SPAWN_SPREAD),
)
holder.add_child(new_honeydew)
new_honeydew.global_position = global_position + new_pos
_put_honeydew(new_honeydew)
audio_player.play_polyphonic(SoundManager.pop())
_set_spawn_timer()
func _put_honeydew(item: Honeydew) -> void:
var item_id := item.get_instance_id()
spawned_honeydews[item_id] = item as Honeydew
func _set_spawn_timer() -> void:
honeydew_spawn_timer = randf_range(
HONEYDEW_INTERVAL_MIN,
HONEYDEW_INTERVAL_MAX,
)

View File

@@ -44,6 +44,7 @@ var showing_after_set: bool = false
func _ready() -> void:
assert(collision_shape != null, "collision_shape missing!")
assert(radius_indicator != null, "radius_indicator missing!")
assert(audio_player != null, "audio_player missing!")
body_entered.connect(_on_body_entered)
body_exited.connect(_on_body_exited)
@@ -189,6 +190,7 @@ func _deposit() -> void:
audio_player.play_polyphonic(SoundManager.swoosh())
await item.start_moving(anthill.global_position).moved
audio_player.play_polyphonic(SoundManager.pop())
item.remove_from_spawner()
_erase_honeydew(item)
item.queue_free()
anthill.deposit_honeydew(1)

View File

@@ -25,6 +25,9 @@ var advance_anim_delta_accum: float = 0
$VisibleOnScreenNotifier3D
)
@onready var main_camera: MainCamera = $/root/World/MainCamera
@onready var audio_player: AudioStreamPlayerPolyphonic = (
$AudioStreamPlayerPolyphonic
)
func _ready() -> void:
@@ -34,6 +37,7 @@ func _ready() -> void:
assert(ui_origin != null, "ui_origin missing!")
assert(main_camera != null, "main_camera missing!")
assert(anim_advance_indicator != null, "anim_advance_indicator missing!")
assert(audio_player != null, "audio_player missing!")
super._ready()
anim_advance_indicator.visible = false