diff options
-rw-r--r-- | 1bitjam.c | 4 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | intermediate/map.bmp | bin | 30858 -> 41098 bytes | |||
-rw-r--r-- | intermediate/rooms.bmp | bin | 0 -> 2538 bytes | |||
-rw-r--r-- | map.c | 160 | ||||
-rw-r--r-- | map.h | 7 |
6 files changed, 133 insertions, 39 deletions
@@ -26,9 +26,7 @@ int entrypoint(int argc, const char** argv, Arena* m) { init_fps(&f, default_mpf); world = arena_alloc(m, sizeof world); init_world(world); - generate_floor(&world->map, 0); - inst_enemy(world, enemy_demon, 100 << fbits, 100 << fbits); - inst_enemy(world, enemy_demon, 200 << fbits, 100 << fbits); + generate_floor(&world->map, world); while (a->o) { fps_begin(&f); while (f.now >= f.next && a->o) { @@ -69,6 +69,7 @@ image_sources = \ $(int_dir)/map.bmp \ $(int_dir)/mask.bmp \ $(int_dir)/npc.bmp \ + $(int_dir)/rooms.bmp \ anim_sources = \ $(int_dir)/demon_fly_left.anm \ diff --git a/intermediate/map.bmp b/intermediate/map.bmp Binary files differindex 13ee910..fd32c56 100644 --- a/intermediate/map.bmp +++ b/intermediate/map.bmp diff --git a/intermediate/rooms.bmp b/intermediate/rooms.bmp Binary files differnew file mode 100644 index 0000000..b9562e4 --- /dev/null +++ b/intermediate/rooms.bmp @@ -1,7 +1,9 @@ #include "asset.h" +#include "random.h" #include "map.h" #include "rect.h" #include "render.h" +#include "world.h" #define null_tile 0xffff @@ -12,44 +14,132 @@ Rect tile_rects[] = { #undef x }; -void generate_floor(Map* m, int seed) { +void generate_room(Map* m) { + 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;*/ 1; + int o = r * map_w * map_h; int e = map_w * map_h, i; - for (i = 0; i < e; i++) { - m->tiles[i] = null_tile; - m->collision[i] = 0; + for (i = 0; i < e; i++, o++) { + int bit = 1 << (o & 0x1f); + if (p[o >> 5] & bit) + m->tiles[i] = tile_brick; + else + m->tiles[i] = null_tile; } - e = map_w * (map_h - 1); - for (i = 0; i < map_w; i++) { - int idx = i + e; - m->tiles[idx] = tile_stone; - m->collision[idx] = 1; +} + +unsigned short get_collider(Map_Tile t) { + switch (t) { + case tile_stone: + case tile_block1: + case tile_block2: + case tile_window_top: + case tile_window_mid: + case tile_window_bot: + case tile_brick_floor: + case tile_brick: return 1; + case tile_brick_ramp5: + case tile_stone_ramp5: return 2; + case tile_brick_ramp6: + case tile_stone_ramp6: return 3; + case tile_brick_ramp7: + case tile_stone_ramp7: return 4; + case tile_brick_ramp8: + case tile_stone_ramp8: return 5; + default: + return 0; } -#define set(x, y) \ - m->tiles[x + y * map_w] = tile_brick; \ - m->collision[x + y * map_w] = 1; - set(0, 13); - set(0, 12); - set(0, 11); - set(1, 11); - set(2, 11); - set(3, 11); - set(4, 11); - set(6, 11); - set(7, 11); - set(8, 11); - set(19, 13); - set(19, 12); - set(19, 11); - set(19, 10); - set(19, 9); - set(19, 8); -#undef set - m->tiles[18 + 13 * map_w] = tile_stone_ramp9; - m->collision[18 + 13 * map_w] = 6; - m->tiles[1 + 12 * map_w] = tile_stone_ramp13; - m->collision[1 + 12 * map_w] = 10; - m->tiles[2 + 12 * map_w] = tile_stone_ramp14; - m->collision[2 + 12 * map_w] = 11; +} + +void generate_collision(Map* m) { + int e = map_w * map_h, i; + for (i = 0; i < e; i++) + m->collision[i] = get_collider(m->tiles[i]); +} + +int imp_check(Map* m, Map_Tile t, int x, int y) { + return + x >= 0 && + y >= 0 && + x < map_w && + y < map_h && + m->tiles[x + y * map_w] == t; +} + +#define check(ox, oy, t) \ + imp_check(m, t, x + ox, y + oy) +#define place(t) \ + m->tiles[x + y * map_w] = t +#define place_o(t, ox, oy) \ + m->tiles[x + ox + (y + oy) * map_w] = t + +void generate_ramps(Map* m) { + int x, y; + for (y = 0; y < map_h; y++) + for (x = 0; x < map_w; x++) { + if ( + check( 0, 0, null_tile) && + check( 1, 0, null_tile) && + check(-1, 0, tile_brick) && + !check(-1, -1, tile_brick) && + check( 0, 1, tile_brick) && + check( 1, 1, tile_brick) + ) { + place(tile_brick_ramp7); + place_o(tile_brick_ramp8, 1, 0); + } + if ( + check( 0, 0, null_tile) && + check(-1, 0, null_tile) && + check( 1, 0, tile_brick) && + !check( 1, -1, tile_brick) && + check( 0, 1, tile_brick) && + check(-1, 1, tile_brick) + ) { + place(tile_brick_ramp6); + place_o(tile_brick_ramp5, -1, 0); + } + if ( + check(0, 0, tile_brick) && + check(0, 1, tile_brick) && + check(0, 2, tile_brick) && (( + check(1, 0, null_tile) && + check(1, 1, null_tile) && + check(1, 2, null_tile)) || ( + check(-1, 0, null_tile) && + check(-1, 1, null_tile) && + check(-1, 2, null_tile))) + ) { + place(tile_window_top); + place_o(tile_window_mid, 0, 1); + place_o(tile_window_bot, 0, 2); + } + } +} + +void generate_floors(Map* m) { + int x, y; + for (y = 0; y < map_h; y++) + for (x = 0; x < map_w; x++) { + if ( + check(0, 0, tile_brick) && + check(0, -1, null_tile) + ) place(tile_brick_floor); + } +} + +#undef check +#undef place + +void generate_floor(Map* m, World* w) { + generate_room(m); + generate_ramps(m); + generate_floors(m); + generate_collision(m); + w->player.x = 16 << fbits; + w->player.y = 16 << fbits; } void render_map(const Map* m, Renderer* r) { @@ -4,6 +4,7 @@ #include "config.h" struct Renderer; +struct World; #define tiles_xmacro \ x(tile_stone, 0, 0) \ @@ -35,6 +36,10 @@ struct Renderer; x(tile_brick_ramp11, 96, 32) \ x(tile_brick_ramp12, 112, 32) \ x(tile_brick_ramp13, 128, 32) \ + x(tile_window_top, 0, 48) \ + x(tile_window_mid, 16, 48) \ + x(tile_window_bot, 32, 48) \ + x(tile_brick_floor, 48, 48) typedef enum { #define x(n, x, y) \ @@ -54,7 +59,7 @@ typedef struct Map { */ } Map; -void generate_floor(Map* m, int seed); +void generate_floor(Map* m, struct World* w); void render_map(const Map* m, struct Renderer* r); #endif |