// Function: main() ====================================================================== int main() { // Variables map_fragment_info_ptr bg_background; // Initialize HAMlib ham_Init(); // Set system prefetch //hel_SysSetPrefetch(TRUE); // Initialize Splash-Screen System hel_SplashInit((void*)g_SplashScreenSystemBuffer); // Enter bg mode 4 for the splash screen ham_SetBgMode(4); // Splashscreen 1 hel_Splash ( (u16*)ResData(RES_SPLASHSCREEN_RAW), // pBitmap (u16*)ResData(RES_SPLASHSCREEN_PAL), // pPalette RGB(0,0,0), // InBlendColor RGB(0,0,0), // OutBlendColor 60, // BlendDelay 2000, // DisplayDelay 500, // ContinueDelay COMPRESSION_TYPE_NONE, // CompressionType, 0 // Flags ); // Quit the splashscreen hel_SplashQuit(); // Setup the background mode ham_SetBgMode(1); // Initialize the text display system ham_InitText(0); // Initialize the palettes ham_LoadBGPal((void*)background_Palette, 256); ham_LoadObjPal((void*)object_Palette, 256); // Set the Text Color ham_SetTextCol(195, 40); // Setup the tileset for our image ham_bg[1].ti = ham_InitTileSet((void*)background_Tiles, SIZEOF_16BIT(background_Tiles), 1, 1); // Setup the map for our image ham_bg[1].mi = ham_InitMapEmptySet(3,0); bg_background = ham_InitMapFragment((void*)background_Map, 60, 20, 0, 0, 60, 20, 0); // Copy (the whole) map to BG0 at x=0, y=0 ham_InsertMapFragment(bg_background, 1, 0, 0); // Display the background ham_InitBg(1, 1, 2, 1); // Setup the array spot array_spot = (32768 * dir_dk) + (4096 * animcnt); // setup the initial state of the frame bits counter frameCounter = 0; // Setup the dk dk = ham_CreateObj( (void *)&dk_Bitmap[array_spot], 0,3,OBJ_MODE_NORMAL,1,0,0,0,0,0,0,dk_x,dk_y); // Start the VBL interrupt handler ham_StartIntHandler(INT_TYPE_VBL, (void*)&vbl_func); while (1) { if (newframe) { // Write some stuff to the screen ham_DrawText(1, 1, "480x160 background"); ham_DrawText(1, 2, "Arrows to scroll left-right"); ham_DrawText(1, 17, "scroll-x: %5d", map_x); ham_DrawText(1, 18, "frame: %5d", frameCounter); // Let the user move the map around if (F_CTRLINPUT_RIGHT_PRESSED) { if (map_x < (480 - 240)) ham_SetBgXY(1, ++map_x, 0); } if (F_CTRLINPUT_LEFT_PRESSED) { if (map_x > 0) ham_SetBgXY(1, --map_x, 0); } newframe = 0; // No longer a new frame } // End of if(newframe) } // End of while(1) return 0; } // End of main()
//******************// // Helper Functions // //******************// void Move() { struct ControllerState cont = GetControllerState(); bool moving = FALSE; // move player if ( cont.left ) { if ( g_cam_x > 0 && ((g_hippy.x + g_hippy.w / 2) == (SCREEN_WIDTH / 2)) ) HScroll(-WALK_SPEED); else if ( g_hippy.x > 0 ) g_hippy.x -= WALK_SPEED; g_hippy.baseFrame = FACE_SIDE; ham_SetObjHFlip(g_hippy.sprite, FALSE); moving = TRUE; } if ( cont.right ) { if ( g_cam_x < (MAP_WIDTH - SCREEN_WIDTH - 1) && ((g_hippy.x + g_hippy.w / 2) == (SCREEN_WIDTH / 2)) ) HScroll(WALK_SPEED); else if ( g_hippy.x < (SCREEN_WIDTH - g_hippy.w) ) g_hippy.x += WALK_SPEED; if ( !moving ) { g_hippy.baseFrame = FACE_SIDE; ham_SetObjHFlip(g_hippy.sprite, TRUE); moving = TRUE; } } if ( cont.up ) { if ( g_cam_y > 0 && ((g_hippy.y + g_hippy.h / 2) == (SCREEN_HEIGHT / 2)) ) VScroll(-WALK_SPEED); else if ( g_hippy.y > 0 ) g_hippy.y -= WALK_SPEED; if ( !moving ) { g_hippy.baseFrame = FACE_UP; moving = TRUE; } } if ( cont.down ) { if ( g_cam_y < (MAP_HEIGHT - SCREEN_HEIGHT - 1) && ((g_hippy.y + g_hippy.h / 2) == (SCREEN_HEIGHT / 2)) ) VScroll(WALK_SPEED); else if ( g_hippy.y < (SCREEN_HEIGHT - g_hippy.h) ) g_hippy.y += WALK_SPEED; if ( !moving ) { g_hippy.baseFrame = FACE_DOWN; moving = TRUE; } } // move player ham_SetBgXY(0, g_cam_x, g_cam_y); ham_SetObjXY(g_hippy.sprite, g_hippy.x, g_hippy.y); // move shroom ham_SetObjXY(g_shroom.sprite, g_shroom.x, g_shroom.y); // move key ham_SetObjXY(g_key.sprite, g_key.x, g_key.y); // set hippy frame int animIndex = g_hippy.w * g_hippy.h * (g_hippy.baseFrame + g_hippy.frameDif); ham_UpdateObjGfx(g_hippy.sprite, (void *)&hippy_bitmap[animIndex]); g_count++; if ( moving && ((g_count % HIPPY_TPF) == 0) ) g_hippy.frameDif =(g_hippy.frameDif + 1) % HIPPY_FRAMES; }