fp: Add waves to mob spawner #27

Merged
doylet merged 1 commits from waves into main 2023-10-01 23:03:54 +00:00
3 changed files with 41 additions and 14 deletions

View File

@ -1414,7 +1414,16 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
link = FP_SentinelList_Erase(&entity->spawn_list, link, game->chunk_pool); link = FP_SentinelList_Erase(&entity->spawn_list, link, game->chunk_pool);
} }
if (entity->spawn_list.size < entity->spawn_cap) { // NOTE: Spawn new entities if (entity->enemies_spawned_this_wave >= entity->enemies_per_wave) {
// NOTE: If all enemies for the current wave have been spawned,
// wait for the cooldown period before starting next wave
if (input->timer_s >= entity->wave_cooldown_timestamp_s) {
entity->current_wave++;
entity->enemies_per_wave *= 2; // NOTE: Double the enemies for the next wave
entity->enemies_spawned_this_wave = 0;
}
} else if (entity->spawn_list.size < entity->spawn_cap) { // NOTE: Spawn new entities
if (input->timer_s >= entity->next_spawn_timestamp_s) { if (input->timer_s >= entity->next_spawn_timestamp_s) {
entity->next_spawn_timestamp_s = DQN_CAST(uint64_t)(input->timer_s + 5.f); entity->next_spawn_timestamp_s = DQN_CAST(uint64_t)(input->timer_s + 5.f);
@ -1442,6 +1451,14 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
waypoint->data.arrive = FP_GameWaypointArrive_WhenWithinEntitySize; waypoint->data.arrive = FP_GameWaypointArrive_WhenWithinEntitySize;
waypoint->data.value = 1.5f; waypoint->data.value = 1.5f;
} }
entity->enemies_spawned_this_wave++;
// NOTE: If all enemies for the current wave have been spawned
// set the cooldown time for the next wave
if (entity->enemies_spawned_this_wave >= entity->enemies_per_wave) {
entity->wave_cooldown_timestamp_s = DQN_CAST(uint64_t)(input->timer_s + 30.f); // NOTE: 30s cooldown
}
} }
} }
} }

View File

@ -119,6 +119,11 @@ static FP_GameEntityHandle FP_Entity_CreateMobSpawner(FP_Game *game, Dqn_V2 pos,
entity->spawn_cap = spawn_cap; entity->spawn_cap = spawn_cap;
entity->spawn_list = FP_SentinelList_Init<FP_GameEntityHandle>(game->chunk_pool); entity->spawn_list = FP_SentinelList_Init<FP_GameEntityHandle>(game->chunk_pool);
entity->current_wave = 1;
entity->enemies_per_wave = 5;
entity->enemies_spawned_this_wave = 0;
entity->wave_cooldown_timestamp_s = 0;
FP_GameShape *shape = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes); FP_GameShape *shape = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
shape->type = FP_GameShapeType_Rect; shape->type = FP_GameShapeType_Rect;
shape->p1 = {}; shape->p1 = {};

View File

@ -177,6 +177,11 @@ struct FP_GameEntity
uint64_t next_spawn_timestamp_s; uint64_t next_spawn_timestamp_s;
uint64_t spawn_cap; uint64_t spawn_cap;
uint64_t current_wave;
uint64_t enemies_per_wave;
uint64_t enemies_spawned_this_wave;
uint64_t wave_cooldown_timestamp_s;
uint64_t flags; uint64_t flags;
uint64_t hp; uint64_t hp;
FP_GameDirection direction; FP_GameDirection direction;