Mon Jul 20, 2015 12:04 am
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
// define some sprites
const byte sprite0[] PROGMEM = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
const byte sprite1[] PROGMEM = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
// define the spritesheet
const byte *spritesheet[] = {sprite0,sprite1};
// define the tilemap
const byte tilemap[] PROGMEM = {12,12,
8,8,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
};
void setup() {
// put your setup code here, to run once:
gb.begin();
gb.titleScreen(F("test"));
gb.display.clear();
gb.display.drawTilemap(-3,-1,tilemap,spritesheet,4,4,76,30); // draw the tilemap
gb.display.drawRect(2,2,80,34);
gb.display.update();
}
void loop() {
// put your main code here, to run repeatedly:
}
Mon Jul 20, 2015 12:44 am
#include <SPI.h>
#include <Gamebuino.h>
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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00000000,
},
// |
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.clear();
}
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.clear();
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 );
gb.display.update();
}
Tue Jul 21, 2015 8:48 pm
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 );
}
}
Wed Jul 22, 2015 12:38 am
Sorunome wrote:
You have some in-efficient code, though, allow me to make that more efficient:
...
The thing is you only need to update the screen if gb.update() returns true, so now you actually draw way fewer. I also set hte persistence to false so that the screen gets cleared automatically.
Sun Jul 26, 2015 10:39 pm