aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-10-08 19:56:08 +1100
committerquou <quou@disroot.org>2024-10-08 19:56:08 +1100
commit9add408984464bd6b3cc018bb14c3d69ad0a2898 (patch)
treedde2af5525fd076d03c5c8e14067a4502aa1051e /map.c
parentb5c69695c9c97c09f7ffa4d5a600d88cc06ee6da (diff)
New flying enemy that drops arrows
Diffstat (limited to 'map.c')
-rw-r--r--map.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/map.c b/map.c
index 2acd988..5c0cf78 100644
--- a/map.c
+++ b/map.c
@@ -152,6 +152,7 @@ void generate_enemies(const Map* m, World* w) {
(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;
+ /* enemies on platforms */
for (y = 1; y < ey; y++) {
for (x = 1; x < ex; x++) {
int plat = -1;
@@ -176,6 +177,39 @@ void generate_enemies(const Map* m, World* w) {
for (; check && x < ex; x++);
}
}
+ /* flying enemies */
+ for (y = 1; y < ey; y++)
+ for (x = 1; x < ex; x++) {
+ Rect rect = { 0 };
+ int i, j;
+ rect.x = x;
+ rect.y = y;
+ for (j = y; j < ey; j++) {
+ if (m->collision[i + j * map_w])
+ rect.h = 0;
+ for (i = x, rect.w = 0; i < ex && rect.h > 3; i++) {
+ if (!m->collision[i + j * map_w])
+ rect.w++;
+ if (rect.w > 4) {
+ Enemy* e;
+ e = inst_enemy(
+ w,
+ enemy_fly,
+ ((x + (rect.w >> 1)) * map_tile_size) << fbits,
+ ((y + (rect.h >> 1)) * map_tile_size) << fbits
+ );
+ e->face = get_r() & 1;
+ x = i;
+ y = j;
+ rect.w = 0;
+ rect.h = 0;
+ goto found;
+ }
+ }
+ rect.h++;
+ }
+ found:;
+ }
}
void generate_floor(Map* m, World* w) {