aboutsummaryrefslogtreecommitdiff
path: root/map.c
blob: c2d9e0dbce5e37712db717b06aec922381f516b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "asset.h"
#include "map.h"
#include "rect.h"
#include "render.h"

#define null_tile 0xffff

Rect tile_rects[] = {
#define x(n, x, y) \
	{ x, y, map_tile_size, map_tile_size },
	tiles_xmacro
#undef x
};

void generate_floor(Map* m, int seed) {
	int e = map_w * map_h, i;
	for (i = 0; i < e; i++) {
		m->tiles[i] = null_tile;
		m->collision[i] = 0;
	}
	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;
	}
#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 render_map(const Map* m, Renderer* r) {
	const Bitmap* tm = get_bitmap(asset_id_map_img);
	int t = 0, x, y;
	for (y = 0; y < map_h; y++) {
		for (x = 0; x < map_w; x++, t++) {
			int tile = m->tiles[t];
			if (tile != null_tile)
				ren_map(
					r,
					x * map_tile_size,
					y * map_tile_size,
					&tile_rects[tile],
					tm
				);
		}
	}
}