aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'map.c')
-rw-r--r--map.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/map.c b/map.c
index 41d224a..17de9a8 100644
--- a/map.c
+++ b/map.c
@@ -147,6 +147,37 @@ void generate_doors(Map* m) {
#undef check
#undef place
+void generate_enemies(const Map* m, World* w) {
+#define check \
+ (m->collision[x + y * map_w] == 1 && \
+ m->collision[x + (y - 1) * map_w] == 0)
+ int x, y, ex = map_w - 1, ey = map_h - 1;
+ for (y = 1; y < ey; y++) {
+ for (x = 1; x < ex; x++) {
+ int plat = -1;
+ for (; x < ex; x++)
+ if (check) {
+ plat = 0;
+ break;
+ }
+ if (!plat)
+ for (; check && x < ex; x++, plat++);
+ if (plat >= 3) {
+ Enemy* e;
+ int sx = x - (plat >> 1);
+ e = inst_enemy(
+ w,
+ enemy_demon,
+ (sx * map_tile_size) << fbits,
+ ((y - 1) * map_tile_size) << fbits
+ );
+ e->face = get_r() & 1;
+ }
+ for (; check && x < ex; x++);
+ }
+ }
+}
+
void generate_floor(Map* m, World* w) {
Player* p = &w->player;
generate_room(m);
@@ -154,6 +185,7 @@ void generate_floor(Map* m, World* w) {
generate_doors(m);
generate_floors(m);
generate_collision(m);
+ generate_enemies(m, w);
p->x = (map_w >> 1) << fbits;
p->y = (map_h - 2) << fbits;
p->x *= map_tile_size;