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
|
#include "map.h"
#include "lzy.h"
#include "cfg.h"
#include "weallstartsomewhere.h"
#include "wakywakysnakysnake.h"
#include "idkwymlol.h"
#include <stddef.h>
#define LOL(x) (unsigned char *)(x)
unsigned char *maps[] = {
map_weallstartsomewhere_json.data, LOL("we all start somewhere"),
map_wakywakysnakysnake_json.data, LOL("waky waky snaky snake"),
map_idkwymlol_json.data, LOL("idk wym lol"),
NULL
};
unsigned int map_id = 0;
void
map_next(void)
{
if (maps[map_id + 2] != NULL)
map_id += 2;
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][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) LZY_DrawRect(x, y, 1, TSIZE);
if (!right) LZY_DrawRect(x + TSIZE - 1, y, 1, TSIZE);
if (!up) LZY_DrawRect(x, y, TSIZE, 1);
if (!down) LZY_DrawRect(x, y + TSIZE - 1, TSIZE, 1);
}
void
map_draw(void)
{
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);
}
|