Enemy swarm movement
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "map_init.h"
|
||||
|
||||
#include <flecs.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "building_factory.h"
|
||||
#include "components.h"
|
||||
@@ -10,14 +11,37 @@
|
||||
#include "utils.h"
|
||||
#include "systems/systems.h"
|
||||
|
||||
i32 getSwarmWaypointIdx(u32 id) {
|
||||
char buf[4];
|
||||
for (i32 i = 0; i < MAX_SWARM_WAYPOINTS; i++) {
|
||||
snprintf(buf, sizeof(buf), "p%d", i);
|
||||
if (id == bzStringDefaultHash(buf))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool initGameObjectsLayer(BzTileMap *map, BzTileObjectGroup *objectGroup) {
|
||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||
game->swamNumWaypoints = 0;
|
||||
for (i32 i = 0; i < objectGroup->objectCount; i++) {
|
||||
BzTileObject object = objectGroup->objects[i];
|
||||
if (bzStringDefaultHash("camera") == object.id) {
|
||||
game->camera.target.x = object.shape.x;
|
||||
game->camera.target.y = object.shape.y;
|
||||
}
|
||||
i32 swarmIdx = getSwarmWaypointIdx(object.id);
|
||||
if (swarmIdx != -1) {
|
||||
game->swarmWaypoints[swarmIdx] = (Vector2) {
|
||||
object.shape.x,
|
||||
object.shape.y,
|
||||
};
|
||||
game->swamNumWaypoints = BZ_MAX(game->swamNumWaypoints, swarmIdx + 1);
|
||||
}
|
||||
if (bzStringDefaultHash("spawn") == object.id) {
|
||||
game->swarmSpawn.x = object.shape.x;
|
||||
game->swarmSpawn.y = object.shape.y;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user