From 91aef268319a77ee8f5a082ca89264bf2671e212 Mon Sep 17 00:00:00 2001 From: quou Date: Sat, 6 May 2023 10:39:19 +1000 Subject: Map rendering and camera movement. --- map.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 map.c (limited to 'map.c') diff --git a/map.c b/map.c new file mode 100644 index 0000000..2b10abd --- /dev/null +++ b/map.c @@ -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); +} -- cgit v1.2.3-54-g00ecf