Hey, and welcome among us
Your game looks great, I hope you'll manage to make it work... to help I made you a quick example about animated sprites :
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
#define NUM_FRAME_SMALL 5
const byte smallEnemyBitmap[NUM_FRAME_SMALL][10] PROGMEM = {
{ 8, 8, 0x0, 0x7E, 0x6C, 0x6C, 0x7E, 0x7E, 0x7E, 0x66,},
{ 8, 8, 0x7E, 0x6C, 0x6C, 0x7E, 0x7E, 0x3C, 0x3C, 0xC,},
{ 8, 8, 0x7E, 0x6C, 0x6C, 0x7E, 0x7E, 0x38, 0x38, 0x18,},
{ 8, 8, 0x7E, 0x6C, 0x6C, 0x7E, 0x7E, 0x1C, 0x1C, 0x18,},
{ 8, 8, 0x0, 0x7E, 0x6C, 0x6C, 0x7E, 0x7E, 0x3C, 0x30,}
};
#define NUM_FRAME_BIG 6
const byte bigEnemyBitmap[NUM_FRAME_BIG][22] PROGMEM = {
{ 16, 10, 0x0, 0x0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3D, 0xA0, 0x3D, 0xA0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3F, 0xE0, 0x38, 0xE0, 0x38, 0xE0,},
{ 16, 10, 0x0, 0x0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3D, 0xA0, 0x3D, 0xA0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3F, 0xE0, 0x1, 0xC0,},
{ 16, 10, 0x3F, 0xE0, 0x3F, 0xE0, 0x3D, 0xA0, 0x3D, 0xA0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3F, 0xE0, 0xF, 0x0, 0x7, 0x0,},
{ 16, 10, 0x3F, 0xE0, 0x3F, 0xE0, 0x3D, 0xA0, 0x3D, 0xA0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3F, 0xE0, 0x7, 0x80, 0x7, 0x0,},
{ 16, 10, 0x3F, 0xE0, 0x3F, 0xE0, 0x3D, 0xA0, 0x3D, 0xA0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3F, 0xE0, 0xF, 0x80, 0xE, 0x0,},
{ 16, 10, 0x3F, 0xE0, 0x3F, 0xE0, 0x3D, 0xA0, 0x3D, 0xA0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3F, 0xE0, 0x3F, 0xE0, 0x1D, 0xC0, 0x1C, 0x0,}
};
void setup(){
gb.begin();
gb.titleScreen(F("Animated Sprite"));
}
void loop(){
if(gb.update()){
byte frame = gb.frameCount % NUM_FRAME_SMALL;
gb.display.drawBitmap(10, 40, smallEnemyBitmap[frame]);
frame = (gb.frameCount/2) % NUM_FRAME_SMALL;
gb.display.drawBitmap(20, 40, smallEnemyBitmap[frame], NOROT, FLIPH);
frame = gb.frameCount % NUM_FRAME_BIG;
gb.display.drawBitmap(30, 38, bigEnemyBitmap[frame]);
}
}
In short you make an array of bitmaps, and access the frame you want each time. In the example, it's based on gb.frameCount so it runs at a constant speed. When I want to animate walking characters, I base the frame to play on the X coordinate of the character, so the faster it moves along the X axis, the faster it's animated (as in
Super Crate Buino).
Edit : for dynamic tilemaps, you can refer to the
TileMapRAM example. If your tilemap won't change after compilation, it's better to store it into the progmem rather than RAM (as RAM is pretty scarce), like I did in [urlhttp://gamebuino.com/forum/viewtopic.php?f=17&t=972]UFO Race[/url].
PS: I've been to the Gouffre de Padirac once when I was young (well I'm still young but you get my point)