Wave incrementing

This commit is contained in:
2024-02-11 19:23:40 +01:00
parent 0319a0a5b3
commit bfc1bc425f
7 changed files with 73 additions and 10 deletions

View File

@@ -41,6 +41,7 @@ ECS_COMPONENT_DECLARE(ConsumePopCapacity);
ECS_COMPONENT_DECLARE(Health);
ECS_COMPONENT_DECLARE(Worker);
ECS_COMPONENT_DECLARE(Building);
ECS_COMPONENT_DECLARE(Swarm);
ECS_COMPONENT_DECLARE(Unit);
ECS_COMPONENT_DECLARE(Tower);
ECS_COMPONENT_DECLARE(Projectile);
@@ -95,6 +96,7 @@ void initComponentIDs(ecs_world_t *ecs) {
ECS_COMPONENT_DEFINE(ecs, Health);
ECS_COMPONENT_DEFINE(ecs, Worker);
ECS_COMPONENT_DEFINE(ecs, Building);
ECS_COMPONENT_DEFINE(ecs, Swarm);
ECS_COMPONENT_DEFINE(ecs, Unit);
ECS_COMPONENT_DEFINE(ecs, Tower);
ECS_COMPONENT_DEFINE(ecs, Projectile);

View File

@@ -292,6 +292,12 @@ typedef struct Health {
} Health;
extern ECS_COMPONENT_DECLARE(Health);
typedef struct Swarm {
int _;
} Swarm;
extern ECS_COMPONENT_DECLARE(Swarm);
// Worker can:
// - Harvest
// - Build

View File

@@ -480,6 +480,8 @@ void update(float dt, void *userData) {
break;
}
updateWave(&game->waveInfo, dt);
SoundState *soundState = ecs_singleton_get_mut(ECS, SoundState);
soundsUpdate(soundState, getCameraBounds(game->camera));
}
@@ -605,9 +607,30 @@ static void renderGame(Game *game, float dt) {
if (game->debug.drawSpatialGrid)
bzSpatialGridDrawDebugGrid(game->entityGrid);
drawPlayerInputUI();
EndMode2D();
static f32 waveDisplay = 0.0f;
if (isWaveOver(&game->waveInfo)) {
game->waveInfo = getWaveInfo(game->waveInfo.number + 1);
waveDisplay = 1.6f;
}
if (waveDisplay > 0.0f) {
const i32 fontSize = 72 * uiGetScale();
char text[32];
snprintf(text, sizeof(text), "Wave: %d", game->waveInfo.number);
Vector2 textSize = MeasureTextEx(game->font, text, fontSize, 1.0f);
i32 x = GetScreenWidth() * 0.5f - textSize.x * 0.5f;
i32 y = GetScreenHeight() * 0.5f - textSize.y;
Color color = WHITE;
const f32 fadeAt = 0.45f;
if (waveDisplay < fadeAt)
color.a = (waveDisplay / fadeAt) * 255;
DrawText(text, x, y, fontSize, color);
waveDisplay -= dt;
}
#if 0
static bool firstRun = true;
if (firstRun) {
editedEmitter = GET_BLOOD_EMITTER();
@@ -623,6 +646,7 @@ static void renderGame(Game *game, float dt) {
ecs_set_ptr(ECS, e, ParticleEmitter, &emitter);
}
#endif
}
void render(float dt, void *userData) {

View File

@@ -268,6 +268,9 @@ void loadMap(Game *game, const char *path) {
game->camera.rotation = 0.0f;
game->camera.zoom = 3.0f;
bzMemSet(game->playerResources, 0, sizeof(*game->playerResources));
game->waveInfo = getWaveInfo(0);
bzTileMapAddLayerCollisions(&game->map, LAYER_TERRAIN, COLL_LAYER_TERRAIN);
bzTileMapOverrideLayer(&game->map, LAYER_TREES, initTreesLayer);

View File

@@ -1,3 +1,4 @@
#include <stdio.h>
#include "systems.h"
#include "../game_state.h"
@@ -74,7 +75,17 @@ void drawGameUI(Game *game, f32 dt) {
BZ_UI_FLEX_ALIGN_CENTER |
BZ_UI_FLEX_JUSTIFY_START
});
uiBaseLabel("Wave: 11 ", game->font, 0.5f, WHITE);
char waveDisplay[32];
if (game->waveInfo.started) {
snprintf(waveDisplay, sizeof(waveDisplay), "Wave: %d ", game->waveInfo.number);
} else {
f32 startingIn = game->waveInfo.data.timeBeforeStart - game->waveInfo.elapsed;
i32 min = startingIn / 60.0f;
i32 sec = startingIn - (min * 60);
snprintf(waveDisplay, sizeof(waveDisplay), "Wave %d starting in: %02d:%02d ",
game->waveInfo.number + 1, min, sec);
}
uiBaseLabel(waveDisplay, game->font, 0.5f, WHITE);
bzUIPopParent(UI); // topBarRight
bzUIPopParent(UI); // topBar
@@ -301,7 +312,10 @@ void drawGameOverUI(Game *game, f32 dt) {
.type = BZ_UI_LAYOUT_FLEX_BOX,
.flags = BZ_UI_FLEX_DIR_COLUMN | BZ_UI_FLEX_ALIGN_CENTER
});
uiBaseLabel("You survived 10 rounds.\n\n", game->font, 0.8f, WHITE);
char gameOverDisplay[32];
snprintf(gameOverDisplay, sizeof(gameOverDisplay), "You survived %d waves.\n\n",
game->waveInfo.number);
uiBaseLabel(gameOverDisplay, game->font, 0.8f, WHITE);
if (uiMainMenuButton("Exit", true)) {
setScreen(game, SCREEN_MAIN_MENU);
unloadMap(game);

View File

@@ -1,4 +1,6 @@
#include "wave.h"
#include "game_state.h"
#include "components.h"
WaveInfo getWaveInfo(i32 idx) {
BZ_ASSERT(idx >= 0);
@@ -12,22 +14,32 @@ WaveInfo getWaveInfo(i32 idx) {
}
WaveInfo info = {
.number = idx,
.data = waveData,
.orcsToSend = waveData.numOrcs,
.goblinsToSend = waveData.numGoblins,
};
info.data.timeBeforeStart /= 60;
return info;
}
void updateWave(WaveInfo *wave, f32 dt) {
wave->orcsElapsed += dt;
wave->golbinsElapsed += dt;
wave->goblinsElapsed += dt;
wave->elapsed += dt;
if (wave->elapsed < wave->data.timeBeforeStart)
return;
wave->started = true;
}
bool isWaveSendingOver(const WaveInfo *wave) {
return wave->orcsToSend == 0 && wave->goblinsToSend == 0;
}
bool isWaveOver(const WaveInfo *wave) {
if (!isWaveSendingOver(wave)) return false;
return wave->started && ecs_count_id(ECS, ecs_id(Swarm)) == 0;
}

View File

@@ -18,18 +18,19 @@ typedef struct WaveInfo {
i32 orcsToSend;
f32 orcsElapsed;
i32 goblinsToSend;
f32 golbinsElapsed;
f32 goblinsElapsed;
f32 elapsed;
bool started;
} WaveInfo;
#define NUM_WAVES 5
static WaveData predefWaves[NUM_WAVES] = {
{ 10, 1.0f, 20, 2.0f, 0, 5 * 60 * 60 },
{ 20, 1.0f, 40, 2.0f, 0, 2 * 60 * 60 },
{ 25, 1.0f, 80, 2.2f, 0, 2 * 60 * 60 },
{ 50, 1.2f, 120, 3.0f, 0, 1.5 * 60 * 60 },
{ 100, 2.0f, 220, 4.0f, 0, 60 * 60 },
{ 10, 1.0f, 20, 2.0f, 0, 5 * 60 },
{ 20, 1.0f, 40, 2.0f, 0, 2 * 60 },
{ 25, 1.0f, 80, 2.2f, 0, 2 * 60 },
{ 50, 1.2f, 120, 3.0f, 0, 1.5f * 60 },
{ 100, 2.0f, 220, 4.0f, 0, 1.0f * 60 },
};
WaveInfo getWaveInfo(i32 idx);
@@ -37,6 +38,7 @@ WaveInfo getWaveInfo(i32 idx);
void updateWave(WaveInfo *wave, f32 dt);
bool isWaveSendingOver(const WaveInfo *wave);
bool isWaveOver(const WaveInfo *wave);
#endif //PIXELDEFENSE_WAVE_H