]>
git.bts.cx Git - benzene.git/blob - src/bz/gfx/tilemap.c
1 #include <bz/gfx/tilemap_internal.h>
3 #include <bz/game/tilemap_internal.h>
4 #include <bz/gfx/gfx_internal.h>
5 #include <bz/math/math.h>
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
);
11 size_t mapFromY
= bzMax(0, ty
);
12 size_t mapToY
= bzMin(tilemap
->height
, ty
+ mh
);
14 size_t tilesX
= mapToX
- mapFromX
;
15 size_t tilesY
= mapToY
- mapFromY
;
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
;
22 size_t idx
= my
* tilemap
->width
+ mx
;
23 BZTilemapTile
*tile
= &tilemap
->tiles
[idx
];
24 BZTilemapTileDefinition
*tileDefinition
= &tilemap
->tileDefinitions
[tile
->tileDefinitionIdx
];
26 //uint8_t tileIdx = tile->spriteIdx;
28 // tileIdx = tileDefinition->spriteIdx;
31 if (mask
== 0 || (tileDefinition
->tagsFlag
& mask
) > 0) {
32 uint8_t spriteIdx
= bzGameGetTilemapSprite(tilemap
, mx
, my
);
35 //Tile *tile = &tiles[tileIdx];
37 //bool flagsSet = ignoreMask;
39 //if (flagsSet == false) {
40 // uint8_t flags = tile->flags;// | mapTile->flags;
41 // flagsSet = (flags & userFlagMask) == userFlagValues;
45 /*if (mapTile->replaceSprite) {
46 spriteIdx = mapTile->spriteIdx;
47 } else if (tile->replaceSprite) {
48 spriteIdx = tile->spriteIdx;
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.