Enemy swarm movement
This commit is contained in:
27
game/wave.c
27
game/wave.c
@@ -1,6 +1,8 @@
|
||||
#include "wave.h"
|
||||
#include "game_state.h"
|
||||
#include "components.h"
|
||||
#include "entity_factory.h"
|
||||
#include "utils.h"
|
||||
|
||||
WaveInfo getWaveInfo(i32 idx) {
|
||||
BZ_ASSERT(idx >= 0);
|
||||
@@ -24,14 +26,33 @@ WaveInfo getWaveInfo(i32 idx) {
|
||||
return info;
|
||||
}
|
||||
|
||||
void updateWave(WaveInfo *wave, f32 dt) {
|
||||
wave->orcsElapsed += dt;
|
||||
wave->goblinsElapsed += dt;
|
||||
static Vector2 randomizeSpawnPos(Vector2 spawnPoint, i32 range) {
|
||||
spawnPoint.x += randFloatRange(-range, range);
|
||||
spawnPoint.y += randFloatRange(-range, range);
|
||||
return spawnPoint;
|
||||
}
|
||||
|
||||
void updateWave(WaveInfo *wave, Game *game, f32 dt) {
|
||||
wave->elapsed += dt;
|
||||
if (wave->elapsed < wave->data.timeBeforeStart)
|
||||
return;
|
||||
wave->started = true;
|
||||
wave->orcsElapsed += dt;
|
||||
wave->goblinsElapsed += dt;
|
||||
|
||||
f32 timeForGoblin = 1.0f / wave->data.goblinSendRate;
|
||||
if (wave->goblinsElapsed >= timeForGoblin) {
|
||||
Vector2 spawnPos = randomizeSpawnPos(game->swarmSpawn, 20);
|
||||
entityCreate(ENTITY_GOBLIN, spawnPos, PLAYER_ENEMY, game);
|
||||
wave->goblinsElapsed -= timeForGoblin;
|
||||
}
|
||||
|
||||
f32 timeForOrc = 1.0f / wave->data.orcSendRate;
|
||||
if (wave->orcsElapsed >= timeForOrc) {
|
||||
Vector2 spawnPos = randomizeSpawnPos(game->swarmSpawn, 20);
|
||||
entityCreate(ENTITY_ORC, spawnPos, PLAYER_ENEMY, game);
|
||||
wave->orcsElapsed -= timeForOrc;
|
||||
}
|
||||
}
|
||||
|
||||
bool isWaveSendingOver(const WaveInfo *wave) {
|
||||
|
||||
Reference in New Issue
Block a user