From 9ae00caefbcfd5ea5a29833ebd7a884336394ea1 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Sun, 19 Jul 2015 15:36:29 +0200 Subject: [PATCH 1/6] basic tilemapper, not much optimization done yet --- libraries/Gamebuino/Display.cpp | 22 ++++++++++++++++++++++ libraries/Gamebuino/Display.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/libraries/Gamebuino/Display.cpp b/libraries/Gamebuino/Display.cpp index 1d8a84e..4224cb0 100644 --- a/libraries/Gamebuino/Display.cpp +++ b/libraries/Gamebuino/Display.cpp @@ -681,6 +681,28 @@ void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, #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,int8_t dx,int8_t dy,int8_t dw,int8_t dh){ + uint8_t tilemap_width = pgm_read_byte(tilemap); + uint8_t tilemap_height = pgm_read_byte(tilemap + 1); + tilemap += 2; // now the first tiyleis at tilemap + uint8_t tile_width = pgm_read_byte(spritesheet[0]); + uint8_t tile_height = pgm_read_byte(spritesheet[0] + 1); + for(uint8_t ddy = 0;ddy < tilemap_height;ddy++){ + for(uint8_t ddx = 0;ddx < tilemap_width;ddx++){ + int drawX = ddx*tile_width + x; + int drawY = ddy*tile_height + y; + if(drawX > dw || drawY > dh || drawX < (dx-tile_width) || drawY < (dy - tile_height)){ + continue; + } + uint8_t tile = pgm_read_byte(tilemap + ddy*tilemap_width + ddx); + drawBitmap(drawX,drawY,spritesheet[tile]); + } + } +} + #if ARDUINO >= 100 size_t Display::write(uint8_t c) { #else diff --git a/libraries/Gamebuino/Display.h b/libraries/Gamebuino/Display.h index 26d1d29..66ba1c9 100644 --- a/libraries/Gamebuino/Display.h +++ b/libraries/Gamebuino/Display.h @@ -147,6 +147,9 @@ class Display : public Print { void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip); boolean getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y); + void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet); + void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet,int8_t dx,int8_t dy,int8_t dw,int8_t dh); + void setFont(const uint8_t* f); uint8_t fontWidth, fontHeight; void drawChar(int8_t x, int8_t y, unsigned char c, uint8_t size); From 9f60169fea458ab7d97e98661b70d43e6900576c Mon Sep 17 00:00:00 2001 From: Sorunome Date: Mon, 20 Jul 2015 01:18:20 +0200 Subject: [PATCH 2/6] more stuff --- libraries/Gamebuino/Display.cpp | 43 +++++++++++++++++++++++++++------ libraries/Gamebuino/Display.h | 3 ++- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/libraries/Gamebuino/Display.cpp b/libraries/Gamebuino/Display.cpp index 4224cb0..59126f7 100644 --- a/libraries/Gamebuino/Display.cpp +++ b/libraries/Gamebuino/Display.cpp @@ -618,6 +618,29 @@ void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap) { #endif } +void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh) { + 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 + 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)); } @@ -684,21 +707,27 @@ void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, 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,int8_t dx,int8_t dy,int8_t dw,int8_t dh){ +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); tilemap += 2; // now the first tiyleis at tilemap uint8_t tile_width = pgm_read_byte(spritesheet[0]); uint8_t tile_height = pgm_read_byte(spritesheet[0] + 1); + uint8_t ddw = dw + dx; + uint8_t ddh = dh + dy; for(uint8_t ddy = 0;ddy < tilemap_height;ddy++){ for(uint8_t ddx = 0;ddx < tilemap_width;ddx++){ - int drawX = ddx*tile_width + x; - int drawY = ddy*tile_height + y; - if(drawX > dw || drawY > dh || drawX < (dx-tile_width) || drawY < (dy - tile_height)){ - continue; + int drawX = ddx*tile_width + x + dx; + int drawY = ddy*tile_height + y + dy; + + if(drawX > (dx-tile_width) && drawY > (dy-tile_width) && drawX < ddw && drawY < ddh){ + 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,spritesheet[tile]); + }else{ // we need to draw a partial bitmap + drawBitmap(drawX,drawY,spritesheet[tile],dx,dy,dw,dh); + } } - uint8_t tile = pgm_read_byte(tilemap + ddy*tilemap_width + ddx); - drawBitmap(drawX,drawY,spritesheet[tile]); } } } diff --git a/libraries/Gamebuino/Display.h b/libraries/Gamebuino/Display.h index 66ba1c9..2329d08 100644 --- a/libraries/Gamebuino/Display.h +++ b/libraries/Gamebuino/Display.h @@ -145,10 +145,11 @@ class Display : public Print { void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap); void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip); + void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh); boolean getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y); void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet); - void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet,int8_t dx,int8_t dy,int8_t dw,int8_t dh); + void 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); void setFont(const uint8_t* f); uint8_t fontWidth, fontHeight; From 4acd7dee258f4c985407b30b55bc8ae48cca168b Mon Sep 17 00:00:00 2001 From: Sorunome Date: Mon, 20 Jul 2015 01:50:03 +0200 Subject: [PATCH 3/6] speed optimizations --- libraries/Gamebuino/Display.cpp | 37 ++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/libraries/Gamebuino/Display.cpp b/libraries/Gamebuino/Display.cpp index 59126f7..e800b06 100644 --- a/libraries/Gamebuino/Display.cpp +++ b/libraries/Gamebuino/Display.cpp @@ -715,18 +715,31 @@ void Display::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t ** uint8_t tile_height = pgm_read_byte(spritesheet[0] + 1); uint8_t ddw = dw + dx; uint8_t ddh = dh + dy; - for(uint8_t ddy = 0;ddy < tilemap_height;ddy++){ - for(uint8_t ddx = 0;ddx < tilemap_width;ddx++){ - int drawX = ddx*tile_width + x + dx; - int drawY = ddy*tile_height + y + dy; - - if(drawX > (dx-tile_width) && drawY > (dy-tile_width) && drawX < ddw && drawY < ddh){ - 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,spritesheet[tile]); - }else{ // we need to draw a partial bitmap - drawBitmap(drawX,drawY,spritesheet[tile],dx,dy,dw,dh); - } + 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; + } + 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,spritesheet[tile]); + }else{ // we need to draw a partial bitmap + drawBitmap(drawX,drawY,spritesheet[tile],dx,dy,dw,dh); } } } From b2ef52f4221c3b7b92def9a488b5055995c6b953 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Wed, 22 Jul 2015 00:29:52 +0200 Subject: [PATCH 4/6] added example --- .../5.Reference/display/tilemap/tilemap.ino | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino diff --git a/libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino b/libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino new file mode 100644 index 0000000..bf90e71 --- /dev/null +++ b/libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino @@ -0,0 +1,143 @@ +#include +#include +Gamebuino gb; + + //map followed by tilesprites + + const byte + + tilemap[] PROGMEM = {24,24, + 0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,6,1,1,3,0,4,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,2,0,6,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 1,1,1,1,8,1,1,1,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,2,0,0,0,0,6,1,1,1,1,8,0,0,0,0,0,0,0,0,0, + 0,0,0,0,2,0,0,4,1,1,1,1,1,1,8,1,1,1,1,3,0,0,0,0, + 0,0,4,1,8,1,1,5,0,0,0,0,0,0,2,0,0,0,0,6,1,1,1,1, + 0,0,2,0,6,1,1,1,1,3,0,0,0,0,2,0,0,0,0,0,0,0,0,0, + 0,0,2,0,0,0,0,0,0,2,0,0,0,0,6,1,1,3,0,0,0,0,0,0, + 1,1,5,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0, + 0,0,0,0,2,0,0,0,0,8,3,0,0,0,0,0,0,2,0,0,0,0,0,0, + 0,0,0,1,8,1,0,0,0,8,5,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,2,0,0,0,0,8,3,0,0,0,4,3,0,0,4,3,0,0,0,0, + 0,0,0,0,0,0,0,0,0,8,5,0,0,0,6,5,0,0,6,5,0,0,0,0, + 0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0,0,0,0,2,0,0,0, + 0,0,0,4,1,1,1,1,1,5,0,0,0,6,1,1,1,1,1,1,5,0,0,0, + 0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0, + 0,0,0,2,0,0,0,0,0,0,0,0,2,0,0,0,0,8,0,0,0,0,0,0, + 0,0,0,2,0,0,0,0,0,0,2,0,2,0,0,0,0,0,8,0,0,0,0,0, + 0,0,0,2,0,0,0,0,2,0,2,0,2,0,0,0,0,0,0,8,0,0,0,0, + + + }, + + + sprite0[] PROGMEM = {5,5, + B00000000, + B00000000, + B00000000, + B00000000, + B00000000, + }, + + // - + sprite1[] PROGMEM = {5,5, + B00000000, + B11111000, + B10001000, + B11111000, + B00000000, + }, + + // | + sprite2[] PROGMEM = {5,5, + B01110000, + B01010000, + B01010000, + B01010000, + B01110000, + }, + + // -. + sprite3[] PROGMEM = {5,5, + B00000000, + B11100000, + B10110000, + B11010000, + B01110000, + }, + + // .- + sprite4[] PROGMEM = {5,5, + B00000000, + B00111000, + B01101000, + B01011000, + B01110000, + }, + + // -' + sprite5[] PROGMEM = {5,5, + B01110000, + B11010000, + B10110000, + B11100000, + B00000000, + }, + + // '- + sprite6[] PROGMEM = {5,5, + B01110000, + B01011000, + B01101000, + B00111000, + B00000000, + }, + + + // '- + sprite7[] PROGMEM = {5,5, + B11111000, + B10001000, + B10001000, + B10001000, + B11111000, + }, + + // '- + sprite8[] PROGMEM = {5,5, + B01110000, + B11011000, + B10000000, + B11011000, + B01110000, + }; + + +// define the spritesheet +const byte *spritesheet[] = {sprite0,sprite1,sprite2,sprite3,sprite4,sprite5,sprite6,sprite7,sprite8}; + + + +int x=0,y=0; + +void setup() { + gb.begin(); + gb.titleScreen(F("test")); + gb.display.persistence = false; +} +void loop() { + if(gb.update()){ + if (gb.buttons.repeat(BTN_RIGHT,1)){x--;} + if (gb.buttons.repeat(BTN_LEFT,1)){x++;} + if (gb.buttons.repeat(BTN_DOWN,1)){y--;} + if (gb.buttons.repeat(BTN_UP,1)){y++;} + gb.display.drawTilemap(x,y,tilemap,spritesheet); // draw the tilemap + gb.display.drawRect(2,2,x,y); + gb.display.cursorY = 12; gb.display.println( x );gb.display.println( y ); + } +} From 044cf2cb635b4af1a8254087e6e99efe46025043 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Wed, 22 Jul 2015 03:02:26 +0200 Subject: [PATCH 5/6] updated example --- .../5.Reference/display/tilemap/tilemap.ino | 97 +++++++++---------- 1 file changed, 47 insertions(+), 50 deletions(-) diff --git a/libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino b/libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino index bf90e71..3198793 100644 --- a/libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino +++ b/libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino @@ -6,7 +6,7 @@ Gamebuino gb; const byte - tilemap[] PROGMEM = {24,24, +tilemap[] PROGMEM = {24,24, 0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,6,1,1,3,0,4,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,2,0,6,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -30,91 +30,89 @@ Gamebuino gb; 0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0, 0,0,0,2,0,0,0,0,0,0,0,0,2,0,0,0,0,8,0,0,0,0,0,0, 0,0,0,2,0,0,0,0,0,0,2,0,2,0,0,0,0,0,8,0,0,0,0,0, - 0,0,0,2,0,0,0,0,2,0,2,0,2,0,0,0,0,0,0,8,0,0,0,0, - - + 0,0,0,2,0,0,0,0,2,0,2,0,2,0,0,0,0,0,0,8,0,0,0,0 }, sprite0[] PROGMEM = {5,5, - B00000000, - B00000000, - B00000000, - B00000000, - B00000000, + B00000000, + B00000000, + B00000000, + B00000000, + B00000000, }, // - sprite1[] PROGMEM = {5,5, - B00000000, - B11111000, - B10001000, - B11111000, - B00000000, + B00000000, + B11111000, + B10001000, + B11111000, + B00000000, }, // | sprite2[] PROGMEM = {5,5, - B01110000, - B01010000, - B01010000, - B01010000, - B01110000, + B01110000, + B01010000, + B01010000, + B01010000, + B01110000, }, // -. sprite3[] PROGMEM = {5,5, - B00000000, - B11100000, - B10110000, - B11010000, - B01110000, + B00000000, + B11100000, + B10110000, + B11010000, + B01110000, }, // .- sprite4[] PROGMEM = {5,5, - B00000000, - B00111000, - B01101000, - B01011000, - B01110000, + B00000000, + B00111000, + B01101000, + B01011000, + B01110000, }, // -' sprite5[] PROGMEM = {5,5, - B01110000, - B11010000, - B10110000, - B11100000, - B00000000, + B01110000, + B11010000, + B10110000, + B11100000, + B00000000, }, // '- sprite6[] PROGMEM = {5,5, - B01110000, - B01011000, - B01101000, - B00111000, - B00000000, + B01110000, + B01011000, + B01101000, + B00111000, + B00000000, }, // '- sprite7[] PROGMEM = {5,5, - B11111000, - B10001000, - B10001000, - B10001000, - B11111000, + B11111000, + B10001000, + B10001000, + B10001000, + B11111000, }, // '- sprite8[] PROGMEM = {5,5, - B01110000, - B11011000, - B10000000, - B11011000, - B01110000, + B01110000, + B11011000, + B10000000, + B11011000, + B01110000, }; @@ -137,7 +135,6 @@ void loop() { if (gb.buttons.repeat(BTN_DOWN,1)){y--;} if (gb.buttons.repeat(BTN_UP,1)){y++;} gb.display.drawTilemap(x,y,tilemap,spritesheet); // draw the tilemap - gb.display.drawRect(2,2,x,y); gb.display.cursorY = 12; gb.display.println( x );gb.display.println( y ); } } From 30c11ca4e70a395291c53047f92d3c67211a41ea Mon Sep 17 00:00:00 2001 From: Sorunome Date: Mon, 27 Jul 2015 00:38:27 +0200 Subject: [PATCH 6/6] more size efficient tilemaps --- libraries/Gamebuino/Display.cpp | 19 +++++++++-------- libraries/Gamebuino/Display.h | 3 ++- .../5.Reference/display/tilemap/tilemap.ino | 21 +++++++++---------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/libraries/Gamebuino/Display.cpp b/libraries/Gamebuino/Display.cpp index e800b06..6076dda 100644 --- a/libraries/Gamebuino/Display.cpp +++ b/libraries/Gamebuino/Display.cpp @@ -496,6 +496,10 @@ 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) { #if (ENABLE_BITMAPS > 0) /* original code int8_t i, j, byteWidth = (w + 7) / 8; @@ -618,10 +622,7 @@ void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap) { #endif } -void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh) { - 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 +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; @@ -710,9 +711,9 @@ void Display::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t ** 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); - tilemap += 2; // now the first tiyleis at tilemap - uint8_t tile_width = pgm_read_byte(spritesheet[0]); - uint8_t tile_height = pgm_read_byte(spritesheet[0] + 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; @@ -737,9 +738,9 @@ void Display::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t ** 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,spritesheet[tile]); + drawBitmap(drawX,drawY,tile_width,tile_height,spritesheet[tile]); }else{ // we need to draw a partial bitmap - drawBitmap(drawX,drawY,spritesheet[tile],dx,dy,dw,dh); + drawBitmap(drawX,drawY,tile_width,tile_height,spritesheet[tile],dx,dy,dw,dh); } } } diff --git a/libraries/Gamebuino/Display.h b/libraries/Gamebuino/Display.h index 2329d08..665ada5 100644 --- a/libraries/Gamebuino/Display.h +++ b/libraries/Gamebuino/Display.h @@ -144,8 +144,9 @@ class Display : public Print { void fillRoundRect(int8_t x0, int8_t y0, int8_t w, int8_t h, int8_t radius); void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap); + void drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h , const uint8_t *bitmap); void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip); - void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh); + 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); boolean getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y); void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet); diff --git a/libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino b/libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino index 3198793..001b26b 100644 --- a/libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino +++ b/libraries/Gamebuino/examples/5.Reference/display/tilemap/tilemap.ino @@ -7,6 +7,7 @@ Gamebuino gb; const byte tilemap[] PROGMEM = {24,24, + 5,5, 0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,6,1,1,3,0,4,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,2,0,6,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -33,8 +34,7 @@ tilemap[] PROGMEM = {24,24, 0,0,0,2,0,0,0,0,2,0,2,0,2,0,0,0,0,0,0,8,0,0,0,0 }, - - sprite0[] PROGMEM = {5,5, + sprite0[] PROGMEM = { B00000000, B00000000, B00000000, @@ -43,7 +43,7 @@ tilemap[] PROGMEM = {24,24, }, // - - sprite1[] PROGMEM = {5,5, + sprite1[] PROGMEM = { B00000000, B11111000, B10001000, @@ -52,7 +52,7 @@ tilemap[] PROGMEM = {24,24, }, // | - sprite2[] PROGMEM = {5,5, + sprite2[] PROGMEM = { B01110000, B01010000, B01010000, @@ -61,7 +61,7 @@ tilemap[] PROGMEM = {24,24, }, // -. - sprite3[] PROGMEM = {5,5, + sprite3[] PROGMEM = { B00000000, B11100000, B10110000, @@ -70,7 +70,7 @@ tilemap[] PROGMEM = {24,24, }, // .- - sprite4[] PROGMEM = {5,5, + sprite4[] PROGMEM = { B00000000, B00111000, B01101000, @@ -79,7 +79,7 @@ tilemap[] PROGMEM = {24,24, }, // -' - sprite5[] PROGMEM = {5,5, + sprite5[] PROGMEM = { B01110000, B11010000, B10110000, @@ -88,7 +88,7 @@ tilemap[] PROGMEM = {24,24, }, // '- - sprite6[] PROGMEM = {5,5, + sprite6[] PROGMEM = { B01110000, B01011000, B01101000, @@ -98,7 +98,7 @@ tilemap[] PROGMEM = {24,24, // '- - sprite7[] PROGMEM = {5,5, + sprite7[] PROGMEM = { B11111000, B10001000, B10001000, @@ -107,7 +107,7 @@ tilemap[] PROGMEM = {24,24, }, // '- - sprite8[] PROGMEM = {5,5, + sprite8[] PROGMEM = { B01110000, B11011000, B10000000, @@ -115,7 +115,6 @@ tilemap[] PROGMEM = {24,24, B01110000, }; - // define the spritesheet const byte *spritesheet[] = {sprite0,sprite1,sprite2,sprite3,sprite4,sprite5,sprite6,sprite7,sprite8};