hi guys
iv e been working on a gaming library that supports a color oled screen. I seem to have fixed everything but the tile map function and definition and I really don't know how to fix it. I tried adding color arguments to the old bitmap functions which seems to work in a way but it still points to two definitions with in the tileMap() routines function definition..
cpp definition all bitmap plus tilemap
void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap) {
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);
}
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) {
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);
}
}
}
}
}
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) {
if((rotation == NOROT) && (flip == NOFLIP)){
drawBitmap(x,y,bitmap); //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
#if (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);
}
}
}
}