Exemplo n.º 1
0
int draw_delete_dialouge(void) {
  draw_clearscrn();
  // Top screen already selected form draw_clearscrn
  printf("\n\n\n\t\t%sDelete %-35.35s%s", FG_RED, file_arr[selected+scroll].name, RESET);
  printf("\n\n\t\t[A] - Yes\n\t\t[B] - No");

  while (appletMainLoop()) {
    consoleUpdate(NULL);
    hidScanInput();
    u32 exitkDown = hidKeysDown(CONTROLLER_P1_AUTO);
    if (exitkDown & KEY_A) {
      return 0;
    }
    else if (exitkDown & KEY_B) {
      return 1;
    }
    consoleUpdate(NULL);
    //gfxFlushBuffers();
    //gfxSwapBuffers();
  }
  // If something goes wrong (+ stops compile warning)
  return 1;
}
int main (int argc, char *argv[]) {
	(void) argc;
	(void) argv;

	// init
	gfxInitDefault();
	gfxSetMode(GfxMode_TiledDouble);
	// wide screen, keep aspect ratio
	gfxConfigureResolution(SCR_WIDTH + 136, SCR_HEIGHT);

	u32* gamebuf = (u32*) malloc(SCR_HEIGHT * SCR_WIDTH * sizeof(u32));

	Game.InitSoundDriver();
	Game.InitGame();
	Game.LoadScores();
	Game.StartGame();

	int game_paused = 0;

	while(appletMainLoop()) {
		hidScanInput();

		//1 Player input loop
		// Get Controller state
		JOYSTICK *jptr = &Game.m_GameTarget.m_Joy1;

		u32 keys_down = hidKeysDown(CONTROLLER_P1_AUTO);
		u32 keys_up = hidKeysUp(CONTROLLER_P1_AUTO);

		if (keys_down & KEY_PLUS) break;

		if (keys_down & KEY_LEFT) jptr->left = 1;
		if (keys_down & KEY_RIGHT) jptr->right = 1;
		if (keys_down & KEY_A) jptr->up = 1;
		if (keys_down & KEY_DOWN) jptr->down = 1;
		if (keys_down & KEY_B) jptr->fire = 1;

		if (keys_down & KEY_X) Game.m_GameTarget.m_Game.TogglePuffBlow();
		if (keys_down & KEY_MINUS) game_paused ^= 1;

		if (keys_up & KEY_LEFT) jptr->left = 0;
		if (keys_up & KEY_RIGHT) jptr->right = 0;
		if (keys_up & KEY_A) jptr->up = 0;
		if (keys_up & KEY_DOWN) jptr->down = 0;
		if (keys_up & KEY_B) jptr->fire = 0;

		// Fake a key press (to pass getPlayerName screen)
		jptr->key = 13;

		// Execute game logic
		Game.MainLoop(gamebuf, game_paused);

		// Draw to screen, upscaling in hardware
		u32 *framebuf = (u32*) gfxGetFramebuffer(NULL, NULL);
		for (int y = 0; y < SCR_HEIGHT; y++)
			for (int x = 0; x < SCR_WIDTH; x++)
				framebuf[gfxGetFramebufferDisplayOffset(x + 68, y)] = gamebuf[y * SCR_WIDTH + x];

		gfxFlushBuffers();
		gfxSwapBuffers();
		gfxWaitForVsync();

		// Add a delay, FIXME: calculate this with:
		//u64 time_now = svcGetSystemTick();
		svcSleepThread(40000000);
	}

	Game.SaveScores();

	// save config here :)

	Game.RemoveSoundDriver();

	// deinit
	free(gamebuf);
	gfxExit();

	return 0;
}