#include "map.h" #include "sprite.h" #include "standard.h" #include "solid.h" void init_map(Map* map, World* world) { const Sprite* floor, * bricks; const Bitmap* fbmp, * bbmp; Bitmap bitmap; int i, x, y, r; bitmap.pixels = map->pixels; bitmap.w = mbmp_w; bitmap.h = mbmp_h; floor = get_sprite(sprite_floor_tile_1); 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 (y = 1; y < map_height - 1; y++) { for (x = 1; x < map_width - 1; x++) { r = rng() % 60; if (r > 50) { floor = get_sprite((r % 4) + sprite_floor_tile_1); } 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 ); } /* Bounds */ new_solid( world, 0, 0, (map_width * map_tile_size) << fbits, map_tile_size << fbits ); new_solid( world, 0, ((map_height - 1) * map_tile_size) << fbits, (map_width * map_tile_size) << fbits, map_tile_size << fbits ); new_solid( world, 0, 0, map_tile_size << fbits, (map_height * map_tile_size) << fbits ); new_solid( world, ((map_width - 1) * map_tile_size) << fbits, 0, map_tile_size << fbits, (map_height * map_tile_size) << fbits ); 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 ); new_solid( world, x << fbits, y << fbits, map_tile_size << fbits, map_tile_size << fbits ); } } 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); }