main.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Makes use of the citro2d example
  2. #include <citro2d.h>
  3. #include "sprites.h"
  4. static C2D_SpriteSheet sprite_sheet;
  5. // Borrowed from new-hbmenu with a minor adjustment.
  6. // with permission as seen below
  7. // <fincs> You have my permission to take code from new-hbmenu and use it in a project licensed under MIT
  8. static bool konamiCheck(u32 down)
  9. {
  10. static const u32 params[] = { KEY_UP, KEY_UP, KEY_DOWN, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_LEFT, KEY_RIGHT, KEY_B, KEY_A };
  11. static u32 state, timeout;
  12. if (down & params[state])
  13. {
  14. state++;
  15. timeout = 30;
  16. if (state == sizeof(params)/sizeof(params[0]))
  17. {
  18. state = 0;
  19. return true;
  20. }
  21. }
  22. if (timeout && !--timeout)
  23. state = 0;
  24. return false;
  25. }
  26. int main() {
  27. // Init libs
  28. romfsInit();
  29. gfxInitDefault();
  30. C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
  31. C2D_Init(C2D_DEFAULT_MAX_OBJECTS);
  32. C2D_Prepare();
  33. C3D_RenderTarget* top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
  34. C3D_RenderTarget* bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
  35. sprite_sheet = C2D_SpriteSheetLoad("romfs:/gfx/sprites.t3x");
  36. if (!sprite_sheet) svcBreak(USERBREAK_PANIC);
  37. bool konami_code = false;
  38. while (aptMainLoop())
  39. {
  40. hidScanInput();
  41. u32 kDown = hidKeysDown();
  42. if (kDown & KEY_START)
  43. break;
  44. if (konami_code == false)
  45. konami_code = konamiCheck(kDown);
  46. // Render images
  47. C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
  48. C2D_TargetClear(top, C2D_Color32(255, 255, 255, 0));
  49. C2D_TargetClear(bottom, C2D_Color32(255, 255, 255, 0));
  50. C2D_SceneBegin(top);
  51. if (konami_code == true)
  52. C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprite_sheet, sprites_eastertop_idx), 0, 0, 0.6f, NULL, 1.0f, 1.0f);
  53. else
  54. C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprite_sheet, sprites_topscreen_idx), 0, 0, 0.6f, NULL, 1.0f, 1.0f);
  55. C2D_SceneBegin(bottom);
  56. if (konami_code == true)
  57. C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprite_sheet, sprites_easterbottom_idx), 0, 0, 0.6f, NULL, 1.0f, 1.0f);
  58. else
  59. C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprite_sheet, sprites_bottomscreen_idx), 0, 0, 0.6f, NULL, 1.0f, 1.0f);
  60. C3D_FrameEnd(0);
  61. }
  62. C2D_SpriteSheetFree(sprite_sheet);
  63. C2D_Fini();
  64. C3D_Fini();
  65. gfxExit();
  66. romfsExit();
  67. return 0;
  68. }