Part 1: Configuring, Programming, and Compiling
Part 2: Placing Tiles and Moving Sprites
Part 4: Colliding Sprites and Project Management
Placing Tiles
As was covered in Part 1, the Game Boy uses two main sections of graphical memory: sprites and background. In order to place a tile for the background, it must be in the background. In order to place a tile for a sprite, it must be in the sprite memory. (There are ways to read and write directly to the different memory locations using GBDK functions and effectively swap things, but that’s a much more advanced topic.)
For our example of using background tiles, we will be printing the classic words “Hello world.” However, to do that, we need tiles to actually write.
alpha.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned char alpha[] = | |
{ | |
0x7C,0x7C,0x86,0x86,0x8A,0x8A,0x92,0x92,0xA2,0xA2,0xC2,0xC2,0x7C,0x7C,0x00,0x00,0x10,0x10,0x30,0x30,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x7C,0x00,0x00, | |
0x7C,0x7C,0x82,0x82,0x02,0x02,0x1C,0x1C,0x60,0x60,0x80,0x80,0xFE,0xFE,0x00,0x00,0xFE,0xFE,0x04,0x04,0x18,0x18,0x04,0x04,0x02,0x02,0x82,0x82,0x7C,0x7C,0x00,0x00, | |
0x0C,0x0C,0x14,0x14,0x24,0x24,0x44,0x44,0x84,0x84,0xFE,0xFE,0x04,0x04,0x00,0x00,0xFC,0xFC,0x80,0x80,0xFC,0xFC,0x02,0x02,0x02,0x02,0x82,0x82,0x7C,0x7C,0x00,0x00, | |
0x7C,0x7C,0x80,0x80,0x80,0x80,0xFC,0xFC,0x82,0x82,0x82,0x82,0x7C,0x7C,0x00,0x00,0xFE,0xFE,0x82,0x82,0x04,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00, | |
0x7C,0x7C,0x82,0x82,0x82,0x82,0x7C,0x7C,0x82,0x82,0x82,0x82,0x7C,0x7C,0x00,0x00,0x7C,0x7C,0x82,0x82,0x82,0x82,0x7E,0x7E,0x02,0x02,0x02,0x02,0x7C,0x7C,0x00,0x00, | |
0x00,0x00,0x30,0x30,0x30,0x30,0x00,0x00,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x00,0x00,0x30,0x30,0x10,0x10,0x20,0x20,0x00,0x00, | |
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x08,0x08,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | |
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x00,0x00,0x01,0x01,0x02,0x02,0x04,0x04,0x08,0x08,0x10,0x10,0x20,0x20,0x40,0x40,0x00,0x00, | |
0x7C,0x7C,0x82,0x82,0x9A,0x9A,0xAA,0xAA,0xBC,0xBC,0x80,0x80,0x7C,0x7C,0x00,0x00,0x38,0x38,0x44,0x44,0x82,0x82,0x82,0x82,0xFE,0xFE,0x82,0x82,0x82,0x82,0x00,0x00, | |
0xFC,0xFC,0x82,0x82,0x82,0x82,0xFC,0xFC,0x82,0x82,0x82,0x82,0xFC,0xFC,0x00,0x00,0x7C,0x7C,0x82,0x82,0x80,0x80,0x80,0x80,0x80,0x80,0x82,0x82,0x7C,0x7C,0x00,0x00, | |
0xF8,0xF8,0x84,0x84,0x82,0x82,0x82,0x82,0x82,0x82,0x84,0x84,0xF8,0xF8,0x00,0x00,0xFE,0xFE,0x80,0x80,0x80,0x80,0xFC,0xFC,0x80,0x80,0x80,0x80,0xFE,0xFE,0x00,0x00, | |
0xFE,0xFE,0x80,0x80,0x80,0x80,0xFC,0xFC,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x7C,0x7C,0x82,0x82,0x80,0x80,0x80,0x80,0x8E,0x8E,0x82,0x82,0x7E,0x7E,0x00,0x00, | |
0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x00,0x00,0x7C,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x7C,0x00,0x00, | |
0x1E,0x1E,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x84,0x84,0x78,0x78,0x00,0x00,0x84,0x84,0x88,0x88,0x90,0x90,0xF0,0xF0,0x88,0x88,0x84,0x84,0x82,0x82,0x00,0x00, | |
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7E,0x7E,0x00,0x00,0x82,0x82,0xC6,0xC6,0xAA,0xAA,0x92,0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x00,0x00, | |
0x82,0x82,0xC2,0xC2,0xA2,0xA2,0x92,0x92,0x8A,0x8A,0x86,0x86,0x82,0x82,0x00,0x00,0x7C,0x7C,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x7C,0x7C,0x00,0x00, | |
0xFC,0xFC,0x82,0x82,0x82,0x82,0x82,0x82,0xFC,0xFC,0x80,0x80,0x80,0x80,0x00,0x00,0x7C,0x7C,0x82,0x82,0x82,0x82,0x92,0x92,0x8A,0x8A,0x84,0x84,0x7A,0x7A,0x00,0x00, | |
0xFC,0xFC,0x82,0x82,0x82,0x82,0x84,0x84,0xF8,0xF8,0x84,0x84,0x82,0x82,0x00,0x00,0x7C,0x7C,0x80,0x80,0x80,0x80,0x7C,0x7C,0x02,0x02,0x02,0x02,0xFC,0xFC,0x00,0x00, | |
0xFE,0xFE,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x7C,0x7C,0x00,0x00, | |
0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x44,0x44,0x28,0x28,0x10,0x10,0x00,0x00,0x82,0x82,0x82,0x82,0x82,0x82,0x92,0x92,0xAA,0xAA,0xC6,0xC6,0x82,0x82,0x00,0x00, | |
0x82,0x82,0x44,0x44,0x28,0x28,0x10,0x10,0x28,0x28,0x44,0x44,0x82,0x82,0x00,0x00,0x82,0x82,0x44,0x44,0x28,0x28,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00, | |
0xFE,0xFE,0x04,0x04,0x08,0x08,0x10,0x10,0x20,0x20,0x40,0x40,0xFE,0xFE,0x00,0x00,0x1C,0x1C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1C,0x1C,0x00,0x00, | |
0x80,0x80,0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,0x02,0x02,0x00,0x00,0x70,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x70,0x70,0x00,0x00, | |
0x10,0x10,0x28,0x28,0x44,0x44,0x82,0x82,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0x00,0x00 | |
}; |
Download or copy the content of “alpha.c” into a file named exactly that: alpha.c.
Note: As was mentioned in Part 1, tiles are represented as collections of hexadecimal numbers. The array alpha is 47 tiles representing numbers 0 – 9, 26 capital letters, and some additional punctuation.
Next, in order to display these tiles, we will change the “main.c” from Part 1 to load these tiles and then display a pattern of them.
main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gb/gb.h> | |
#include "alpha.c" | |
void init(); | |
void checkInput(); | |
void updateSwitches(); | |
void main() { | |
init(); | |
while(1) { | |
checkInput(); // Check for user input (and act on it) | |
updateSwitches(); // Make sure the SHOW_SPRITES and SHOW_BKG switches are on each loop | |
wait_vbl_done(); // Wait until VBLANK to avoid corrupting visual memory | |
} | |
} | |
void init() { | |
DISPLAY_ON; // Turn on the display | |
set_bkg_data(0, 47, alpha); // Load 47 tiles into background memory | |
} | |
void updateSwitches() { | |
HIDE_WIN; | |
SHOW_SPRITES; | |
SHOW_BKG; | |
} | |
void checkInput() { | |
if (joypad() & J_B) { | |
// The B button was pressed! | |
} | |
} |
Running the build script will produce the following response when run in an emulator.

While not particularly useful as a first demonstration, it shows two things:
- Unless changed, the background remains whatever was last written to it
- The Game Boy hardware makes assumptions. In this case, when reset, it makes its background tile memory to be all zeros. Without other instructions, it took the first tile, a ‘0’, and repeated it across the entire screen.
To print “Hello world” we need one additional thing: an array of tile locations.
In programming Game Boy games, it is often much more convenient to produce a ‘map’ of where you want tiles to go and then use this map instead of arranging tiles one at a time. In fact, GBDK’s API is built with this in mind. Using an additional function set_bkg_tiles, we can write out a section of tiles at a time. However, before we can call it, we need that map.
helloWorld.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned char helloWorld[] = | |
{ | |
0x30,0x18,0x15,0x1C,0x1C,0x1F,0x30,0x30,0x30,0x30, | |
0x30,0x27,0x1F,0x22,0x1C,0x14,0x30,0x30,0x30,0x30 | |
}; |
Like with “alpha.c”, copy or download “helloWorld.c” and add it to the folder containing the other files.
To use the map, we need to update “main.c”.
main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gb/gb.h> | |
#include "alpha.c" | |
#include "helloWorld.c" | |
void init(); | |
void checkInput(); | |
void updateSwitches(); | |
void main() { | |
init(); | |
while(1) { | |
checkInput(); // Check for user input (and act on it) | |
updateSwitches(); // Make sure the SHOW_SPRITES and SHOW_BKG switches are on each loop | |
wait_vbl_done(); // Wait until VBLANK to avoid corrupting memory | |
} | |
} | |
void init() { | |
DISPLAY_ON; // Turn on the display | |
set_bkg_data(0, 47, alpha); // Load 47 tiles into background memory | |
// Use the 'helloWorld' array to write background tiles starting at 0,6 (tile positions) | |
// and write for 10 tiles in width and 2 tiles in height | |
set_bkg_tiles(0,6,10,2,helloWorld); | |
} | |
void updateSwitches() { | |
HIDE_WIN; | |
SHOW_SPRITES; | |
SHOW_BKG; | |
} | |
void checkInput() { | |
if (joypad() & J_B) { | |
// The B button was pressed! | |
} | |
} |
After building the new files, we get a different response:

Note: Within the helloWorld array, I used “0x30” as a blank. This is tile position 48. Yet, remember, only 47 tiles were loaded. The 48th tile position, like with the other hardware assumption of showing all zeros, is because the background is reset, too. Without loading a new tile in that position, it will remain blank.
Finally, before getting to input and moving sprites around on the screen, we will do one more thing: create an additional blank map. As explained in the above note, the 48th position in the background table is blank. So, in order to create a blank screen, we can use this as we did with the helloWorld array. We simply create a new map of 20 tiles by 18 tiles (or 160 pixels by 144 pixels).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned char blankScreen[] = | |
{ | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, | |
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30 | |
}; |
And, finally, adjusting our “main.c” to use this additional map, and to sneak in some user input, here’s the updated version.
main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gb/gb.h> | |
#include "alpha.c" | |
#include "helloWorld.c" | |
#include "blankScreen.c" | |
void init(); | |
void checkInput(); | |
void updateSwitches(); | |
void main() { | |
init(); | |
while(1) { | |
checkInput(); // Check for user input (and act on it) | |
updateSwitches(); // Make sure the SHOW_SPRITES and SHOW_BKG switches are on each loop | |
wait_vbl_done(); // Wait until VBLANK to avoid corrupting memory | |
} | |
} | |
void init() { | |
DISPLAY_ON; // Turn on the display | |
set_bkg_data(0, 47, alpha); // Load 47 tiles into background memory | |
// Use the 'helloWorld' array to write background tiles starting at 0,6 (tile positions) | |
// and write for 10 tiles in width and 2 tiles in height | |
set_bkg_tiles(0,6,10,2,helloWorld); | |
} | |
void updateSwitches() { | |
HIDE_WIN; | |
SHOW_SPRITES; | |
SHOW_BKG; | |
} | |
void checkInput() { | |
if (joypad() & J_B) { | |
// Use the 'blankScreen' array to write background tiles starting at 0,0 (tile positions) | |
// and for 20 tiles in width and 18 tiles in height | |
set_bkg_tiles(0,0,20,18,blankScreen); | |
} | |
} |
Now, when we press ‘B’, we write a new map of ‘blank’ tiles over the old output, effectively creating a blank screen.
Note: It is far more efficient to set the first tile of the background table to be ‘blank.’ That way, by default, the screen will show either all dark or white, depending on your needs. However, for the sake of the above examples, it is worth showing how using the assumptions of the hardware against itself can save time and later effort.
Moving Sprites
Sprites work much like background tiles. They are loaded and used with functionality that works the same way internally. However, like with background tiles, we need some sprite tiles to work with before we can begin to move them around in any manner.
sprites.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned char sprites[] = | |
{ | |
0x7E,0x7E,0x81,0x81,0xA5,0xA5,0x81,0x81, | |
0x81,0x81,0xBD,0xBD,0x81,0x81,0x7E,0x7E, | |
0x7E,0x7E,0x81,0x81,0xA5,0xA5,0x81,0x81, | |
0x99,0x99,0xA5,0xA5,0x81,0x81,0x7E,0x7E | |
}; |
With the introduction of an additional file to include, we need to change “main.c” once again. We also need to introduce some new functions in order to use the sprites.
main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gb/gb.h> | |
#include "alpha.c" | |
#include "helloWorld.c" | |
#include "blankScreen.c" | |
#include "sprites.c" | |
void init(); | |
void checkInput(); | |
void updateSwitches(); | |
// The player array will hold the player's position as X ([0]) and Y ([1]) | |
UINT8 player[2]; | |
void main() { | |
init(); | |
while(1) { | |
checkInput(); // Check for user input (and act on it) | |
updateSwitches(); // Make sure the SHOW_SPRITES and SHOW_BKG switches are on each loop | |
wait_vbl_done(); // Wait until VBLANK to avoid corrupting memory | |
} | |
} | |
void init() { | |
DISPLAY_ON; // Turn on the display | |
set_bkg_data(0, 47, alpha); // Load 47 tiles into background memory | |
// Use the 'helloWorld' array to write background tiles starting at 0,6 (tile positions) | |
// and write for 10 tiles in width and 2 tiles in height | |
set_bkg_tiles(0,6,10,2,helloWorld); | |
// Load the the 'sprites' tiles into sprite memory | |
set_sprite_data(0, 1, sprites); | |
// Set the first movable sprite (0) to be the first tile in the sprite memory (0) | |
set_sprite_tile(0,0); | |
player[0] = 80; | |
player[1] = 72; | |
} | |
void updateSwitches() { | |
HIDE_WIN; | |
SHOW_SPRITES; | |
SHOW_BKG; | |
} | |
void checkInput() { | |
if (joypad() & J_B) { | |
// Use the 'blankScreen' array to write background tiles starting at 0,0 (tile positions) | |
// and for 20 tiles in width and 18 tiles in height | |
set_bkg_tiles(0,0,20,18,blankScreen); | |
} | |
} |
The function set_sprite_data works like set_bkg_data to load some array of values into sprite memory. set_sprite_tile assigns the first movable sprite to be some tile from the sprite tile set. In the above case, it uses the first tile in the sprite tile set.
Note: There is a hard limit to the number of moving sprites at a time set at 20 (0 – 19) with only 10 sprites moving per line. GBDK stores addresses for these moving sprites, which can be accessed through the set_sprite_tile function. To move larger sets of tiles at a time, especially in the case of larger visual sprites, multiple calls to set_sprite_tile are needed.
While our current code loads and prepares sprites for movement, it does not do anything quite yet. To move a sprite, we need the move_sprite function.
main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gb/gb.h> | |
#include "alpha.c" | |
#include "helloWorld.c" | |
#include "blankScreen.c" | |
#include "sprites.c" | |
void init(); | |
void checkInput(); | |
void updateSwitches(); | |
// The player array will hold the player's position as X ([0]) and Y ([1]) | |
UINT8 player[2]; | |
void main() { | |
init(); | |
while(1) { | |
checkInput(); // Check for user input (and act on it) | |
updateSwitches(); // Make sure the SHOW_SPRITES and SHOW_BKG switches are on each loop | |
wait_vbl_done(); // Wait until VBLANK to avoid corrupting memory | |
} | |
} | |
void init() { | |
DISPLAY_ON; // Turn on the display | |
set_bkg_data(0, 47, alpha); // Load 47 tiles into background memory | |
// Use the 'helloWorld' array to write background tiles starting at 0,6 (tile positions) | |
// and write for 10 tiles in width and 2 tiles in height | |
set_bkg_tiles(0,6,10,2,helloWorld); | |
// Load the the 'sprites' tiles into sprite memory | |
set_sprite_data(0, 1, sprites); | |
// Set the first movable sprite (0) to be the first tile in the sprite memory (0) | |
set_sprite_tile(0,0); | |
player[0] = 80; | |
player[1] = 72; | |
} | |
void updateSwitches() { | |
HIDE_WIN; | |
SHOW_SPRITES; | |
SHOW_BKG; | |
} | |
void checkInput() { | |
if (joypad() & J_B) { | |
// Use the 'blankScreen' array to write background tiles starting at 0,0 (tile positions) | |
// and for 20 tiles in width and 18 tiles in height | |
set_bkg_tiles(0,0,20,18,blankScreen); | |
} | |
// UP | |
if (joypad() & J_UP) { | |
player[1]–; | |
} | |
// DOWN | |
if (joypad() & J_DOWN) { | |
player[1]++; | |
} | |
// LEFT | |
if (joypad() & J_LEFT) { | |
player[0]–; | |
} | |
// RIGHT | |
if (joypad() & J_RIGHT) { | |
player[0]++; | |
} | |
// Move the sprite in the first movable sprite list (0) | |
// the the position of X (player[0]) and y (player[1]) | |
move_sprite(0, player[0], player[1]); | |
} |
Now, after adding in some additional checks for user input and using the move_sprite function, we can move a sprite around on the screen using the directional input.
Note: The below GIF demonstrates one of my favorite aspects of the Game Boy: screen wrap. Without some type of checks in place, a sprite can move all the way ‘right’ and end up back on the edge of the left side.
With loading background and sprite tiles and then moving them around, we can make most of the games which came out for the original Game Boy. It may not seem that way, of course, but most of the ‘work’ in programming Game Boy games comes not in the coding itself, per se, but in memory and screen management. As with the hardware assumptions mentioned in this post, taking advantage of what the Game Boy assumes and making smart decisions about how to load things can speed up a project considerably.
In Part 3, I will cover two useful tools for helping with Game Boy programming projects: Game Boy Tile Designer (GBTD) and Game Boy Map Builder (GBMB).