int main() { sf2d_init(); sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); consoleInit(GFX_BOTTOM, NULL); printf("sftd sample\n"); // Font loading sftd_init(); sftd_font *font = sftd_load_font_mem(airstrike_ttf, airstrike_ttf_size); while (aptMainLoop()) { hidScanInput(); if (hidKeysDown() & KEY_START) break; sf2d_start_frame(GFX_TOP, GFX_LEFT); sftd_draw_text(font, 10, 10, RGBA8(255, 0, 0, 255), 20, "Font drawing on the top screen!"); sftd_draw_textf(font, 10, 40, RGBA8(0, 255, 0, 255), 20, "FPS %f", sf2d_get_fps()); sf2d_end_frame(); sf2d_swapbuffers(); } sftd_free_font(font); sftd_fini(); sf2d_fini(); return 0; }
static int lua_term(lua_State *L) { int argc = lua_gettop(L); if (argc != 0) return luaL_error(L, "wrong number of arguments"); cur_screen = 2; sf2d_fini(); return 0; }
void unload_gfx_lib(lua_State *L) { for (int i = 0; gfx_libs[i].name; i++) { if (gfx_libs[i].unload) gfx_libs[i].unload(L); } sftd_fini(); sf2d_fini(); }
int main(int argc, char **argv) { // Start sf2dlib sf2d_init(); sf2d_set_clear_color(RGBA8(0xF5, 0xF2, 0xEF, 0xFF)); // Initialize console on top screen // consoleInit(GFX_TOP, NULL); printf("Sizeof report:\n"); printf(" > elementNode: %i\n", sizeof(elementNode_s)); printf(" > elementList: %i\n", sizeof(elementList_s)); printf(" %2i | %2i |", strcmp("ab", "aa"), strcmp("ab", "ac")); printf(" %2i | %2i \n", strcmp("a ", "aA"), strcmp("a ", "aa")); AlchemyScene scene; scene.initialize(); // consoleClear(); keystate_s ks; while(aptMainLoop()) { hidKeys(&ks); // Draw the top screen sf2d_start_frame(GFX_TOP, GFX_LEFT); scene.drawTopScreen(); sf2d_end_frame(); // Draw the bottom screen sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); scene.drawBottomScreen(); sf2d_end_frame(); // Swap the buffers sf2d_swapbuffers(); scene.updateInput(ks); // Exit the loop if (ks.down & KEY_START) break; } scene.destroy(); // Stop sf2dlib sf2d_fini(); return 0; }
int main() { sf2d_init(); //Graphics Load //Create Touhou Game CircleController circle_controller = circle_controller_init(); while (aptMainLoop()) { //Program loop if (circle_controller->flag_exit == 1) break; //Exit Application circle_controller_handle_state(circle_controller); } sf2d_fini(); //Graphics Exit return 0; }
int main() { sf2d_init(); //Graphics Load csndInit(); //Audio Load TouhouController touhou_controller = touhou_controller_init(); //Create Touhou Game while (aptMainLoop()) { //Program loop if (touhou_controller->flag_exit == 1) break; //Exit Application touhou_controller_handle_state(touhou_controller); } //sleep(1000); //ZZZ Code to let audio finish csndExit(); //Audio Exit sf2d_fini(); //Graphics Exit return 0; }
int main() { // Set the random seed based on the time srand(time(NULL)); sf2d_init(); sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); sf2d_texture *tex1 = sf2d_create_texture_mem_RGBA8(dice_img.pixel_data, dice_img.width, dice_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); sf2d_texture *tex2 = sf2d_create_texture_mem_RGBA8(citra_img.pixel_data, citra_img.width, citra_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); float rad = 0.0f; u16 touch_x = 320/2; u16 touch_y = 240/2; touchPosition touch; circlePosition circle; u32 held; while (aptMainLoop()) { hidScanInput(); hidCircleRead(&circle); held = hidKeysHeld(); if (held & KEY_START) { break; } else if (held & KEY_TOUCH) { hidTouchRead(&touch); touch_x = touch.px; touch_y = touch.py; } else if (held & (KEY_L | KEY_R)) { sf2d_set_clear_color(RGBA8(rand()%255, rand()%255, rand()%255, 255)); } sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_rectangle_rotate(260, 20, 40, 40, RGBA8(0xFF, 0xFF, 0x00, 0xFF), -2.0f*rad); sf2d_draw_rectangle(20, 60, 40, 40, RGBA8(0xFF, 0x00, 0x00, 0xFF)); sf2d_draw_rectangle(5, 5, 30, 30, RGBA8(0x00, 0xFF, 0xFF, 0xFF)); sf2d_draw_texture_rotate(tex1, 400/2 + circle.dx, 240/2 - circle.dy, rad); sf2d_end_frame(); sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); sf2d_draw_rectangle_rotate(190, 160, 70, 60, RGBA8(0xFF, 0xFF, 0xFF, 0xFF), 3.0f*rad); sf2d_draw_rectangle(30, 100, 40, 60, RGBA8(0xFF, 0x00, 0xFF, 0xFF)); sf2d_draw_texture_rotate(tex2, touch_x, touch_y, -rad); sf2d_draw_rectangle(160-15 + cosf(rad)*50.0f, 120-15 + sinf(rad)*50.0f, 30, 30, RGBA8(0x00, 0xFF, 0xFF, 0xFF)); sf2d_draw_fill_circle(40, 40, 35, RGBA8(0x00, 0xFF, 0x00, 0xFF)); sf2d_end_frame(); rad += 0.2f; sf2d_swapbuffers(); } sf2d_free_texture(tex1); sf2d_free_texture(tex2); sf2d_fini(); return 0; }
int main() { sf2d_init(); sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); consoleInit(GFX_BOTTOM, NULL); printf("intraFont test sinusoid\n"); intraFontInit(); intraFont *font = intraFontLoad("/ltn8.pgf", INTRAFONT_CACHE_ASCII); intraFontSetStyle(font, 1.0f, 0, 0, 0.0f, INTRAFONT_ALIGN_CENTER); struct Sinusoid { float angle; // In degrees float amplitude; float step; float speed; float speed_inc; char str[64]; } sinus = {0.f,35.f,10.f,0.f,0.007f,"intraFont 0.31 - 2009 by BenHur"}; float x = 0.0f; float y = 0.0f; float size = 0.65f; float tmp_angle; int i; u32 held; while (aptMainLoop()) { hidScanInput(); held = hidKeysHeld(); if (held & KEY_START) { break; } else if (held & KEY_L) { size += 0.1f; } else if (held & KEY_R) { size -= 0.1f; } if (held & KEY_UP) { y -= 3.0f; } else if (held & KEY_DOWN) { y += 3.0f; } if (held & KEY_RIGHT) { x += 3.0f; } else if (held & KEY_LEFT) { x -= 3.0f; } sf2d_start_frame(GFX_TOP, GFX_LEFT); //sf2d_draw_rectangle(50, 60, 50, 50, RGBA8(0,255,0,255)); intraFontSetStyle(font, size, RGBA8(255,0,0,255), RGBA8(0,255,0,255), 0.0f, INTRAFONT_ALIGN_LEFT); intraFontPrint(font, x, y, "ola k ase"); // * Draw the sinusoid * /*float draw_x = x - intraFontMeasureText(font,sinus.str)/2; // Get the x position of the 1st char // Increment the speed if (fabsf(sinus.speed += sinus.speed_inc) > 10.f) sinus.speed_inc = -sinus.speed_inc; // Increment the angle tmp_angle = (sinus.angle += sinus.speed); if (sinus.angle > 360.f) sinus.angle -= 360.f; // Draw one by one for (i = 0; i != strlen(sinus.str); i++, tmp_angle += sinus.step) { intraFontSetStyle(font, 1.0f, WHITE, BLACK, 45.f*cosf(tmp_angle*M_PI/180.f), INTRAFONT_ALIGN_LEFT); draw_x = intraFontPrintEx(font, draw_x, y + sinus.amplitude*sinf(tmp_angle*M_PI/180.f), sinus.str+i,1); }*/ sf2d_end_frame(); sf2d_swapbuffers(); } intraFontUnload(font); intraFontShutdown(); sf2d_fini(); return 0; }
//Frees SudokuGFX void sudoku_gfx_free(SudokuGFX s_gfx) { sf2d_fini(); if (s_gfx != NULL) { free(s_gfx); } }
int main() { cfguInit(); CFGU_GetSystemModel(&MODEL_3DS); FILE * file; shouldRenderDebug = true; if ((file = fopen("settings.bin", "r"))) { fread(&shouldRenderDebug,sizeof(bool),1,file); fread(&shouldSpeedup,sizeof(bool),1,file); osSetSpeedupEnable(shouldSpeedup); fclose(file); } sf2d_init(); csndInit(); noItem = newItem(ITEM_NULL, 0); currentMenu = MENU_TITLE; currentSelection = 0; quitGame = false; icons = sfil_load_PNG_buffer(icons2_png, SF2D_PLACE_RAM); font = sfil_load_PNG_buffer(Font_png, SF2D_PLACE_RAM); bottombg = sfil_load_PNG_buffer(bottombg_png, SF2D_PLACE_RAM); dirtColor[0] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 0)); dirtColor[1] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 1)); dirtColor[2] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 2)); dirtColor[3] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 3)); dirtColor[4] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 4)); loadSound(&snd_playerHurt, "resources/playerhurt.raw"); loadSound(&snd_playerDeath, "resources/playerdeath.raw"); loadSound(&snd_monsterHurt, "resources/monsterhurt.raw"); loadSound(&snd_test, "resources/test.raw"); loadSound(&snd_pickup, "resources/pickup.raw"); loadSound(&snd_bossdeath, "resources/bossdeath.raw"); loadSound(&snd_craft, "resources/craft.raw"); bakeLights(); int i; for (i = 0; i < 5; ++i) { minimap[i] = sf2d_create_texture(128, 128, TEXFMT_RGBA8, SF2D_PLACE_RAM); sf2d_texture_tile32(minimap[i]); } sf2d_set_vblank_wait(true); sf2d_set_clear_color(0xFF000000); k_up.input = KEY_DUP | KEY_CPAD_UP | KEY_CSTICK_UP; k_down.input = KEY_DDOWN | KEY_CPAD_DOWN | KEY_CSTICK_DOWN; k_left.input = KEY_DLEFT | KEY_CPAD_LEFT | KEY_CSTICK_LEFT; k_right.input = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT; k_attack.input = KEY_A | KEY_B | KEY_L | KEY_ZR; k_menu.input = KEY_X | KEY_Y | KEY_R | KEY_ZL; k_pause.input = KEY_START; k_accept.input = KEY_A; k_decline.input = KEY_B; k_delete.input = KEY_X; k_menuNext.input = KEY_R; k_menuPrev.input = KEY_L; if ((file = fopen("btnSave.bin", "rb"))) { fread(&k_up.input, sizeof(int), 1, file); fread(&k_down.input, sizeof(int), 1, file); fread(&k_left.input, sizeof(int), 1, file); fread(&k_right.input, sizeof(int), 1, file); fread(&k_attack.input, sizeof(int), 1, file); fread(&k_menu.input, sizeof(int), 1, file); fread(&k_pause.input, sizeof(int), 1, file); fread(&k_accept.input, sizeof(int), 1, file); fread(&k_decline.input, sizeof(int), 1, file); fread(&k_delete.input, sizeof(int), 1, file); fread(&k_menuNext.input, sizeof(int), 1, file); fread(&k_menuPrev.input, sizeof(int), 1, file); fclose(file); } if ((file = fopen("lastTP.bin", "r"))) { char fnbuf[256]; fgets(fnbuf, 256, file); // get directory to texturepack loadTexturePack(fnbuf); fclose(file); } tickCount = 0; initRecipes(); defineTables(); while (aptMainLoop()) { ++tickCount; hidScanInput(); tickKeys(hidKeysHeld(), hidKeysDown()); if (quitGame) break; if (initGame > 0) setupGame(initGame == 1 ? true : false); if (currentMenu == 0) { tick(); sf2d_start_frame(GFX_TOP, GFX_LEFT); offsetX = xscr; offsetY = yscr; sf2d_draw_rectangle(0, 0, 400, 240, 0xFF0C0C0C); //RGBA8(12, 12, 12, 255)); //You might think "real" black would be better, but it actually looks better that way renderLightsToStencil(); renderBackground(xscr, yscr); renderEntities(player.x, player.y, &eManager); renderPlayer(); resetStencilStuff(); offsetX = 0; offsetY = 0; if(shouldRenderDebug){ sprintf(fpsstr, " FPS: %.0f, X:%d, Y:%d, E:%d", sf2d_get_fps(), player.x, player.y, eManager.lastSlot[currentLevel]); drawText(fpsstr, 2, 225); } sf2d_end_frame(); sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); if(!shouldRenderMap){ sf2d_draw_texture(bottombg, 0, 0); renderGui(); } else { renderZoomedMap(); } sf2d_end_frame(); } else { tickMenu(currentMenu); renderMenu(currentMenu, xscr, yscr); } sf2d_swapbuffers(); } freeRecipes(); freeLightBakes(); sf2d_free_texture(icons); sf2d_free_texture(minimap[0]); sf2d_free_texture(minimap[1]); sf2d_free_texture(minimap[2]); sf2d_free_texture(minimap[3]); sf2d_free_texture(minimap[4]); freeSounds(); csndExit(); cfguExit(); sf2d_fini(); return 0; }
int main() { sf2d_init(); csndInit(); noItem = newItem(ITEM_NULL,0); currentMenu = MENU_TITLE; currentSelection = 0; quitGame = false; icons = sfil_load_PNG_buffer(icons2_png, SF2D_PLACE_RAM); font = sfil_load_PNG_buffer(Font_png, SF2D_PLACE_RAM); //consoleInit(GFX_BOTTOM, NULL); // printf("Press 'Start' to exit.\n"); loadSound(&snd_playerHurt, "resources/playerhurt.raw"); loadSound(&snd_playerDeath, "resources/playerdeath.raw"); loadSound(&snd_monsterHurt, "resources/monsterhurt.raw"); loadSound(&snd_test, "resources/test.raw"); loadSound(&snd_pickup, "resources/pickup.raw"); loadSound(&snd_bossdeath, "resources/bossdeath.raw"); loadSound(&snd_craft, "resources/craft.raw"); int i; for(i = 0;i < 5;++i){ minimap[i] = sf2d_create_texture(128,128,TEXFMT_RGBA8,SF2D_PLACE_RAM); sf2d_texture_tile32(minimap[i]); } sf2d_set_vblank_wait(true); sf2d_set_clear_color(0xFF); /* Default inputs */ k_up.input = KEY_DUP | KEY_CPAD_UP | KEY_CSTICK_UP; k_down.input = KEY_DDOWN | KEY_CPAD_DOWN | KEY_CSTICK_DOWN; k_left.input = KEY_DLEFT | KEY_CPAD_LEFT | KEY_CSTICK_LEFT; k_right.input = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT; k_attack.input = KEY_A | KEY_B | KEY_L | KEY_ZR; k_menu.input = KEY_X | KEY_Y | KEY_R | KEY_ZL; k_pause.input = KEY_START; k_accept.input = KEY_A; k_decline.input = KEY_B; k_delete.input = KEY_X; FILE * file; /* If btnSave exists, then use that. */ if ((file = fopen("btnSave.bin", "rb"))){ fread(&k_up.input, sizeof(int), 1, file); fread(&k_down.input, sizeof(int), 1, file); fread(&k_left.input, sizeof(int), 1, file); fread(&k_right.input, sizeof(int), 1, file); fread(&k_attack.input, sizeof(int), 1, file); fread(&k_menu.input, sizeof(int), 1, file); fread(&k_pause.input, sizeof(int), 1, file); fread(&k_accept.input, sizeof(int), 1, file); fread(&k_decline.input, sizeof(int), 1, file); fread(&k_delete.input, sizeof(int), 1, file); fclose(file); } //screenShot = false; tickCount=0; initRecipes(); defineTables(); while (aptMainLoop()) { ++tickCount; hidScanInput(); tickKeys(hidKeysHeld(),hidKeysDown()); //if (quitGame || hidKeysHeld() & KEY_SELECT) break; if (quitGame) break; //if (hidKeysDown() & (KEY_L | KEY_R)) screenShot = true; // else screenShot = false; if(initGame > 0) setupGame(initGame == 1 ? true : false); if(currentMenu == 0){ tick(); sprintf(fpsstr, " FPS: %.0f, X:%d, Y:%d, E:%d", sf2d_get_fps(),player.x, player.y,eManager.lastSlot[currentLevel]); sf2d_start_frame(GFX_TOP, GFX_LEFT); if(currentLevel == 0){ sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5); sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF); } offsetX = xscr;offsetY = yscr; renderBackground(xscr,yscr); renderEntities(player.x, player.y, &eManager); renderPlayer(); offsetX = 0;offsetY = 0; renderItemWithText(player.p.activeItem, 10, 205); // drawText(debugText,2,208); drawText(fpsstr,2,225); sf2d_end_frame(); sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); if(currentLevel == 0 && airWizardHealthDisplay > 0){ sprintf(bossHealthText, "BOSS: %.0f%%", ((float)airWizardHealthDisplay/2000.0)*100); drawText(bossHealthText,2,225); } renderGui(); sf2d_draw_texture(minimap[currentLevel], 192, 112);//y:56 sf2d_end_frame(); } else{ tickMenu(currentMenu); renderMenu(currentMenu,xscr,yscr); } sf2d_swapbuffers(); } freeRecipes(); sf2d_free_texture(icons); sf2d_free_texture(minimap[0]); sf2d_free_texture(minimap[1]); sf2d_free_texture(minimap[2]); sf2d_free_texture(minimap[3]); sf2d_free_texture(minimap[4]); freeSounds(); csndExit(); sf2d_fini(); return 0; }
int main() { char* names[] = { "nul/20", "item1", "second item", "the third one", "item4", "item5", "item6", "item7", "item8", "item9", "item10", "item11", "item12", "item13", "item14", "item15", "item16", "item17", "item18", "item19", "item20", "item21", "item22", "item23", "item24", "item25", "item26", "item27", "item28", "item29" }; int nbitems = 30; uint8_t owneditem[nbitems]; for (int i=0; i<nbitems; i++) owneditem[i] = 0; sf2d_init(); sf2d_set_clear_color(RGBA8(255, 255, 255, 255)); sf2d_set_vblank_wait(0); // Font loading sftd_init(); sftd_font* font = sftd_load_font_mem(FreeSans_ttf, FreeSans_ttf_size); int fontSize = 20; int row = 0; int nbrow = 10; int firstrow = 0; #define LONG_TIMEOUT 500 #define SHORT_TIMEOUT_MAX 100 #define SHORT_TIMEOUT_MIN 20 u64 oldTime = osGetTime(); u64 timer = 0; u64 timeout = LONG_TIMEOUT; while (aptMainLoop()) { hidScanInput(); if (hidKeysDown() & KEY_START) break; if ((hidKeysHeld() & KEY_UP) && timer == 0) row--; if (row == -1) { row++; firstrow--; if (firstrow == -1) { row = nbrow-1; firstrow = nbitems-nbrow; } } if ((hidKeysHeld() & KEY_DOWN) && timer == 0) row++; if (row == nbrow) { row--; firstrow++; if (firstrow+nbrow == nbitems+1) { firstrow = 0; row = 0; } } int index = firstrow+row; owneditem[index] += 100; if (hidKeysDown() & KEY_LEFT) owneditem[index]--; if (hidKeysDown() & KEY_RIGHT) owneditem[index]++; owneditem[index] %= 100; // use osGetTime to have key repetition u64 newTime = osGetTime(); u64 delay = newTime-oldTime; oldTime = newTime; if (hidKeysHeld()) { timer += delay; if (timer>timeout) { timer = 0; if (timeout == LONG_TIMEOUT) { timeout = SHORT_TIMEOUT_MAX; } else { timeout = umax(timeout-2, SHORT_TIMEOUT_MIN); } } } else { timer = 0; timeout = LONG_TIMEOUT; } sf2d_start_frame(GFX_TOP, GFX_LEFT); { for (int i=0; i<nbrow; i++) { unsigned int color = RGBA8(0, 0, 0, 255); if (i == row) { sf2d_draw_rectangle(0, i*fontSize, 400, fontSize, RGBA8(0, 0, 0, 255)); color = RGBA8(255, 255, 255, 255); } sftd_draw_textf(font, 010, i*fontSize, color, fontSize, names[firstrow+i]); sftd_draw_textf(font, 210, i*fontSize, color, fontSize, "%i", owneditem[firstrow+i]); } } sf2d_end_frame(); sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); { sftd_draw_textf(font, 0, 20, RGBA8(0, 255, 0, 255), 20, "Press START to exit"); sftd_draw_textf(font, 0, 40, RGBA8(0, 255, 0, 255), 20, "Timeout: %i", timeout); } sf2d_end_frame(); sf2d_swapbuffers(); } sftd_free_font(font); sftd_fini(); sf2d_fini(); return 0; }
// Main part of the coding, where everything works (or not) int main(void) { init(); // Main loop while (aptMainLoop()) { // Verify button presses hidScanInput(); // Unsigned variables for different types of button presses u32 kDown = hidKeysDown(); u32 kHeld = hidKeysHeld(); // u32 kUp = hidKeysUp(); // Exit homebrew if (kDown & KEY_START) { break; } // Activate first easter egg else if (kDown & KEY_SELECT) { easterEgg = !easterEgg; } // Change pages for the easterEgg/debug menu. else if (kDown & KEY_R) { if (++easterPage > MAX_PAGE) easterPage = 0; } else if (kDown & KEY_L) { if (--easterPage < 0) easterPage = MAX_PAGE; } timerStep(); // If no movement, set the sprite timer to 0 if (kDown & KEY_UP || kDown & KEY_DOWN || kDown & KEY_LEFT || kDown & KEY_RIGHT) { sprTimer = 0; } // Reset horizontal and vertical speeds vsp = 0; hsp = 0; // Player movement (pretty easy to understand) // TODO: Would it be possible to make this less... iffy? if (kHeld & KEY_UP) { if (!(kHeld & KEY_DOWN)) { vsp = -.5; // Vertical speed to negative .5 playerDir = BACK; // Player direction = back } } if (kHeld & KEY_DOWN) { vsp = .5; // Vertical speed to .5 playerDir = FORWARD; // Player direction = up } if (kHeld & KEY_LEFT) { if (!(kHeld & KEY_RIGHT)) { hsp = -.5; // Vertical speed to negative .5 playerDir = LEFT; // Player direction = left } } if (kHeld & KEY_RIGHT) { hsp = .5; // Vertical speed to .5 playerDir = RIGHT; // Player direction = right } // Diagonal movement speed fix if (vsp != 0) { if (hsp != 0) { vsp *= .8; hsp *= .8; } } // Movement calculation... AND proper room colision. // TODO: Consider a function for translating and/or clamping coordinates directly? player_pos.x = fclamp(player_pos.x + hsp * dt, rooms[room].collision[0].x, rooms[room].collision[1].x); player_pos.y = fclamp(player_pos.y + vsp * dt, rooms[room].collision[0].y, rooms[room].collision[1].y); // Scrolling calculation. // TODO: Make these constants better/customizable. if (player_pos.x - camera_pos.x >= 300) { camera_pos.x = player_pos.x - 300; } else if (player_pos.x - camera_pos.x <= 100) { camera_pos.x = player_pos.x - 100; } camera_pos.x = fclamp(camera_pos.x, 0, rooms[room].scroll_max.x); if (player_pos.y - camera_pos.y >= 200) { camera_pos.y = player_pos.y - 200; } else if (player_pos.y - camera_pos.y <= 50) { camera_pos.y = player_pos.y - 50; } camera_pos.y = fclamp(camera_pos.y, 0, rooms[room].scroll_max.y); // Player sprites if (hsp == 0 && vsp == 0) curr_tex = tex_arr_friskWalk[playerDir][0]; else curr_tex = tex_arr_friskWalk[playerDir][(int)floor(sprTimer)]; // Sprite animation timer // TODO: Why .15 * .03 * actual time? sprTimer += (.03 * dt); while (sprTimer >= 4) { sprTimer -= 4; } if (!next_exit){ if (roomTimer < 255) { roomTimer = fmin(roomTimer + (4 * dt), 255); } next_exit = exit_room(room, &player_pos); } else { roomTimer -= 4 * dt; if (roomTimer <= 0) { room = next_exit->room_id; player_pos = next_exit->entrance; next_exit = NULL; roomTimer = 0; } } render(); // Swap sf2d framebuffers and wait for VBlank sf2d_swapbuffers(); } // Free images/textures/fonts from memory for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { sf2d_free_texture(tex_arr_friskWalk[i][j]); } } for (int i = 0; i < 3; ++i) { sf2d_free_texture(rooms[i].bg.tex); } sftd_free_font(font); // Exit services sf2d_fini(); sftd_fini(); sound_stop(home); audio_stop(); hidExit(); aptExit(); srvExit(); return 0; }
int main() { L = luaL_newstate(); luaL_openlibs(L); luaL_requiref(L, "love", initLove, 1); sf2d_init(); // 2D Drawing lib. sftd_init(); // Text Drawing lib. cfguInit(); ptmuInit(); // consoleInit(GFX_BOTTOM, NULL); sf2d_set_clear_color(RGBA8(0x0, 0x0, 0x0, 0xFF)); // Reset background color. osSetSpeedupEnable(true); // Enables CPU speedup for a free performance boost. // Detect if we are running on a .cia, because if we are // we load from RomFS rather than the SD Card. // TODO: Load RomFS from .3dsx's aswell. Result rc = romfsInit(); romfsExists = (rc) ? false : true; // Change working directory if (romfsExists) { chdir("romfs:/"); } else { char cwd[256]; getcwd(cwd, 256); char newCwd[261]; strcat(newCwd, cwd); strcat(newCwd, "game"); chdir(newCwd); } luaL_dobuffer(L, boot_lua, boot_lua_size, "boot"); // Do some setup Lua side. // If main.lua exists, execute it. // If not then just load the nogame screen. if (fileExists("main.lua")) { if (luaL_dofile(L, "main.lua")) displayError(); } else { if (luaL_dobuffer(L, nogame_lua, nogame_lua_size, "nogame")) displayError(); } if (luaL_dostring(L, "love.timer.step()")) displayError(); if (luaL_dostring(L, "if love.load then love.load() end")) displayError(); while (aptMainLoop()) { if (shouldQuit) { if (forceQuit) break; bool shouldAbort = false; // lua_getfield(L, LUA_GLOBALSINDEX, "love"); // lua_getfield(L, -1, "quit"); // lua_remove(L, -2); // if (!lua_isnil(L, -1)) { // lua_call(L, 0, 1); // shouldAbort = lua_toboolean(L, 1); // lua_pop(L, 1); // }; TODO: Do this properly. if (luaL_dostring(L, "if love.quit then love.quit() end")) displayError(); if (!shouldAbort && !errorOccured) break; } // Quit event if (!errorOccured) { if (luaL_dostring(L, "love.keyboard.scan()\n" "love.timer.step()\n" "if love.update then love.update(love.timer.getDelta()) end")) { displayError(); } // Top screen // Left side sf2d_start_frame(GFX_TOP, GFX_LEFT); if (luaL_dostring(L, "if love.draw then love.draw() end")) displayError(); sf2d_end_frame(); // Right side if (is3D) { sf2d_start_frame(GFX_TOP, GFX_RIGHT); if (luaL_dostring(L, "if love.draw then love.draw() end")) displayError(); sf2d_end_frame(); } // Bot screen sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); if (luaL_dostring(L, "if love.draw then love.draw() end")) displayError(); sf2d_end_frame(); luaL_dostring(L, "love.graphics.present()"); } else { hidScanInput(); u32 kTempDown = hidKeysDown(); if (kTempDown & KEY_START) { forceQuit = true; shouldQuit = true; } char *errMsg = lua_tostring(L, -1); sf2d_start_frame(GFX_TOP, GFX_LEFT); lua_getfield(L, LUA_GLOBALSINDEX, "love"); lua_getfield(L, -1, "errhand"); lua_remove(L, -2); if (!lua_isnil(L, -1)) { lua_pushstring(L, errMsg); lua_call(L, 1, 0); } sf2d_end_frame(); sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); lua_getfield(L, LUA_GLOBALSINDEX, "love"); lua_getfield(L, -1, "errhand"); lua_remove(L, -2); if (!lua_isnil(L, -1)) { lua_pushstring(L, errMsg); lua_call(L, 1, 0); } sf2d_end_frame(); luaL_dostring(L, "love.graphics.present()"); } } luaL_dostring(L, "love.audio.stop()"); lua_close(L); sftd_fini(); sf2d_fini(); cfguExit(); ptmuExit(); if (soundEnabled) ndspExit(); if (romfsExists) romfsExit(); return 0; }
int main(void) { Result ret = 0, error = 0; sf2d_init(); sftd_init(); romfsInit(); srand(osGetTime()); // consoleInit(GFX_TOP, NULL); // TODO: Comment it! // consoleInit(GFX_BOTTOM, NULL); // TODO: Comment it! printf("> Loading texture manager\n"); PHBanku::texture = new TextureManager(); ret = PHBanku::texture->load(); if (R_FAILED(ret)) { // Graphics error |= ERR_GRAPHICS; } printf("> Loading font manager\n"); PHBanku::font = new FontManager(); ret = PHBanku::font->load(); if (R_FAILED(ret)) { // Font error |= ERR_FONT; } printf("> Loading data manager\n"); PHBanku::data = new DataManager(); ret = PHBanku::data->load(); if (R_FAILED(ret)) { // Data error |= ERR_DATA; } #ifdef __cia printf("> Starting title selector\n"); while (!error && TS_Loop()) { // Draw the static loading screen again because of ts.h PHBanku::texture->drawStaticLoadingScreen(); printf("> Loading filesystem services\n"); ret = FSCIA_Init(titleEntry.titleid, titleEntry.mediatype); if (R_FAILED(ret)) { // Filesystem error |= ERR_FILESYSTEM; } #else // __3dsx printf("> Loading filesystem services\n"); ret = FS_Init(); if (R_FAILED(ret)) { // Filesystem error |= ERR_FILESYSTEM; } #endif printf("> Loading save manager\n"); PHBanku::save = new SaveManager(); ret = PHBanku::save->load(); if (R_FAILED(ret)) { // Save error |= ERR_SAVE; } if (!error) { printf("> Starting box viewer...\n"); Viewer* viewer = new BoxViewer(); ViewState state = Viewer::startMainLoop(viewer); if (state == ViewState::Saving) { // TODO Remove when better save display! consoleInit(GFX_TOP, NULL); printf("Saving...\n"); // ^ PHBanku::save->save(); } else { // TODO Remove when better exit display! consoleInit(GFX_TOP, NULL); printf("Exiting...\n"); // ^ } delete viewer; } delete PHBanku::save; #ifdef __cia FSCIA_Exit(); consoleExit(GFX_TOP, NULL); break; // TODO Remove! The app crash itself after the 2nd ts, unknown cause. } // while (TS_LOOP()) if (!error) { // TODO Remove when better exit display! consoleInit(GFX_BOTTOM, NULL); // ^ printf("\nThe app execution ended!\n"); printf("Thanks for being awesome!\n"); } #else FS_Exit(); #endif if (error) { // TODO Remove when better error display! consoleInit(GFX_TOP, NULL); // ^ printf("\nProblem happened: 0x%lx\n", error); if (error & ERR_SAVE) printf(" \a Save\n"); if (error & ERR_DATA) printf(" \a Data\n"); if (error & ERR_FONT) printf(" \a Font\n"); if (error & ERR_GRAPHICS) printf(" \a Graphics\n"); if (error & ERR_FILESYSTEM) printf(" \a Filesystem\n"); printf("PHBank version: %08x\n", VERSION); printf("Can't start the viewer.\n"); printf("Press any key to exit\n"); waitKey(KEY_ANY); } delete PHBanku::data; delete PHBanku::font; delete PHBanku::texture; romfsExit(); sftd_fini(); sf2d_fini(); return 0; }
int main() { //gfxInitDefault(); sf2d_init(); sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); consoleInit(GFX_TOP, NULL); Result rc = _srvGetServiceHandle(&romfsRealHandle, "fs:USER"); printf("realHandle: %08lX\n", rc); rc = FSUSER_Initialize(&romfsRealHandle); printf("initReal: %08lX\n", rc); // Regular RomFS u8 zeros[0xC]; memset(zeros, 0, sizeof(zeros)); FS_archive arch = { ARCH_ROMFS, { PATH_EMPTY, 1, (u8*)"" }, 0, 0 }; FS_path path = { PATH_BINARY, sizeof(zeros), zeros }; Handle romFS_file; rc = FSUSER_OpenFileDirectly(&romfsRealHandle, &romFS_file, arch, path, FS_OPEN_READ, FS_ATTRIBUTE_NONE); printf("romfsOpen: %08lX\n", rc); rc = romfsInitFromFile(romFS_file, 0); u8 *decomp_out; u8 *darc_decomp; u32 decomp_size; u32 darc_decomp_size; sf2d_texture **mon; char *mon_garc; char *box_garc; if (rc) { printf("romfsInit: %08lX\n", rc); mon_garc = "sdmc:/1"; box_garc = "sdmc:/3_box"; } else { printf("romfs Init Successful!\n"); mon_garc = "romfs:/a/0/9/3"; //Pokemon X/Y box_garc = "romfs:/a/1/0/4"; //Pokemon X/Y u32 num_mon = gnumrecords(mon_garc); if(!num_mon) { mon_garc = "sdmc:/1"; num_mon = gnumrecords(mon_garc); } u32 box_test = gnumrecords(box_garc); if(!box_test) { box_garc = "sdmc:/3_box"; } } u32 num_mon = gnumrecords(mon_garc); mon = (sf2d_texture**)malloc(num_mon * sizeof(sf2d_texture*)); printf("Loading sprites..."); int i; for(i = 0; i < 32; i++) { gfread(mon_garc, i, &decomp_out, &decomp_size); sf2d_texture *mon_sprite = create_texture_from_xy7_clim(decomp_out, decomp_size); mon[i] = mon_sprite; free(decomp_out); } printf("Pokemon sprites read.\n"); gfread(box_garc, 0, &darc_decomp, &darc_decomp_size); printf("Box sprites read.\n"); u32 box_clim_size; u32 box_bg_size; u32 box_name_size; void *box_clim; void *box_bg_clim; void *box_name; if(darc_decomp) { printf("darc_file: %x\n", box_clim); } printf("All read!\n"); sf2d_texture *cursor = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "cursol01.bclim"); sf2d_texture *wallpaper = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "box_wp02.bclim"); sf2d_texture *name_box = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "box_name02.bclim"); sf2d_texture *mode01 = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "mode01.bclim"); sf2d_texture *mode02 = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "mode02.bclim"); sf2d_texture *mode03 = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "mode03.bclim"); sf2d_texture *left_button = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "left_button.bclim"); sf2d_texture *right_button = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "right_button.bclim"); float cursor_spot = 0; u8 cursor_direction = 1; float cursor_add = 0.4f; u8 cursor_mon_x = 3; u8 cursor_mon_y = 2; // Main loop while (aptMainLoop()) { hidScanInput(); if(cursor_direction) { cursor_spot += cursor_add; if(cursor_spot >= 5.0f) cursor_direction--; } else { cursor_spot -= cursor_add; if(cursor_spot <= 0.0f) cursor_direction++; } sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); clim_draw_texture(wallpaper, 0, 0); clim_draw_texture(mode01, 25, 0); clim_draw_texture(mode02, 25+50+10, 0); clim_draw_texture(mode03, 25+50+10+50+10, 0); clim_draw_texture(name_box, 20, 20); clim_draw_texture(left_button, 5, 20); clim_draw_texture(right_button, 20+name_box->width, 20); int x, y; int i = 1; for(y = 0; y < 5; y++) { for(x = 0; x < 6; x++) { clim_draw_texture(mon[i], 10+(x*32), 45+(y*30)); i++; } } clim_draw_texture(cursor, (int)(10-5+((cursor_mon_x + 1) * 32)-cursor_spot), (int)(45+5+((cursor_mon_y - 1) * 30)+cursor_spot)); sf2d_end_frame(); u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu sf2d_swapbuffers(); } sf2d_fini(); romfsExit(); gfxExit(); return 0; }
void Graphic::closeGraphicEnviroment() { TextureManager::freeAllTextures(); FontManager::freeAllFonts(); sftd_fini(); sf2d_fini(); }
int main() { touchPosition touch; sf2d_init(); sftd_init(); sftd_font *text = sftd_load_font_mem(Roboto_ttf, Roboto_ttf_size); sftd_font *title = sftd_load_font_mem(RobotoThin_ttf, RobotoThin_ttf_size); sf2d_texture *logo = sfil_load_PNG_buffer(logo_png, SF2D_PLACE_RAM); sf2d_texture *record = sfil_load_PNG_buffer(record_png, SF2D_PLACE_RAM); sf2d_texture *stop = sfil_load_PNG_buffer(stop_png, SF2D_PLACE_RAM); sf2d_set_clear_color(RGBA8(0xFA, 0xFA, 0xFA, 0xFF)); sharedmem = (u32*)memalign(0x1000, sharedmem_size); audiobuf = linearAlloc(audiobuf_size); MIC_Initialize(sharedmem, sharedmem_size, control, 0, 3, 1, 1);//See mic.h. // Threading stuff svcCreateEvent(&threadRequest,0); u32 *threadStack = memalign(32, STACKSIZE); svcCreateThread(&threadHandle, threadMic, 0, &threadStack[STACKSIZE/4], 0x3f, 0); while(aptMainLoop()) { hidScanInput(); hidTouchRead(&touch); u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_texture(logo, 60, 70); sftd_draw_text(title, 177, 80, RGBA8(0, 0, 0, 222), 40, "Audio"); sftd_draw_text(title, 175, 120, RGBA8(0, 0, 0, 222), 40, "Recorder"); sf2d_end_frame(); sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); sf2d_draw_texture(record, 85, 85); sf2d_draw_texture(stop, 165, 85); sf2d_end_frame(); svcSignalEvent(threadRequest); if(print == 1) { sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_texture(logo, 60, 70); sftd_draw_text(title, 177, 80, RGBA8(0, 0, 0, 222), 40, "Audio"); sftd_draw_text(title, 175, 120, RGBA8(0, 0, 0, 222), 40, "Recorder"); sftd_draw_text(text, 130, 209, RGBA8(0, 0, 0, 222), 16, "Recording audio..."); sf2d_end_frame(); } if(recording == 2) { sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_texture(logo, 60, 70); sftd_draw_text(title, 177, 80, RGBA8(0, 0, 0, 222), 40, "Audio"); sftd_draw_text(title, 175, 120, RGBA8(0, 0, 0, 222), 40, "Recorder"); sftd_draw_text(text, 130, 209, RGBA8(0, 0, 0, 222), 16, "Saving audio..."); sf2d_end_frame(); } sf2d_swapbuffers(); } MIC_Shutdown(); sftd_free_font(text); sftd_free_font(title); sf2d_free_texture(logo); sf2d_free_texture(record); sf2d_free_texture(stop); // tell thread to exit threadExit = true; // signal the thread svcSignalEvent(threadRequest); // give it time to exit svcSleepThread(10000000ULL); // close handles and free allocated stack svcCloseHandle(threadRequest); svcCloseHandle(threadHandle); free(threadStack); free(sharedmem); linearFree(audiobuf); linearFree(nomute_audiobuf); sf2d_fini(); sftd_fini(); return 0; }
int main() { sf2d_init(); sf2d_set_vblank_wait(0); // this will depend on the level uint8_t mapWidth = 4; uint8_t mapHeight = 3; uint16_t mapDim = mapWidth*mapHeight; uint8_t map_u[mapDim]; uint16_t mapLength = generateLevel(map_u, mapWidth, mapHeight, 12); uint8_t map[mapDim]; memcpy(map, map_u, mapDim); // get some drawing parameters uint16_t areaWidth = TWIDTH*2/3; uint16_t areaHeight = THEIGHT*2/3; uint16_t recWidth = areaWidth/mapWidth; uint16_t recHeight = areaHeight/mapHeight; uint16_t areaTop = (THEIGHT-mapHeight*recHeight)/2; uint16_t areaLeft = (TWIDTH-mapWidth*recWidth)/2; uint8_t curX = 0; uint8_t curY = 0; uint16_t playerLength = 0; float colorInterpolation = 0; u64 oldTime = 0; u64 keyTime = 0; while (aptMainLoop()) { // manage timer according to time passed since last frame u64 newTime = osGetTime(); keyTime += newTime-oldTime; oldTime = newTime; hidScanInput(); if (hidKeysDown() & KEY_START) break; // move cursor according to input uint16_t oldCurXY = curY*mapWidth+curX; curX += mapWidth; curY += mapHeight; if (hidKeysDown() & KEY_LEFT) curX--; if (hidKeysDown() & KEY_RIGHT) curX++; if (hidKeysDown() & KEY_UP) curY--; if (hidKeysDown() & KEY_DOWN) curY++; curX %= mapWidth; curY %= mapHeight; uint16_t newCurXY = curY*mapWidth+curX; if (newCurXY != oldCurXY) { map[newCurXY]--; playerLength++; keyTime=0; // force cursor display now } if (map[newCurXY] == 255) { // reset level curX = 0; curY = 0; playerLength = 0; memcpy(map, map_u, mapDim); } if (playerLength == mapLength) break; // TODO should be "you won" u32 targetColor = RGBA8(0x00,0xaa,0xaa,255); float targetInterpolation = (float)playerLength/(float)mapLength; if (newTime%256==0) colorInterpolation = (colorInterpolation*3+targetInterpolation*1)/4; u32 darkColor = interpolate(targetColor, greyed(targetColor), colorInterpolation); u32 liteColor = interpolate(darkColor, 0xffffffff, 1.0f/3.0f); // white is too clear u32 bgColor = interpolate(darkColor, 0, 0.5f); sf2d_set_clear_color(bgColor); sf2d_start_frame(GFX_TOP, GFX_LEFT); { // draw tiles for (uint8_t x=0; x<mapWidth; x++) for (uint8_t y=0; y<mapHeight; y++) { sf2d_draw_rectangle(x*recWidth+areaLeft, y*recHeight+areaTop, recWidth, recHeight, interpolate(darkColor, liteColor, ((float)map[y*mapWidth+x])/3)); } // draw cursor float t = (float)(keyTime%2048)/2048.0f; uint8_t op = pow(fabs(t-0.5f)*2,4)*255; sf2d_draw_rectangle(curX*recWidth+areaLeft, curY*recHeight+areaTop, recWidth, recHeight, RGBA8(0,0,0,op)); } sf2d_end_frame(); sf2d_swapbuffers(); } sf2d_fini(); return 0; }
CtrUi::~CtrUi() { sf2d_free_texture(main_texture); sf2d_fini(); }
int main() { hasSound = !csndInit(); rotation.d.sample = _sampleRotation; rotation.d.readTiltX = _readTiltX; rotation.d.readTiltY = _readTiltY; rotation.d.readGyroZ = _readGyroZ; stream.postVideoFrame = 0; stream.postAudioFrame = 0; stream.postAudioBuffer = _postAudioBuffer; if (!allocateRomBuffer()) { return 1; } if (hasSound) { audioLeft = linearAlloc(AUDIO_SAMPLES * sizeof(int16_t)); audioRight = linearAlloc(AUDIO_SAMPLES * sizeof(int16_t)); } sf2d_init(); sf2d_set_clear_color(0); tex = sf2d_create_texture(256, 256, TEXFMT_RGB565, SF2D_PLACE_RAM); memset(tex->data, 0, 256 * 256 * 2); sdmcArchive = (FS_archive) { ARCH_SDMC, (FS_path) { PATH_EMPTY, 1, (const u8*)"" }, 0, 0 }; FSUSER_OpenArchive(0, &sdmcArchive); logFile = VFileOpen("/mgba.log", O_WRONLY | O_CREAT | O_TRUNC); struct GUIFont* font = GUIFontCreate(); if (!font) { goto cleanup; } struct GBAGUIRunner runner = { .params = { 320, 240, font, "/", _drawStart, _drawEnd, _pollInput, 0, 0, GUI_PARAMS_TRAIL }, .setup = _setup, .teardown = 0, .gameLoaded = _gameLoaded, .gameUnloaded = _gameUnloaded, .prepareForFrame = 0, .drawFrame = _drawFrame, .pollGameInput = _pollGameInput }; GBAGUIInit(&runner, 0); GBAGUIRunloop(&runner); GBAGUIDeinit(&runner); cleanup: linearFree(renderer.outputBuffer); if (logFile) { logFile->close(logFile); } sf2d_free_texture(tex); sf2d_fini(); if (hasSound) { linearFree(audioLeft); linearFree(audioRight); } csndExit(); return 0; }