From 20da505f2e5171f1d47eb17ed29dede5f1eee973 Mon Sep 17 00:00:00 2001 From: Joshalosh Date: Mon, 2 Oct 2023 08:42:23 +1100 Subject: [PATCH] fp: Add waves to mob spawner --- feely_pona.cpp | 19 ++++++++++++++++++- feely_pona_entity_create.cpp | 31 ++++++++++++++++++------------- feely_pona_game.h | 5 +++++ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/feely_pona.cpp b/feely_pona.cpp index 545e84e..0c57f72 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -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); } - 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) { 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.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 + } } } } diff --git a/feely_pona_entity_create.cpp b/feely_pona_entity_create.cpp index 9d1a492..f2abc03 100644 --- a/feely_pona_entity_create.cpp +++ b/feely_pona_entity_create.cpp @@ -107,24 +107,29 @@ static FP_GameEntityHandle FP_Entity_CreateMobSpawner(FP_Game *game, Dqn_V2 pos, { va_list args; va_start(args, fmt); - FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args); - FP_GameEntityHandle result = entity->handle; + FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args); + FP_GameEntityHandle result = entity->handle; va_end(args); - entity->local_pos = pos; - entity->local_hit_box_size = Dqn_V2_InitNx1(32); + entity->local_pos = pos; + entity->local_hit_box_size = Dqn_V2_InitNx1(32); FP_Entity_AddDebugEditorFlags(game, result); - entity->flags |= FP_GameEntityFlag_MobSpawner; + entity->flags |= FP_GameEntityFlag_MobSpawner; - entity->spawn_cap = spawn_cap; - entity->spawn_list = FP_SentinelList_Init(game->chunk_pool); + entity->spawn_cap = spawn_cap; + entity->spawn_list = FP_SentinelList_Init(game->chunk_pool); - FP_GameShape *shape = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes); - shape->type = FP_GameShapeType_Rect; - shape->p1 = {}; - shape->p2 = entity->local_hit_box_size; - shape->render_mode = TELY_RenderShapeMode_Line; - shape->colour = TELY_COLOUR_BLUE_CADET_V4; + 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); + shape->type = FP_GameShapeType_Rect; + shape->p1 = {}; + shape->p2 = entity->local_hit_box_size; + shape->render_mode = TELY_RenderShapeMode_Line; + shape->colour = TELY_COLOUR_BLUE_CADET_V4; return result; } diff --git a/feely_pona_game.h b/feely_pona_game.h index 4ca79a2..dcb8af3 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -177,6 +177,11 @@ struct FP_GameEntity uint64_t next_spawn_timestamp_s; 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 hp; FP_GameDirection direction; -- 2.34.1