fp: Add waves to mob spawner #27
@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,24 +107,29 @@ static FP_GameEntityHandle FP_Entity_CreateMobSpawner(FP_Game *game, Dqn_V2 pos,
|
|||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args);
|
FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args);
|
||||||
FP_GameEntityHandle result = entity->handle;
|
FP_GameEntityHandle result = entity->handle;
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
entity->local_pos = pos;
|
entity->local_pos = pos;
|
||||||
entity->local_hit_box_size = Dqn_V2_InitNx1(32);
|
entity->local_hit_box_size = Dqn_V2_InitNx1(32);
|
||||||
FP_Entity_AddDebugEditorFlags(game, result);
|
FP_Entity_AddDebugEditorFlags(game, result);
|
||||||
entity->flags |= FP_GameEntityFlag_MobSpawner;
|
entity->flags |= FP_GameEntityFlag_MobSpawner;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
FP_GameShape *shape = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
|
entity->current_wave = 1;
|
||||||
shape->type = FP_GameShapeType_Rect;
|
entity->enemies_per_wave = 5;
|
||||||
shape->p1 = {};
|
entity->enemies_spawned_this_wave = 0;
|
||||||
shape->p2 = entity->local_hit_box_size;
|
entity->wave_cooldown_timestamp_s = 0;
|
||||||
shape->render_mode = TELY_RenderShapeMode_Line;
|
|
||||||
shape->colour = TELY_COLOUR_BLUE_CADET_V4;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user