#pragma once #include #include "../datatypes.cpp" #include "../helpers.cpp" #include "mapperbase.cpp" namespace UwU { class TileMapper : public MapperBase { // not actually tilemapping yet public: 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 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); } }; }