#pragma once #include #include "datatypes.cpp" #include "helpers.cpp" namespace UwU { class Tilemap { public: Tilemap() { 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 u, uint16_t v) { // returns uv coordinates that point to a specific pixel of a specific tile on a tilesheet buffer uint16_t mapX = (u & 0x03f8) >> 3; uint16_t mapY = (v & 0x03f8) << 4; uint16_t tileIndex = tilemap[mapY + mapX]; uint16_t u1 = (tileIndex & 0x003f) << 3; u1 += (u & 0x0007); uint16_t v1 = (tileIndex & 0x0fc0) >> 3; v1 += (v & 0x0007); return Coord2(u1, v1); } }; }