//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- const int tile_base = 0; const int map_base = 20; videoSetMode(0); videoSetModeSub(MODE_5_2D); vramSetBankC(VRAM_C_SUB_BG); PrintConsole *console = consoleInit(0, 3, BgType_ExRotation, BgSize_ER_256x256, map_base, tile_base, false, false); ConsoleFont font; font.gfx = (u16*)fontTiles; font.pal = (u16*)fontPal; font.numChars = 95; font.numColors = fontPalLen / 2; font.bpp = 8; font.asciiOffset = 32; font.convertSingleColor = false; consoleSetFont(console, &font); int bg3 = console->bgId; iprintf("Custom Font Demo\n"); iprintf(" by Poffy\n"); iprintf("modified by WinterMute and dovoto\n"); iprintf("for libnds examples\n"); unsigned int angle = 0; int scrollX = 0; int scrollY = 0; int scaleX = intToFixed(1,8); int scaleY = intToFixed(1,8); while(1) { scanKeys(); u32 keys = keysHeld(); if ( keys & KEY_L ) angle+=64; if ( keys & KEY_R ) angle-=64; if ( keys & KEY_LEFT ) scrollX++; if ( keys & KEY_RIGHT ) scrollX--; if ( keys & KEY_UP ) scrollY++; if ( keys & KEY_DOWN ) scrollY--; if ( keys & KEY_A ) scaleX++; if ( keys & KEY_B ) scaleX--; if( keys & KEY_X ) scaleY++; if( keys & KEY_Y ) scaleY--; swiWaitForVBlank(); bgSetRotateScale(bg3, angle, scaleX, scaleY); bgSetScroll(bg3, scrollX, scrollY); bgUpdate(); } }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- int i = 0; int angle = 0; videoSetMode(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_SPRITE); oamInit(&oamMain, SpriteMapping_1D_32, false); u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color); /* This is where we load the image. * In this case we're doing a really simple striped pattern, * but we could also load a bitmap. */ for(i = 0; i < 32 * 32 / 2; i++) { //gfx[i] = 1 | (1 << 8); gfx[i] = 0x201; // alternating red and yellow } SPRITE_PALETTE[1] = RGB15(31,0,0); // full red SPRITE_PALETTE[2] = RGB15(28,28,0); // bright yellow while(1) { scanKeys(); /* Slow down the rotate if the left trigger is pressed * I'd like to do a fixed-point here, but I don't know how */ float inc = (keysHeld() & KEY_L)? 0.05 : 0.3; if(keysHeld() & KEY_LEFT) angle += degreesToAngle(inc); if(keysHeld() & KEY_RIGHT) angle -= degreesToAngle(inc); //------------------------------------------------------------------------- // Set the first rotation/scale matrix // // There are 32 rotation/scale matricies that can store sprite rotations // Any number of sprites can share a sprite rotation matrix or each sprite // (up to 32) can utilize a seperate rotation. Because this sprite is doubled // in size we have to adjust its position by subtracting half of its height and // width (20 - 16, 20 - 16, ) //------------------------------------------------------------------------- oamRotateScale(&oamMain, 0, angle, intToFixed(1, 8), intToFixed(1, 8)); oamSet(&oamMain, //main graphics engine context 0, //oam index (0 to 127) 20 - 16, 20 - 16, //x and y pixle location of the sprite 0, //priority, lower renders last (on top) 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite SpriteSize_32x32, SpriteColorFormat_256Color, gfx, //pointer to the loaded graphics 0, //sprite rotation/scale matrix index true, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); //------------------------------------------------------------------------- // Because the sprite below has size double set to false it can never be larger than // 32x32 causing it to clip as it rotates. //------------------------------------------------------------------------- oamSet(&oamMain, //main graphics engine context 1, //oam index (0 to 127) 204, 20, //x and y pixle location of the sprite 0, //priority, lower renders last (on top) 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite SpriteSize_32x32, SpriteColorFormat_256Color, gfx, //pointer to the loaded graphics 0, //sprite rotation/scale matrix index false, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); swiWaitForVBlank(); oamUpdate(&oamMain); } return 0; }