]> git.bts.cx Git - benzene.git/blob - src/bz/gfx/tilemap.c
Fixed Aseprite rendering system
[benzene.git] / src / bz / gfx / tilemap.c
1 #include <bz/gfx/tilemap_internal.h>
2
3 #include <bz/game/tilemap_internal.h>
4 #include <bz/gfx/gfx_internal.h>
5 #include <bz/math/math.h>
6
7 void bzGfxMap(BZTilemapID tilemap, int tx, int ty, int x, int y, int mw, int mh, uint32_t mask) {
8 size_t mapFromX = bzMax(0, tx);
9 size_t mapToX = bzMin(tilemap->width, tx + mw);
10
11 size_t mapFromY = bzMax(0, ty);
12 size_t mapToY = bzMin(tilemap->height, ty + mh);
13
14 size_t tilesX = mapToX - mapFromX;
15 size_t tilesY = mapToY - mapFromY;
16
17 for (size_t mty = 0; mty < tilesY; ++mty) {
18 for (size_t mtx = 0; mtx < tilesX; ++mtx) {
19 size_t mx = mapFromX + mtx;
20 size_t my = mapFromY + mty;
21
22 size_t idx = my * tilemap->width + mx;
23 BZTilemapTile *tile = &tilemap->tiles[idx];
24 BZTilemapTileDefinition *tileDefinition = &tilemap->tileDefinitions[tile->tileDefinitionIdx];
25
26 //uint8_t tileIdx = tile->spriteIdx;
27 //if (tileIdx == 0) {
28 // tileIdx = tileDefinition->spriteIdx;
29 //}
30
31 if (mask == 0 || (tileDefinition->tagsFlag & mask) > 0) {
32 uint8_t spriteIdx = bzGameGetTilemapSprite(tilemap, mx, my);
33
34 //if (tileIdx > 0) {
35 //Tile *tile = &tiles[tileIdx];
36
37 //bool flagsSet = ignoreMask;
38
39 //if (flagsSet == false) {
40 // uint8_t flags = tile->flags;// | mapTile->flags;
41 // flagsSet = (flags & userFlagMask) == userFlagValues;
42 //}
43
44 //if (flagsSet) {
45 /*if (mapTile->replaceSprite) {
46 spriteIdx = mapTile->spriteIdx;
47 } else if (tile->replaceSprite) {
48 spriteIdx = tile->spriteIdx;
49 }*/
50
51 if (spriteIdx > 0) {
52 int height = bzMax(tileDefinition->height, 1);
53 for (int i = 0; i < height; ++i) {
54 bzSpr(spriteIdx - i * 16, x + mtx * 8, y + mty * 8 - i * 8); // Fixme, just sspr it.
55 }
56 }
57 //}
58 }
59 }
60 }
61 }