aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'map.c')
-rw-r--r--map.c95
1 files changed, 95 insertions, 0 deletions
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);
+}