Skip to content

Instantly share code, notes, and snippets.

@videlais

videlais/main.c Secret

Created July 4, 2016 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save videlais/ecd4ceffa167e73ae4686571a3a4656f to your computer and use it in GitHub Desktop.
Save videlais/ecd4ceffa167e73ae4686571a3a4656f to your computer and use it in GitHub Desktop.
main.c for third GBDK example
#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!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment