tilemap and collision routines help adding to gfx

Understanding the language, error messages, etc.

Re: tilemap and collision routines help adding to gfx

Postby Duhjoker » Mon Oct 03, 2016 9:57 pm

Edited no relevant info
Last edited by Duhjoker on Thu Oct 20, 2016 6:11 am, edited 1 time in total.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: tilemap and collision routines help adding to gfx

Postby Duhjoker » Sat Oct 15, 2016 9:20 am

Edited nothing worth saving
Last edited by Duhjoker on Thu Oct 20, 2016 6:10 am, edited 1 time in total.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: tilemap and collision routines help adding to gfx

Postby Duhjoker » Mon Oct 17, 2016 8:17 am

Could I please get some help with the bitmap functions and the tile map. I've been trying to figure this out for days and im still stuck.

ive tried adding color arguments to the regular gamebuino bitmap functions in both the cpp and the h file. ive also tried just using the gfx color versions but they don't work with the tile map. On the second bitmap function I only used the original bitmap code and marked out the grey scale stuff. Any way they all seem to match but I noticed this in both summoners and the og gamebuino library.....

Code: Select all
void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint16_t color) {
   int8_t w = pgm_read_byte(bitmap);
   int8_t h = pgm_read_byte(bitmap + 1);
   bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
   drawBitmap(x, y, w, h, bitmap, color);// shouldn't this be in thew next one down
}

void Display::drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint16_t color) {
#if (ENABLE_BITMAPS > 0)
   //   original code
   int8_t i, j, byteWidth = (w + 7) / 8;
   for (j = 0; j < h; j++) {
      for (i = 0; i < w; i++) {
         if (pgm_read_byte(bitmap + j * byteWidth + i / 8) & (B10000000 >> (i % 8))) {
            drawPixel(x + i, y + j, color); //shouldn't this be the last bit of the top
         }
      }
   }
}


other than that they match perfectly but something is messing me up

ok does the Boolean getbitmap pixel need a color argument? how would I add that to the cpp version?

there is also a drawpixel definition in some of the functions cpp counter parts do they need the color argument too?

ok here are errors
Code: Select all
Arduino: 1.6.11 (Windows 7), TD: 1.30-beta3, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz optimize speed (overclock), US English"

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:649:6: error: prototype for 'void Display::drawBitmap(int8_t, int8_t, const uint8_t*, uint8_t, uint8_t, uint16_t)' does not match any in class 'Display'

 void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip, uint16_t color) {

      ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:625:6: error: candidates are: void Display::drawBitmap(int8_t, int8_t, int8_t, int8_t, const uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint16_t)

 void Display::drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh, uint16_t color) {

      ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:612:6: error:                 void Display::drawBitmap(int8_t, int8_t, int8_t, int8_t, const uint8_t*, uint16_t)

 void Display::drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint16_t color) {

      ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:605:6: error:                 void Display::drawBitmap(int8_t, int8_t, const uint8_t*, uint16_t)

 void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint16_t color) {

      ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp: In member function 'void Display::drawTilemap(int, int, const uint8_t*, const uint8_t**, uint8_t, uint8_t, uint8_t, uint8_t)':

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:742:72: error: no matching function for call to 'Display::drawBitmap(int8_t&, int8_t&, uint8_t&, uint8_t&, const uint8_t*&)'

     drawBitmap(drawX, drawY, tile_width, tile_height, spritesheet[tile]);

                                                                        ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:742:72: note: candidates are:

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:605:6: note: void Display::drawBitmap(int8_t, int8_t, const uint8_t*, uint16_t)

 void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint16_t color) {

      ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:605:6: note:   candidate expects 4 arguments, 5 provided

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:612:6: note: void Display::drawBitmap(int8_t, int8_t, int8_t, int8_t, const uint8_t*, uint16_t)

 void Display::drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint16_t color) {

      ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:612:6: note:   candidate expects 6 arguments, 5 provided

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:625:6: note: void Display::drawBitmap(int8_t, int8_t, int8_t, int8_t, const uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint16_t)

 void Display::drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh, uint16_t color) {

      ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:625:6: note:   candidate expects 10 arguments, 5 provided

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:752:88: error: no matching function for call to 'Display::drawBitmap(int8_t&, int8_t&, uint8_t&, uint8_t&, const uint8_t*&, uint8_t&, uint8_t&, uint8_t&, uint8_t&)'

     drawBitmap(drawX, drawY, tile_width, tile_height, spritesheet[tile], dx, dy, dw, dh);

                                                                                        ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:752:88: note: candidates are:

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:605:6: note: void Display::drawBitmap(int8_t, int8_t, const uint8_t*, uint16_t)

 void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint16_t color) {

      ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:605:6: note:   candidate expects 4 arguments, 9 provided

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:612:6: note: void Display::drawBitmap(int8_t, int8_t, int8_t, int8_t, const uint8_t*, uint16_t)

 void Display::drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint16_t color) {

      ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:612:6: note:   candidate expects 6 arguments, 9 provided

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:625:6: note: void Display::drawBitmap(int8_t, int8_t, int8_t, int8_t, const uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint16_t)

 void Display::drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh, uint16_t color) {

      ^

C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinocolor\src\DISPLAYRGB.cpp:625:6: note:   candidate expects 10 arguments, 9 provided

Error compiling for board Teensy 3.2 / 3.1.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


and the sketch
Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

#define GREEN 0x0400

const byte green_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};



void setup() {
  gb.begin();
  gb.titleScreen(F("test"));

}

void loop() {
 if(gb.update()){
  gb.display.drawBitmap(70, 70, 16, 16, green_square, GREEN);
 }

}


h file functions
Code: Select all
//OG Gamebuino
      void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint16_t color);
      void drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint16_t color);
      //void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip, uint16_t color);
      void drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh, uint16_t color);
      boolean getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y);


cpp counterparts
Code: Select all
void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint16_t color) {
   int8_t w = pgm_read_byte(bitmap);
   int8_t h = pgm_read_byte(bitmap + 1);
   bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
   drawBitmap(x, y, w, h, bitmap, color);
}

void Display::drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint16_t color) {
#if (ENABLE_BITMAPS > 0)
   //   original code
   int8_t i, j, byteWidth = (w + 7) / 8;
   for (j = 0; j < h; j++) {
      for (i = 0; i < w; i++) {
         if (pgm_read_byte(bitmap + j * byteWidth + i / 8) & (B10000000 >> (i % 8))) {
            drawPixel(x + i, y + j, color);
         }
      }
   }
}

void Display::drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh, uint16_t color) {
   int8_t i, j, byteWidth = (w + 7) / 8;
   dw += dx;
   dh += dy;
   //int8_t largest = 0;
   //int8_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))) {
            int8_t drawX = x + i;
            int8_t drawY = y + j;

            if (drawX >= dx && drawX < dw && drawY >= dy && drawY < dh) {
               drawPixel(drawX, drawY, color);
            }
         }
      }
   }
}

boolean Display::getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y) {
   return pgm_read_byte(bitmap + 2 + y * ((pgm_read_byte(bitmap) + 7) / 8) + (x >> 3)) & (B10000000 >> (x % 8));
}

void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip, uint16_t color) {
   if ((rotation == NOROT) && (flip == NOFLIP)) {
      drawBitmap(x, y, bitmap, color); //use the faster algorithm
      return;
   }
   uint8_t w = pgm_read_byte(bitmap);
   uint8_t h = pgm_read_byte(bitmap + 1);
   bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
   (ENABLE_BITMAPS > 0),
   int8_t i, j, //coordinates in the raw bitmap
      k, l, //coordinates in the rotated/flipped bitmap
      byteNum, bitNum, byteWidth = (w + 7) >> 3;

   rotation %= 4;

   for (i = 0; i < w; i++) {
      byteNum = i / 8;
      bitNum = i % 8;
      for (j = 0; j < h; j++) {
         if (pgm_read_byte(bitmap + j * byteWidth + byteNum) & (B10000000 >> bitNum)) {
            switch (rotation) {
            case NOROT: //no rotation
               k = i;
               l = j;
               break;
            case ROTCCW: //90° counter-clockwise
               k = j;
               l = w - i - 1;
               break;
            case ROT180: //180°
               k = w - i - 1;
               l = h - j - 1;
               break;
            case ROTCW: //90° clockwise
               k = h - j - 1;
               l = i;
               break;
            }
            if (flip) {
               flip %= 4;
               if (flip & B00000001) { //horizontal flip
                  k = w - k - 1;
               }
               if (flip & B00000010) { //vertical flip
                  l = h - l;
               }
            }
            k += x; //place the bitmap on the screen
            l += y;
            drawPixel(k, l);
         }
      }
   }
#else
   drawRect(x, y, w, h);
#endif
}

void Display::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet) {
   drawTilemap(x, y, tilemap, spritesheet, 0, 0, LCDWIDTH, LCDHEIGHT);
}
void Display::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh) {
   uint8_t tilemap_width = pgm_read_byte(tilemap);
   uint8_t tilemap_height = pgm_read_byte(tilemap + 1);
   uint8_t tile_width = pgm_read_byte(tilemap + 2);
   uint8_t tile_height = pgm_read_byte(tilemap + 3);
   tilemap += 4; // now the first tiyleis at tilemap
   uint8_t ddw = dw + dx;
   uint8_t ddh = dh + dy;
   uint8_t maxDdx = (dw - x + tile_width - 1) / tile_width;
   uint8_t maxDdy = (dh - y + tile_height - 1) / tile_height;
   if (tilemap_width < maxDdx) {
      maxDdx = tilemap_width;
   }
   if (tilemap_height < maxDdy) {
      maxDdy = tilemap_height;
   }
   int8_t startDdx = (-x) / tile_width;
   int8_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 (uint8_t ddy = startDdy; ddy < maxDdy; ddy++) {
      for (uint8_t ddx = startDdx; ddx < maxDdx; ddx++) {
         int8_t drawX = ddx*tile_width + x + dx;
         int8_t drawY = ddy*tile_height + y + dy;
         uint8_t tile = pgm_read_byte(tilemap + ddy*tilemap_width + ddx);
         if (drawX >= dx && drawY >= dy && drawX <= (ddw - tile_width) && drawY <= (ddh - tile_height)) {
            drawBitmap(drawX, drawY, tile_width, tile_height, spritesheet[tile]);

            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
            drawBitmap(drawX, drawY, tile_width, tile_height, spritesheet[tile], dx, dy, dw, dh);
         }
      }
   }
}



Also what do I do about the setFont commands in the Gamebuino cpp the new library uses setTextSize(uint8_t 16) and doesn't use a setFontwidth and height

EDITED:::: 0:45 October 20th

Ok so I've been going about the colorizing the tilemap and drawBitMap commands all wrong. Using the grey scale stuff you would normally set the color before each call to produce grey, black or white(neutral). So all I needed was a function to set the color but in uint16_t. Fortunately my display files already have a set color function for other functions that match gamebuinos but in uint16_t so it was easy to add a set color function.

I did have to remove the new code from from the cpp's drawBitMap that has the grey scale bits. It wouldn't work with the way Im Working the code.

Lol you know I could have saved a lot of forum space and time and aggravation if some one had said hey ....... Did you know? Just saying!
Last edited by Duhjoker on Sat Oct 29, 2016 9:35 am, edited 1 time in total.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: tilemap and collision routines help adding to gfx

Postby Duhjoker » Sat Oct 22, 2016 1:14 am

Can I please please please on my hands and knees get some help with fixing the bitmap commands and tilemap stuff to work in the new library. I've been trying to do this for weeks and nobody else can help from lack of interest or the know how to do so.

Seriously I'm beefing for help. I would pay for it at this point!!!!!!

I've tried Every thing I know and more and I can't figure it out. Everything else is done!!!
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Previous

Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 15 guests