aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'map.c')
-rw-r--r--map.c161
1 files changed, 125 insertions, 36 deletions
diff --git a/map.c b/map.c
index 5c0cf78..b5680fa 100644
--- a/map.c
+++ b/map.c
@@ -14,18 +14,24 @@ Rect tile_rects[] = {
#undef x
};
-void generate_room(Map* m) {
+void generate_room(Map* m, int r) {
const Bitmap* b = get_bitmap(asset_id_rooms_img);
const unsigned* p = (const unsigned*)&b[1];
- const int max_rooms = b->h / map_h;
- const int r = get_r() % max_rooms;
+#ifdef force_room
+ r = force_room;
+#endif
int o = r * map_w * map_h;
int e = map_w * map_h, i;
for (i = 0; i < e; i++, o++) {
int bit = 1 << (o & 0x1f);
- if (p[o >> 5] & bit)
- m->tiles[i] = tile_brick;
- else
+ if (p[o >> 5] & bit) {
+ if ((get_r() & 127) == 0)
+ m->tiles[i] = tile_block1;
+ else if ((get_r() & 127) == 0)
+ m->tiles[i] = tile_stone;
+ else
+ m->tiles[i] = tile_brick;
+ } else
m->tiles[i] = null_tile;
}
}
@@ -146,6 +152,8 @@ void generate_doors(Map* m) {
#undef check
#undef place
+#undef place_a
+#undef place_o
void generate_enemies(const Map* m, World* w) {
#define check \
@@ -178,46 +186,41 @@ void generate_enemies(const Map* m, World* w) {
}
}
/* flying enemies */
- for (y = 1; y < ey; y++)
+ for (y = 1; y < ey; y++) {
+ int next_y = 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;
- }
+ int i = 0, j = 0;
+ int ei = x + 4, ej = y + 4;
+ int ok = 1;
+ for (j = y; j < ej; j++)
+ for (i = x; i < ei; i++) {
+ if (m->collision[i + j * map_w])
+ ok = 0;
}
- rect.h++;
+ if (ok) {
+ Enemy* e;
+ e = inst_enemy(
+ w,
+ enemy_fly,
+ ((x + 2) * map_tile_size) << fbits,
+ ((y + 2) * map_tile_size) << fbits
+ );
+ e->face = get_r() & 1;
+ x = i;
+ next_y = j;
}
- found:;
}
+ y = next_y;
+ }
}
-void generate_floor(Map* m, World* w) {
+void generate_floor(Map* m, World* w, int fi) {
Player* p = &w->player;
w->enemy_count = 0;
w->effect_count = 0;
w->deathzone_count = 0;
- generate_room(m);
+ set_ri(0);
+ generate_room(m, fi);
generate_ramps(m);
generate_doors(m);
generate_floors(m);
@@ -249,3 +252,89 @@ void render_map(const Map* m, Renderer* r) {
}
}
}
+
+#define place(t, c, x, y) { \
+ m->tiles[x + y * map_w] = t; \
+ m->collision[x + y * map_w] = c; \
+ }
+#define ncol(x, y) \
+ m->collision[x + y * map_w] = 0;
+
+void generate_intro(Map* m, struct World* w) {
+ int i, j, b = map_h - 1;
+ int e = map_w * map_h;
+ for (i = 0; i < e; i++) {
+ m->tiles[i] = null_tile;
+ m->collision[i] = 0;
+ }
+ for (i = 0; i < map_w; i++) {
+ int bot = b * map_w;
+ m->collision[i] = 1;
+ m->tiles[i + bot] = tile_stone;
+ m->collision[i + bot] = 1;
+ }
+ b = map_w - 1;
+ for (i = 0; i < map_h; i++)
+ m->collision[b + i * map_w] = 1;
+ for (i = 0; i < 15; i++)
+ place(tile_stone, 1, i, 13);
+ for (i = 0; i < 14; i++)
+ place(tile_stone, 1, i, 12);
+ for (i = 0; i < 12; i++)
+ place(tile_stone, 1, i, 11);
+ for (i = 0; i < 10; i++)
+ place(tile_stone, 1, i, 10);
+ place(tile_stone_ramp7, 4, 15, 13);
+ place(tile_stone_ramp8, 5, 16, 13);
+ place(tile_stone_ramp10, 7, 14, 12);
+ place(tile_stone_ramp7, 4, 12, 11);
+ place(tile_stone_ramp8, 5, 13, 11);
+ place(tile_stone_ramp7, 4, 10, 10);
+ place(tile_stone_ramp8, 5, 11, 10);
+ for (j = 0; j < 10; j++)
+ for (i = 0; i < 5; i++)
+ place(tile_brick, 1, i, j);
+ place(tile_trapdoor3, 0, 4, 9);
+ place(tile_brick_dark, 0, 3, 9);
+ place(tile_gate, 0, 2, 9);
+ place(tile_window_top, 1, 4, 3);
+ place(tile_window_mid, 1, 4, 4);
+ place(tile_window_bot, 1, 4, 5);
+ place(tile_window_top, 1, 4, 0);
+ place(tile_window_mid, 1, 4, 1);
+ place(tile_window_bot, 1, 4, 2);
+ w->player.x = (18 * map_tile_size) << fbits;
+ w->player.y = (13 * map_tile_size) << fbits;
+}
+
+void generate_outro(Map* m, struct World* w) {
+ int i, j;
+ int e = map_w * map_h;
+ for (i = 0; i < e; i++) {
+ m->tiles[i] = null_tile;
+ m->collision[i] = 0;
+ }
+ for (i = 0; i < map_h; i++) {
+ int y = i * map_w;
+ m->collision[y + (map_w - 1)] = 1;
+ m->collision[y] = 1;
+ }
+ for (j = 10; j < map_h; j++)
+ for (i = 0; i < map_w; i++)
+ place(tile_brick, 1, i, j);
+ for (i = 0; i < map_w; i++)
+ if (i & 1)
+ place(tile_brick_floor, 0, i, 9);
+ w->player.x = (map_w >> 1) << fbits;
+ w->player.x *= map_tile_size;
+ w->player.x += (map_tile_size >> 1) << fbits;
+ w->player.y = (9 * map_tile_size) << fbits;
+}
+
+#undef place
+#undef ncol
+
+int room_count(void) {
+ const Bitmap* bm = get_bitmap(asset_id_rooms_img);
+ return bm->h / map_h;
+}