Switch to full style
Understanding the language, error messages, etc.
Post a reply

Re: TilemapRamino example

Sun May 28, 2017 1:36 am

ok lets break the function down...

hese are the definitions.....
Code:
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);
            }
         }
      }
   }
}

Re: TilemapRamino example

Sun May 28, 2017 1:43 am

To be honest, I think you should just write your own tile map algorithm because this is a little complicated. If the bit maps are displayed fine anywhere on the screen, then I think the problem is with the drawTilemap() function.

Re: TilemapRamino example

Sun May 28, 2017 1:51 am

for(unsigned int y = 0; y < 15; y++) {
for(unsigned int x = 0; x < 20; x++) {
Int tile = pgm_read_byte(data + (x + y * 20));
drawBitmap(x * 16, y * 16, tile);
}
}

Re: TilemapRamino example

Sun May 28, 2017 1:51 am

Something like that

Re: TilemapRamino example

Sun May 28, 2017 1:54 am

replace the drawTilemap function with something like that and it should work
Edit:
Duhjoker I can't help you if you keep leaving like this, try the code above and quickly tell me if it works I'm trying to diagnose the problem
Last edited by awesome101 on Sun May 28, 2017 2:11 am, edited 1 time in total.

Re: TilemapRamino example

Sun May 28, 2017 2:11 am

Where exactly do I add that?

Re: TilemapRamino example

Sun May 28, 2017 2:12 am

In the drawTilemap() function

Re: TilemapRamino example

Sun May 28, 2017 2:16 am

void Grafx_esp::drawTilemap() {
for(unsigned int y = 0; y < 15; y++) {
for(unsigned int x = 0; x < 20; x++) {
int tile = pgm_read_byte(tilemap_black + (x + y * 20));
drawBitmap(x * 16, y * 16, tile);
}
}

Re: TilemapRamino example

Sun May 28, 2017 2:18 am

When you call the function in your sketch, pass in no arguments

Re: TilemapRamino example

Sun May 28, 2017 2:24 am

Did it work??
Hello?
Post a reply