I'll be waiting with bells on my feet Naed!
In the meantime I would like to play around with mouguino's example. Since the drawbitmapfromSD should allow me use the tilemap functions and collision data too. Storing animated sprites should still be in Progmem as it will be faster but this should still be good for storing large non moving bitmaps and displaying the tilemaps.
The more I look at it the more I'm starting to understand but I'm not seeing how to open open the files for reading.
ok so im trying to integrate the code into my display files .cpp and .h. Now that I understand it a lil. Any way adding the two functions was easy enough for both files and adding the color arguments was a piece of cake but im a lil confused on how to update it to the tilemap functions. I have no idea what to do about it though.
ok look at this....
- Code: Select all
//draw from SD mouguino
// Draw bitmap from SD at position x0, y0
int drawBitmapFromSd(byte x0, byte y0, char *bitmap, uint16_t color) { // where bitmap[] is the name of the bitmap file on SD
char buf[13]; // max 2 bytes for W/H + 11 bytes of data to cover the 84 pixel width of the Gamebuino screen
// 1. open bitmap file
#ifdef debug // use PROGMEM dump of bitmap data
if (bitmap == "ff.bmp") bmp = ff;
else if (bitmap == "d2.bmp") bmp = d2;
else if (bitmap == "d4.bmp") bmp = d4;
else if (bitmap == "358.bmp") bmp = i358;
else if (bitmap == "383.bmp") bmp = i383;
else if (bitmap == "400.bmp") bmp = i400;
else return BMP_NO_FILE;
#else // open real bitmap on SD
if (pf_open(bitmap)) return BMP_NO_FILE;
#endif
// 2a. read information from bitmap header > identifier
readNCharsAt(2, 0, buf); // BMP.wIdentifier
buf[2] = NULL;
if (strcmp(buf, "BM")) return BMP_NOT_WBM;
// 2b. read information from bitmap header > bpp, compression and data size
readNCharsAt(10, 28, buf); // BMP.wBitsPerPixel + BMP.dwCompression + BMP.dwDataSize
if (WORD(buf, 0) != 1) return BMP_NOT_1BPP; // not a 1bpp bitmap
if (LONG(buf, 2)) return BMP_ERR_CMP; // not an UNcompressed bitmap
word datasize = WORD(buf, 6);
// 2c. read information from bitmap header > data offset
readNCharsAt(4, 10, buf); // BMP.dwDataOffset
word offset = WORD(buf, 0);
// 2d. read information from bitmap header > dimensions
readNCharsAt(8, 18, buf); // BMP.dwWidth + BMP.dwHeight
byte w = (byte)buf[0];
if (w>LCDWIDTH) return BMP_TOO_BIG;
byte h = (byte)buf[4];
byte datalen = datasize / h;
// 3. read and draw bitmap data
buf[0] = w; buf[1] = 1; // get bitmap data line by line
for (byte y = 0; y<h; y++) {
readNCharsAt(datalen, offset + y*datalen, buf + 2);
drawBitmap(x0, y0 + (h - 1) - y, buf, color); // and draw it!
}
return BMP_OK;
}
byte slide;
at the bottom of the function, the drawbitmap function, the variables are listed differently than the gamebuinos and mine of course.
ok now on this tile map function.....
- Code: Select all
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, uint16_t color) {
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)) {
//this 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
//this drawBitmap(drawX, drawY, tile_width, tile_height, spritesheet[tile], dx, dy, dw, dh, color);
}
}
}
}
all right so if I want to use the tilemap with it I need to change these two lines
drawBitmap1(drawX, drawY, spritesheet[tile], tile_width, tile_height, color);
drawBitmap(drawX, drawY, tile_width, tile_height, spritesheet[tile], dx, dy, dw, dh, color);
ok so the first line is easy enough it uses the drawbitmap1 command I have for the color library. but I want it work with the new drawfrom sd command so do I make it read...
drawBitmapFromSD(x0, y0 + (h - 1) - y, buf, spritesheet[tile], tile_width, tile_height, color);
and the second goes like this?
drawBitmap(x0, y0 + (h - 1) - y, buf, tile_width, tile_height, spritesheet[tile], dx, dy, dw, dh, color);
Or how can I make a tilemap using the above code and how do I give them collision
Edit:::: when ever I try to compile mouguino's code I get a bunch of errors snout the petitfatfs and the declarations of byte. I could use some help please.
Edit the byte problem was coming from the teensy 3.2's print.h for some reason it had Byte in the file but I don't know how to fix it.
Other than that I guess the first part should have been getting the function to work. What is up with Int in front of the drawbitmapfromSD? Can that be void? Also the draw from SD commands use byte instead of int8_t. Can this be changed.
Edit:::::
Dec 5th 2016
I've almost got it. I had to change some stuff but I'm closer. The problem lies in the RX TX stuff at the top that says it's needed for the petitfatfs to work. It says that loop until set is not declared in this scope and points to the spif in the ().