Hardware Reference
In-Depth Information
Figure 11-6. Four-color palette using black, red, green, and blue (from left to right)
The Gameduino Tools Online page ( http://gameduino.com/tools ) offers three great tools that convert image
files to the proper coding to avoid hand coding sprites, backgrounds and lossy images. The tool also provides an
Arduino sketch to quickly check the sprites on the display before putting them in a game. The tool provides a .h file
that contains the converted image. The three types of conversions tools background, sprite sheets and lossy image
conversion requires an image to convert. The sprite sheet tool also has options for the sprite size and color palette type.
The easiest way to get started making sprites is to use GIMP ( www.gimp.org/ ) —free, open source image
manipulation software that is capable of creating PNG files. When creating a new sprite image, it is best to work at
the actual pixel size and with dimensions in multiples of 16. Multiple different sprites can be made in one file, and the
conversion tool will divide them up according to the settings. Note that the conversion tool may not always get
the colors perfect and manual manipulation of the palette may be required in the Arduino sketch.
Coding Stack It
To get started coding Stack it, create a new sketch and add a new file within the Arduino IDE by pressing Ctrl+Shift+N,
and enter cube.h when prompted. Listing 11-2 contains the converted image from the Gameduino image tool—the
variables names in cube.h are generated by the image tool. Listing 11-2 uses only the image information and does
not include the function that is autogenerated by the image tool. Two static arrays are declared in cube.h . The first
is cube_sprimg[] , which is the mapping to the color palette, and the other is cube_sprpal[] . The bytes set in both
cube_sprimg[] and cube_sprpal[] are in the order they will be loaded into the Gameduino's memory. Because of the
little-endian mode of the Gameduino, the palette has the lower byte of the color set before the higher byte.
Listing 11-2. Sprite Code for Stack It
static PROGMEM prog_uchar cube_sprimg[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x02,0x01,0x01,0x01,0x01,0x02,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x02,0x01,0x01,0x01,0x01,0x02,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
static PROGMEM prog_uchar cube_sprpal[] = {
0x00,0x00, 0x00,0x7c, 0xe0,0x03, 0xff,0xff,
};
 
Search WWH ::




Custom Search