fp: Add waves to mob spawner

This commit is contained in:
Joshalosh 2023-10-02 08:42:23 +11:00
parent 4212fe8452
commit 20da505f2e
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);
}
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
}
}
}
}

View File

@ -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<FP_GameEntityHandle>(game->chunk_pool);
entity->spawn_cap = spawn_cap;
entity->spawn_list = FP_SentinelList_Init<FP_GameEntityHandle>(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;
}

View File

@ -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;