summaryrefslogtreecommitdiff
path: root/src/map.c
blob: 3c894fefb6c14f47572c60587fa54d2209192b90 (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "map.h"
#include "lzy.h"
#include "cfg.h"
#include "maps.h"
#include <stddef.h>
#include <string.h>

struct {
	const Tmj2cMap *map;
	const char *name;
} maps[] = {
	{ &map_nuancierdesaut_tmj,      "nuancier de saut" },
	{ &map_trailblazer_tmj,         "trailblazer" },
	{ &map_weallstartsomewhere_tmj, "we all start kekpart" },
	{ &map_wakywakysnakysnake_tmj,  "waky waky snaky snek" },
	{ &map_fillerepisode_tmj,       "filler episode" },
	{ &map_idkwymmdr_tmj,           "idk wym mdr" },
	{ &map_brulez_tmj,              "brulez" },
};
unsigned int map_id = 0;

void
map_next(void)
{
	if (map_id + 1 < sizeof(maps) / sizeof(maps[0]))
		map_id += 1;
	else
		map_id = 0;
}

int
map_width(void)
{
	return 25;
}

int
map_height(void)
{
	return 14;
}

int
map_get(int x, int y)
{
	if (x < 0 || y < 0 || x >= map_width() || y >= map_height())
		return 1;
	return maps[map_id].map->layers[0].data[x + y * map_width()];
}

int
map_get_px(int x, int y)
{
	if (x < 0 || y < 0)
		return 1;
	return map_get(x / TSIZE, y / TSIZE);
}

static void
draw_outline(int x, int y)
{
	const int left = (map_get(x - 1, y) == 1);
	const int right = (map_get(x + 1, y) == 1);
	const int up = (map_get(x, y - 1) == 1);
	const int down = (map_get(x, y + 1) == 1);
	x *= TSIZE;
	y *= TSIZE;
	if (!left)  (void)LZY_FillRect(x, y, 1, TSIZE);
	if (!right) (void)LZY_FillRect(x + TSIZE - 1, y, 1, TSIZE);
	if (!up)    (void)LZY_FillRect(x, y, TSIZE, 1);
	if (!down)  (void)LZY_FillRect(x, y + TSIZE - 1, TSIZE, 1);
}

void
map_draw(void)
{
	LZY_DrawSetColor(BLACK);
	for (int y = 0; y < map_height(); y++)
		for (int x = 0; x < map_width(); x++)
			if (map_get(x, y) == 1)
				draw_outline(x, y);
}

void
map_draw_ui(void)
{
	const char *s = maps[map_id].name;
	const int x = (DISPLAY_WIDTH - CHR_WIDTH * strlen(s)) / 2;
	const int y = (DISPLAY_HEIGHT - CHR_HEIGHT) / 2;
	(void)LZY_DrawText(x, y, s);
}