aboutsummaryrefslogtreecommitdiff
path: root/src/map.c
blob: 87a0b3ba3138836501c7a511897b76689c3fac78 (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
#include <stdint.h>

#include "vga.h"
#include "data.h"

#include "map.h"

/* current map; set via map_init */
static const uint8_t *cmap;

void map_init(const uint8_t map[])
{
    cmap = map;
}

void map_render()
{
    Rect src = { 0, 0, 160, 48 };
    Rect dst = { 0, 0, 8, 8 };

    for (uint8_t y = 0; y < MAP_H; y++)
        for (uint8_t x = 0; x < MAP_W; x++)
        {
            dst.x = x * MAP_TILE_W;
            dst.y = y * MAP_TILE_H + MAP_OFFS_Y;

            uint8_t t = cmap[x + y * MAP_W];
            src.x = (t % MAP_TILESET_COLS) * MAP_TILE_W;
            src.y = (t / MAP_TILESET_COLS) * MAP_TILE_H;

            blitrc(binary_tiles_start, &src, &dst);
        }
}

uint8_t map_is_blocked(uint16_t x, uint16_t y)
{
    return cmap[(x / MAP_TILE_W) + (y / MAP_TILE_H) * MAP_W] >= MAP_FIRST_BLOCKED;
}

uint8_t map_is_deadly(uint16_t x, uint16_t y)
{
    return cmap[(x / MAP_TILE_W) + (y / MAP_TILE_H) * MAP_W] >= MAP_FIRST_DEADLY;
}