OK I'm working on a gaming feature added to sumotoys ili93xx library and ive been able to get most everything going but I'm having two different problems. Both have to do with a tile map function.
The first part has to do with the tilemap function itself. What it does is allows you store a bunch of bitmaps within the same progmem space together and assigns them an integer in RAM that can be used in array like a .json file. It only stores the bitmaps once and uses the integer array to make a tilemap made up of different bitmap tiles.
When I first tried to implement the function in the library it was only showing about a quarter of the tile map in a corner. So I asked for help and someone pointed out that the uint8_t's and int16_t's to uint16_t and int16_t. That helped a bit and now shows only half of the tilemap in a corner.
The next part has to do with the int x and placement of a particular sprite or sets of sprites. Ok so if I want to tell a bitmap where to be I would usually just use the coordinates in the function. But what this does is uses this...
int player_x = 160;
int player_y = 120;
int player_direction = 2;
Then you use player_x and player_y in the bitmap function and it puts the bitmap at the starting point given above. like so......
if (tft.buttons.repeat(BTN_RIGHT,1));//{x--;}
if (tft.buttons.repeat(BTN_LEFT,1));//{x++;}
if (tft.buttons.repeat(BTN_DOWN,1));//{y--;}
if (tft.buttons.repeat(BTN_UP,1));//{y++;}
if(tft.buttons.repeat(BTN_DOWN,3)){
tft.drawBitmap1(player_x,player_y,paul_front_black,16,16,BLACK);
tft.drawBitmap1(player_x,player_y,paul_front_blue,16,16,BLUE);
tft.drawBitmap1(player_x,player_y,paul_front_brown,16,16,BROWN);
tft.drawBitmap1(player_x,player_y,paul_front_pink,16,16,PINK);
tft.drawBitmap1(player_x,player_y,paul_front_yellow,16,16,YELLOW);
player_direction = 2;
player_y = player_y + 1;}
if(player_y >= 40){
player_y = 40;}
Buuut it puts the bitmaps it puts the bitmaps being displayed at 32 and 32 instead. now the peculiar thing is that the player direction works.
void TFT_ILI93XX::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet, uint16_t color) {
drawTilemap(x, y, tilemap, spritesheet, 0, 0, TFT_ILI93XX_TFTWIDTH, TFT_ILI93XX_TFTHEIGHT, color);
}
void TFT_ILI93XX::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);
uint16_t tilemap_height = pgm_read_byte(tilemap + 1);
uint16_t tile_width = pgm_read_byte(tilemap + 2);
uint16_t tile_height = pgm_read_byte(tilemap + 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++) {
for (uint16_t ddx = startDdx; ddx < maxDdx; ddx++) {
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 TFT_ILI93XX::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) {
int8_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);
}
}
}
}
}
here is the .h part notice the int x and y which are supposed to be coordinates for the bitmap.
boolean getBitmapPixel(const uint8_t* bitmap, uint16_t x, uint16_t y);
void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet, uint16_t color);
void 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);
void 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);
typedef struct { //line 171 "Public Variables - ADD by Summoner123
int x; //X coordinate - ADD by Summoner123
int y; //Y coordinate - ADD by Summoner123
const byte *spritecol; //Sprite of object - ADD by Summoner123
}object;
object solid[60]; // Matriz were saved a Sprite, X and Y cordinates of all tiles on the screen - ADD by Summoner123
byte numcolision = 0; //count of solid objects indacat how many tiles drawed on the screen - ADD by Summoner123
bool flagcollision = true;