basic tilemapping

This commit is contained in:
2026-07-25 21:53:33 -07:00
parent 5298e75fdb
commit e6ce80ce13
5 changed files with 52 additions and 8 deletions
+14 -3
View File
@@ -9,11 +9,22 @@
namespace UwU {
class TileMapper : public MapperBase<TileMapper> { // not actually tilemapping yet
public:
TileMapper() {}
TileMapper() {
this->tileMap = new uint16_t[16384]; // the map of tile positions 128x128 8x8 tiles from a 512x512 bitmap space
}
uint16_t* tileMap;
Coord2 map(uint16_t x0, uint16_t y0, uint16_t x, uint16_t y) {
uint16_t u = x -x0;
uint16_t v = y -y0;
uint16_t u0 = x - x0;
uint16_t v0 = y - y0;
// returns uv coordinates that point to a specific pixel of a specific tile on a tilesheet buffer
uint16_t mapX = (u0 & 0x03f8) >> 3;
uint16_t mapY = (v0 & 0x03f8) << 4;
uint16_t tileIndex = tileMap[mapY + mapX];
uint16_t u = (tileIndex & 0x003f) << 3;
u += (u0 & 0x0007);
uint16_t v = (tileIndex & 0x0fc0) >> 3;
v += (v0 & 0x0007);
return Coord2(u, v);
}
};