hese are the definitions.....
- Code: Select all
boolean Grafx_esp::getBitmapPixel(const uint8_t* bitmap, uint16_t x, uint16_t y) {
return pgm_read_byte(bitmap + 2 + y * ((pgm_read_byte(bitmap) + 7) / 8) + (x >> 3)) & (B10000000 >> (x % 8));
}
void Grafx_esp::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet, uint16_t color) {
drawTilemap(x, y, tilemap, spritesheet, 0, 0, Grafx_TFTWIDTH, Grafx_TFTHEIGHT, color);
}
void Grafx_esp::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet, uint16_t dx, uint16_t dy, uint16_t dw, uint16_t dh, uint16_t color) {
uint16_t tilemap_width = pgm_read_byte(tilemap); // tilemap width
uint16_t tilemap_height = pgm_read_byte(tilemap + 1); // tilemap height what is the +1
uint16_t tile_width = pgm_read_byte(tilemap + 2); //tile width what is +2
uint16_t tile_height = pgm_read_byte(tilemap + 3); // tile height what +3
tilemap += 4; // now the first tiyleis at tilemap
uint16_t ddw = dw + dx;
uint16_t ddh = dh + dy;
uint16_t maxDdx = (dw - x + tile_width - 1) / tile_width;
uint16_t maxDdy = (dh - y + tile_height - 1) / tile_height;
if (tilemap_width < maxDdx) {
maxDdx = tilemap_width;
}
if (tilemap_height < maxDdy) {
maxDdy = tilemap_height;
}
int16_t startDdx = (-x) / tile_width;
int16_t startDdy = (-y) / tile_height;
if (startDdx < 0) {
startDdx = 0;
}
if (startDdy < 0) {
startDdy = 0;
}
if (flagcollision)numcolision = 0; //Line 735 - clear numcolision - ADD by Summoner123
for (uint16_t ddy = startDdy; ddy < maxDdy; ddy++) { //what are these ++
for (uint16_t ddx = startDdx; ddx < maxDdx; ddx++) { what are these ++
int16_t drawX = ddx*tile_width + x + dx;
int16_t drawY = ddy*tile_height + y + dy;
uint16_t tile = pgm_read_byte(tilemap + ddy*tilemap_width + ddx);
if (drawX >= dx && drawY >= dy && drawX <= (ddw - tile_width) && drawY <= (ddh - tile_height)) {
drawBitmap1(drawX, drawY, spritesheet[tile], tile_width, tile_height, color);
if (flagcollision) {
solid[numcolision].x = drawX; //Save X coordinate - ADD by Summoner123
solid[numcolision].y = drawY; //Save Y coordinate - ADD by Summoner123
solid[numcolision].spritecol = spritesheet[tile]; //Save Sprite of tile - ADD by Summoner123
numcolision++; //Increment numcolision - ADD by Summoner123
}
}
else { // we need to draw a partial bitmap
drawBitmapTm(drawX, drawY, tile_width, tile_height, spritesheet[tile], dx, dy, dw, dh, color);
}
}
}
}
void Grafx_esp::drawBitmapTm(int16_t x, int16_t y, int16_t w, int16_t h, const uint8_t *bitmap, uint16_t dx, uint16_t dy, uint16_t dw, uint16_t dh, uint16_t color) {
int16_t i, j, byteWidth = (w + 7) / 8;
dw += dx;
dh += dy;
int16_t largest = 0;
int16_t largesty = 0;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
if (pgm_read_byte(bitmap + j * byteWidth + i / 8) & (B10000000 >> (i % 8))) {
int16_t drawX = x + i;
int16_t drawY = y + j;
if (drawX >= dx && drawX < dw && drawY >= dy && drawY < dh) {
drawPixel(drawX, drawY, color);
}
}
}
}
}