git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/examples/cross-platform/platformer_template/src/main.c

      1 #include <gbdk/platform.h>
      2 #include <stdint.h>
      3 #include "player.h"
      4 #include "common.h"
      5 #include "level.h"
      6 #include "camera.h"
      7 #include "NextLevel.h"
      8 #include "TitleScreen.h"
      9 
     10 BANKREF_EXTERN(NextLevel)
     11 BANKREF_EXTERN(TitleScreen)
     12 
     13 
     14 void main(void)
     15 {
     16 
     17     
     18     #ifdef NINTENDO
     19         // init palettes
     20         BGP_REG = DMG_PALETTE(DMG_BLACK, DMG_WHITE, DMG_LITE_GRAY, DMG_DARK_GRAY);
     21         OBP0_REG =OBP1_REG =DMG_PALETTE(DMG_DARK_GRAY, DMG_BLACK, DMG_WHITE,  DMG_LITE_GRAY );
     22     #endif
     23     
     24 	// Turn the background map on to make it visible
     25     SHOW_BKG;
     26     SHOW_SPRITES;
     27     SPRITES_8x16;
     28 
     29     ShowCentered(TitleScreen_WIDTH,TitleScreen_HEIGHT,BANK(TitleScreen),TitleScreen_tiles,TitleScreen_TILE_COUNT,TitleScreen_map,TitleScreen_palettes);
     30 
     31     WaitForStartOrA();
     32 
     33     // Make sure these are initially different so the "setupcurrentLevel" logic is triggered
     34     currentLevel=255;
     35     nextLevel=0;
     36 
     37     // Loop forever
     38     while(1) {
     39 
     40 		// yield CPU and wait for start of next frame
     41         vsync();
     42 
     43         // if we want to change levels
     44         if(nextLevel!=currentLevel){
     45 
     46 
     47             // if we're not starting the game (where currentLevel = 255)
     48             if(currentLevel!=255){
     49                 
     50                 ShowCentered(NextLevel_WIDTH,NextLevel_HEIGHT,BANK(NextLevel),NextLevel_tiles,NextLevel_TILE_COUNT,NextLevel_map,NextLevel_palettes);
     51 
     52                 WaitForStartOrA();
     53             }
     54 
     55             // Update what our current level is
     56             currentLevel=nextLevel;
     57             
     58             DISPLAY_OFF;
     59 
     60             // Setup the new level
     61             SetupCurrentLevel();
     62 
     63             camera_x=0;
     64 
     65             // Draw the initial area
     66             // Draw one extra column to avoid a blank row when first scrolling.
     67             // If scrolling vertically also, you should draw one extra row as well.
     68             // The platformer template will only scroll horizontally
     69             SetCurrentLevelSubmap(0,0,DEVICE_SCREEN_WIDTH+1,DEVICE_SCREEN_HEIGHT);
     70 
     71             DISPLAY_ON;
     72 
     73             #if DEVICE_SCREEN_BUFFER_WIDTH == DEVICE_SCREEN_WIDTH
     74                 // On platforms where screen buffer has no more space than physical screen,
     75                 // the next map column will be written to the leftmost screen column.
     76                 // So we blank the leftmost column to hide visual artifacts where possible.
     77                 HIDE_LEFT_COLUMN;
     78             #endif
     79 
     80             // Setup the player
     81             SetupPlayer();
     82         }
     83 
     84         // Get the joypad input
     85         joypadPrevious = joypadCurrent;
     86         joypadCurrent = joypad();
     87 
     88         uint8_t spritesUsed = UpdatePlayer();
     89         hide_sprites_range(spritesUsed,MAX_HARDWARE_SPRITES);
     90         
     91         UpdateCamera();
     92     }
     93 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.