fp: Render the current wave
This commit is contained in:
parent
8ebbb64877
commit
b758a05809
@ -1824,6 +1824,14 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
|
||||
FP_Game_MoveEntity(game, entity_handle, acceleration_meters_per_s);
|
||||
}
|
||||
|
||||
// NOTE: If all enemies for the current wave have been spawned and the cooldown has elapsed
|
||||
// start the next wave.
|
||||
if (game->enemies_spawned_this_wave >= game->enemies_per_wave && game->clock_ms >= game->wave_cooldown_timestamp_ms) {
|
||||
game->enemies_per_wave = DQN_MAX(5 * DQN_CAST(uint32_t)game->mob_spawners.size, DQN_CAST(uint32_t)(game->enemies_per_wave * 1.5f));
|
||||
game->enemies_spawned_this_wave = 0;
|
||||
game->current_wave++;
|
||||
}
|
||||
|
||||
// NOTE: Update entity =========================================================================
|
||||
for (FP_GameEntityIterator it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &it, game->root_entity); ) {
|
||||
FP_GameEntity *entity = it.entity;
|
||||
@ -1878,18 +1886,9 @@ 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->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 (game->enemies_spawned_this_wave < game->enemies_per_wave && entity->spawn_list.size < entity->spawn_cap) { // NOTE: Spawn new entities
|
||||
if (input->timer_s >= entity->next_spawn_timestamp_s) {
|
||||
uint16_t hp_adjustment = DQN_CAST(uint16_t)entity->current_wave - 1;
|
||||
uint16_t hp_adjustment = DQN_CAST(uint16_t)game->current_wave;
|
||||
entity->next_spawn_timestamp_s = DQN_CAST(uint64_t)(input->timer_s + 5.f);
|
||||
|
||||
Dqn_V2 entity_world_pos = FP_Game_CalcEntityWorldPos(game, entity->handle);
|
||||
@ -1921,13 +1920,10 @@ 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
|
||||
}
|
||||
game->enemies_spawned_this_wave++;
|
||||
if (game->enemies_spawned_this_wave >= game->enemies_per_wave)
|
||||
game->wave_cooldown_timestamp_ms = game->clock_ms + 30'000;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2603,6 +2599,33 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
|
||||
TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "[J|K] Melee/Range");
|
||||
}
|
||||
|
||||
// NOTE: Render the wave ===================================================
|
||||
{
|
||||
TELY_Render_PushTransform(renderer, Dqn_M2x3_Identity());
|
||||
DQN_DEFER { TELY_Render_PopTransform(renderer); };
|
||||
|
||||
TELY_Render_PushFont(renderer, game->talkco_font_large);
|
||||
DQN_DEFER { TELY_Render_PopFont(renderer); };
|
||||
|
||||
uint64_t time_until_next_wave_ms = 0;
|
||||
if (game->enemies_spawned_this_wave >= game->enemies_per_wave) {
|
||||
if (game->wave_cooldown_timestamp_ms > game->clock_ms) {
|
||||
time_until_next_wave_ms = game->wave_cooldown_timestamp_ms - game->clock_ms;
|
||||
}
|
||||
}
|
||||
|
||||
Dqn_f32 mid_x = platform->core.window_size.x * .5f;
|
||||
if (time_until_next_wave_ms) {
|
||||
TELY_Render_TextF(renderer,
|
||||
Dqn_V2_InitNx2(mid_x, player_avatar_rect.pos.y),
|
||||
Dqn_V2_InitNx1(0.5f),
|
||||
"%.1fs remaining until Wave %u!",
|
||||
(time_until_next_wave_ms / 1000.f), game->current_wave + 1);
|
||||
} else {
|
||||
TELY_Render_TextF(renderer, Dqn_V2_InitNx2(mid_x, player_avatar_rect.pos.y), Dqn_V2_InitNx1(0.5f), "Wave %u", game->current_wave);
|
||||
}
|
||||
}
|
||||
|
||||
if (!FP_Game_IsNilEntityHandle(game, game->clicked_entity)) {
|
||||
// NOTE: Render building blueprint =========================================================
|
||||
if (game->active_menu == FP_GameActiveMenu_Build) {
|
||||
|
@ -410,11 +410,6 @@ static FP_GameEntityHandle FP_Entity_CreateMobSpawner(FP_Game *game, Dqn_V2 pos,
|
||||
|
||||
entity->spawn_cap = spawn_cap;
|
||||
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;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -209,11 +209,6 @@ 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;
|
||||
FP_GameDirection direction;
|
||||
Dqn_V2 local_pos;
|
||||
@ -328,6 +323,11 @@ struct FP_Game
|
||||
Dqn_usize build_mode_building_index;
|
||||
|
||||
Dqn_FArray<FP_GameEntityHandle, 4> mob_spawners;
|
||||
|
||||
uint32_t current_wave;
|
||||
uint32_t enemies_per_wave;
|
||||
uint32_t enemies_spawned_this_wave;
|
||||
uint64_t wave_cooldown_timestamp_ms;
|
||||
};
|
||||
|
||||
struct FP_GameAStarNode
|
||||
|
Loading…
Reference in New Issue
Block a user