diff options
author | quou <quou@disroot.org> | 2023-05-06 10:39:19 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2023-05-06 10:39:19 +1000 |
commit | 91aef268319a77ee8f5a082ca89264bf2671e212 (patch) | |
tree | 7deb9a4a9e928d4b78f7c3398e7d9c97a4649140 /map.c | |
parent | 2ab411c4b8855d11d48454a93262e8eae3ba7fc7 (diff) |
Map rendering and camera movement.
Diffstat (limited to 'map.c')
-rw-r--r-- | map.c | 95 |
1 files changed, 95 insertions, 0 deletions
@@ -0,0 +1,95 @@ +#include "map.h" +#include "sprite.h" +#include "standard.h" + +void init_map(Map* map) { + const Sprite* floor, * bricks; + const Bitmap* fbmp, * bbmp; + Bitmap bitmap; + int i, x, y; + + bitmap.pixels = map->pixels; + bitmap.w = mbmp_w; + bitmap.h = mbmp_h; + + floor = get_sprite(sprite_floor_tile); + bricks = get_sprite(sprite_bricks); + fbmp = get_bitmap(floor->bitmap); + bbmp = get_bitmap(bricks->bitmap); + + for (i = 0; i < mbmp_w * mbmp_h; i++) { + bitmap.pixels[i] = make_black(); + } + + for (x = 1; x < map_width - 1; x++) { + for (y = 1; y < map_height - 1; y++) { + blit( + &bitmap, + fbmp, + map_tile_size * x, + map_tile_size * y, + &floor->rect + ); + } + } + + for (x = 0; x < map_width; x++) { + blit( + &bitmap, + bbmp, + map_tile_size * x, + 0, + &bricks->rect + ); + blit( + &bitmap, + bbmp, + map_tile_size * x, + (map_height - 1) * map_tile_size, + &bricks->rect + ); + } + + for (y = 0; y < map_height; y++) { + blit( + &bitmap, + bbmp, + 0, + map_tile_size * y, + &bricks->rect + ); + blit( + &bitmap, + bbmp, + (map_width - 1) * map_tile_size, + map_tile_size * y, + &bricks->rect + ); + } + + for (i = 0; i < 20; i++) { + x = rand_range(0, map_width - 1) * map_tile_size; + y = rand_range(0, map_height - 1) * map_tile_size; + blit( + &bitmap, + bbmp, + x, + y, + &bricks->rect + ); + } +} + +void render_map(Map* map, int cx, int cy) { + Bitmap bitmap; + Rectangle rect; + + bitmap.pixels = map->pixels; + bitmap.w = mbmp_w; + bitmap.h = mbmp_h; + rect.x = 0; + rect.y = 0; + rect.w = bitmap.w; + rect.h = bitmap.h; + render_bitmap(&bitmap, -cx >> fbits, -cy >> fbits, &rect); +} |