Files
UwUGL/mappers/tilemapper.cpp
T

31 lines
972 B
C++
Raw Normal View History

2026-07-24 18:01:59 -07:00
#pragma once
#include <stdint.h>
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "mapperbase.cpp"
namespace UwU {
class TileMapper : public MapperBase<TileMapper> { // not actually tilemapping yet
public:
2026-07-25 21:53:33 -07:00
TileMapper() {
this->tileMap = new uint16_t[16384]; // the map of tile positions 128x128 8x8 tiles from a 512x512 bitmap space
}
uint16_t* tileMap;
2026-07-24 18:01:59 -07:00
2026-07-24 19:06:14 -07:00
Coord2 map(uint16_t x0, uint16_t y0, uint16_t x, uint16_t y) {
2026-07-25 21:53:33 -07:00
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);
2026-07-24 18:01:59 -07:00
return Coord2(u, v);
}
};
}