aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-10-05 15:22:44 +1000
committerquou <quou@disroot.org>2024-10-05 15:22:44 +1000
commit8f6e5a1aba52b46fc20408e3064ddf60390615c0 (patch)
treed8c9a4b1e45dfe4ad58453623b306c81d3320019
parente23139b9059fe595c48aa201783499cd6ba2ff6f (diff)
generate enemies in teh level
-rw-r--r--intermediate/rooms.bmpbin2538 -> 2538 bytes
-rw-r--r--map.c32
2 files changed, 32 insertions, 0 deletions
diff --git a/intermediate/rooms.bmp b/intermediate/rooms.bmp
index b9562e4..a0bf456 100644
--- a/intermediate/rooms.bmp
+++ b/intermediate/rooms.bmp
Binary files differ
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;