Ejemplo n.º 1
0
static void processMenuOption(int menuopt)
{
    switch(menuopt) {
        case EXIT :
            killMenuLanguages();
            MODPlay_Unload (&mod_track);
            Free_Voice();
            WPAD_Shutdown();
            GRRLIB_Stop();
            saveConfig(FILE_CFG);
            // if we have been launched from a channel then reset to menu
            if (!*((u32*) 0x80001800)) {
                WII_Initialize();
                WII_ReturnToMenu();
            }
            else {               // else the homebrew is launched from a loader so exit back to the loader
                exit(0);
            }
            break;
        case ONE_PLAYER_GAME :
        case TWO_PLAYER_COOP :
        case TWO_PLAYER_VERSUS :
            main_mode=GAME;
            initGame(menuopt);
            break;
    }
    if(menuopt>=MUSIC_BAR && menuopt<=(MUSIC_BAR+64)) {
        MODPlay_SetVolume( &mod_track, opt_music, opt_music);
    }
}
//------------------------------------------------------------------------------
//! \brief Play a module (called from the game)
//!
//! \param id = SMOD_xxx id
//------------------------------------------------------------------------------
void CAudioDrv::PlayModule(int id)
{
	if (!m_AudioValidFlag) return;
	if (m_DisableMusicFlag) return;

	MODPlay_Stop(&methane_music);

	if (m_DisableMusicFlag) id = SMOD_EMPTY;

	switch(id) {
		case SMOD_TUNE1:
			MODPlay_SetMOD(&methane_music, tune1_mod);
			break;
		case SMOD_TUNE2:
			MODPlay_SetMOD(&methane_music, tune2_mod);
			break;
		case SMOD_BOSS:
			MODPlay_SetMOD(&methane_music, boss_mod);
			break;
		case SMOD_COMPLETE:
			MODPlay_SetMOD(&methane_music, complete_mod);
			break;
		case SMOD_TITLE:
			MODPlay_SetMOD(&methane_music, title_mod);
			break;
		default:
			MODPlay_SetMOD(&methane_music, empty_mod);
			break;
	}

	// Set the volume, cause it resets on every new mod
	MODPlay_SetVolume(&methane_music, music_volume, music_volume);
	MODPlay_Start(&methane_music);
}
//------------------------------------------------------------------------------
//! \brief Change the music and sound volume
//! \param s = sound volume (0 to 10)
//! \param m = music volume (0 to 10)
//------------------------------------------------------------------------------
void CAudioDrv::ChangeVolume(int s, int m)
{
	sound_volume = s;
	music_volume = m * 6.4;

	// Set the volume for the current mod
	MODPlay_SetVolume(&methane_music, music_volume, music_volume);
}
Ejemplo n.º 4
0
int main(int argc, char* argv[])
{
    u8 *tex_ptrone=GRRLIB_LoadTexture(handpointerred_png);
    u8 *tex_ptrtwo=GRRLIB_LoadTexture(handpointergreen_png);
    u8 *tex_back=GRRLIB_LoadJPG(bigmenuback_jpg, bigmenuback_jpg_size);
    u8 *tex_fore=GRRLIB_LoadTexture(credits_png);

    fatInitDefault();
    GRRLIB_InitVideo();
    WPAD_Init();

    SYS_SetResetCallback(WiiResetPressed);
    SYS_SetPowerCallback(WiiPowerPressed);
    WPAD_SetPowerButtonCallback(WiimotePowerPressed);
    rmode = VIDEO_GetPreferredMode(NULL);

    AESND_Init(NULL);
    MODPlay_Init(&mod_track);
    Init_Voice();

    AESND_Pause(0);                // the sound loop is running now

                                 // set the MOD song
    if (MODPlay_SetMOD (&mod_track, dojo_dan_oriental_mod) < 0 ) {
        MODPlay_Unload (&mod_track);
    } else {
        // set the music volume to the minimum so we don't hear the music before saved volume is known
        MODPlay_SetVolume( &mod_track, 0,0);
        MODPlay_Start (&mod_track);// Play the MOD
    }

    WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);

    WPAD_SetVRes(WPAD_CHAN_ALL, rmode->fbWidth, rmode->xfbHeight);

    initMain();

    MODPlay_SetVolume( &mod_track, opt_music, opt_music);

    while( HWButton == 0) {
        WPAD_ScanPads();
        u32 wpad_one_down = WPAD_ButtonsDown(0);
        u32 wpad_two_down = WPAD_ButtonsDown(1);

        u32 type;
        WPADData *wd_one, *wd_two;
        WPAD_ReadPending(WPAD_CHAN_ALL, countevs);
        WPAD_Probe(WPAD_CHAN_ALL, &type);

        wd_one = WPAD_Data(0);
        wd_two = WPAD_Data(1);

        switch(main_mode) {
            case STARTUP :
                GRRLIB_FillScreen(0xFF000000);
                GRRLIB_DrawImg(0, 0, 640, 480, tex_back, 0, 1, 1, alpha>255?255:alpha);
                GRRLIB_DrawImg(68,308, 256, 80, tex_fore, 0, 1, 1, alpha>255?255:alpha);
                if(alpha++>394 || wpad_one_down > 0) {
                    main_mode=MENU;
                    if(tex_back) free(tex_back);
                    if(tex_fore) free(tex_fore);
                    initMenu();
                }
                break;
            case MENU :
                GRRLIB_FillScreen(0xFF000000);
                int menuopt = menuWiimote(wd_one,wpad_one_down);
                if(menuopt==EXIT) {
                    if(tex_ptrone) free(tex_ptrone);
                    if(tex_ptrtwo) free(tex_ptrtwo);
                }

                if(menuopt>NOTHING) {
                    processMenuOption(menuopt);
                    if(main_mode==GAME) {
                        MODPlay_Unload (&mod_track);
                        if(opt_tileset==SPOOKY)
                            MODPlay_SetMOD (&mod_track, graveyard_mod);
                        else
                        if(opt_tileset==EGYPTIAN)
                            MODPlay_SetMOD (&mod_track, egypt_crap_mod);
                        else
                        if(opt_tileset==SIMPLE)
                            MODPlay_SetMOD (&mod_track, childhood_mod);
                        else
                        if(opt_tileset==SPACE)
                            MODPlay_SetMOD (&mod_track, nebulos_mod);
                        else
                            MODPlay_SetMOD (&mod_track, sushi_mod);
                        MODPlay_SetVolume( &mod_track, opt_music, opt_music);
                        MODPlay_Start (&mod_track);
                    }
                    else
                        drawMenu(wd_one);
                }
                else
                    drawMenu(wd_one);
                break;
            case GAME :
                if(gameWiimote(wd_one,wpad_one_down,wd_two,wpad_two_down)) {
                    // we are exiting the game back to the menu
                    main_mode=MENU;
                    MODPlay_Unload (&mod_track);
                    MODPlay_SetMOD (&mod_track, dojo_dan_oriental_mod);
                    MODPlay_SetVolume( &mod_track, opt_music, opt_music);
                    MODPlay_Start (&mod_track);
                    killGame();
                    initMenu();
                }
                else {
                    drawGame();
                }
                break;
        }

        // alternate which pointer is on top every frame to not give the advantage to player one in two player mode
        static int ticktock=0;

        ticktock++;

        if(wd_two->ir.valid && ticktock%2==0) {
            if(main_mode==GAME && whatGameMode()==ONE_PLAYER_GAME) {
                // don't display second pointer in one player mode
            }
            else
                GRRLIB_DrawColImg(wd_two->ir.x - 9,wd_two->ir.y - 7,68,80,tex_ptrtwo,0,1,1,0xEEFFFFFF);
        }

        if(wd_one->ir.valid) {
            GRRLIB_DrawColImg(wd_one->ir.x - 9,wd_one->ir.y - 7,68,80,tex_ptrone,0,1,1,0xEEFFFFFF);
        }

        if(wd_two->ir.valid && ticktock%2!=0) {
            if(main_mode==GAME && whatGameMode()==ONE_PLAYER_GAME) {
                // don't display second pointer in one player mode
            }
            else
                GRRLIB_DrawColImg(wd_two->ir.x - 9,wd_two->ir.y - 7,68,80,tex_ptrtwo,0,1,1,0xEEFFFFFF);
        }

        if(wd_one->btns_h & WPAD_BUTTON_1) {
            GRRLIB_ScrShot("MahjonggWii_Screen_%y%m%d_%H%M%S.png",time(NULL));
        }

        GRRLIB_Render();
    }

    // we are exiting, free the mallocs
    switch( main_mode) {
        case GAME:
            killGame();

    }
    if(tex_ptrone) free(tex_ptrone);
    if(tex_ptrtwo) free(tex_ptrtwo);
    killMenuLanguages();
    MODPlay_Unload (&mod_track);
    Free_Voice();
    WPAD_Shutdown();
    GRRLIB_Stop();
    saveConfig(FILE_CFG);
    SYS_ResetSystem(HWButton, 0, 0);

    return 0;
}
Ejemplo n.º 5
0
void _Music_Start()
{
	int ret;

	// always init SND, so banner sounds play if music disabled
	ASND_Init();
	ASND_Pause(0);

	if (CFG.music == 0) {
		dbg_printf(gt("Music: Disabled"));
		dbg_printf("\n");
		return;
	} else {
		dbg_printf(gt("Music: Enabled"));
		dbg_printf("\n");
	}
	
	was_playing = false;

	//get a music file
	ret = get_music_file();
	if (ret==0) return;

	if (music_format == FORMAT_MP3) {

		MP3Player_Init();
		MP3Player_Volume(0x80); // of 255
		//ret = MP3Player_PlayBuffer(music_buf, music_size, NULL);
		ret = MP3Player_PlayFile(music_f, mp3_reader, NULL);
		dbg_printf("mp3 play: %s (%d)\n", ret? gt("ERROR"):gt("OK"), ret);
		if (ret) goto err_play;
		usleep(10000); // wait 10ms and verify if playing
		if (!MP3Player_IsPlaying()) {
			err_play:
			printf(gt("Error playing %s"), music_fname);
			printf("\n");
			Music_Stop();
			sleep(1);
		}

	} else {

		music_buf = malloc(music_size);
		if (!music_buf) {
			printf(gt("music file too big (%d) %s"), music_size, music_fname);
			printf("\n");
			sleep(1);
			music_format = 0;
			return;
		}
		//printf("Loading...\n");
		ret = fread(music_buf, music_size, 1, music_f);
		//printf("size: %d %d\n", music_size, ret); sleep(2);
		fclose(music_f);
		music_f = NULL;
		if (ret != 1) {
			printf(gt("error reading: %s (%d)"), music_fname, music_size); printf("\n"); sleep(2);
			free(music_buf);
			music_buf = NULL;
			music_size = 0;
			music_format = 0;
			return;
		}
		MODPlay_Init(&mod);
		ret = MODPlay_SetMOD(&mod, music_buf);
		dbg_printf("mod play: %s (%d)\n", ret?gt("ERROR"):gt("OK"), ret);
		if (ret < 0 ) {
			Music_Stop();
		} else  {
			MODPlay_SetVolume(&mod, 32,32); // fix the volume to 32 (max 64)
			MODPlay_Start(&mod); // Play the MOD
		}
	}
}
Ejemplo n.º 6
0
int main(int argc, char **argv) {

  GRRLIB_Init();	
	
  // Initialise the attached controllers
  WPAD_Init();
  WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
	
  // Initialise the audio subsystem
  AESND_Init(NULL);
	
  MODPlay_Init(&play);
  MODPlay_SetMOD(&play,bg_music);
  MODPlay_SetVolume(&play,63,63);
  MODPlay_Start(&play);

  cui_cursor cursor;
  cursor.tex[0]=GRRLIB_LoadTexture(player1_point_png);
  cursor.tex[1]=GRRLIB_LoadTexture(player1_grab_png);
  cursor.is_grabbing=false; 
	
  cui_board board;
	
  ENGINE engine = FIRSTCHESS;
  if(engine == TSCP){
    int i;
    for (i=0; i < CUI_TILE_NB; i++) {
      board.piece[i]=init_piece[i];
      if(init_color[i] == 1){
	board.color[i]=CUI_BLACK;
      }else if (init_color[i] == 6){
	board.color[i]=CUI_EMPTY;
      }else if (init_color[i] == 0){
	board.color[i]=CUI_WHITE;
      }
    }
			
    init_hash();
    init_board();
    open_book();
    gen();
  }


  cui_board_read_core(&board, engine);

  GRRLIB_SetBackgroundColour(0x030, 0x30, 0x42, 0xFF);
	
  board.tile_color1 = 0xAAAAAAFF;
  board.tile_color2 = 0x444444FF;
  board.piece_color1 = 0xAAAAAAFF;
  board.piece_color2 = 0x444444FF;
	
  cui_board_init(&board);

  cui_game game;
  game.board = &board;
  game.engine = engine; 
  game.cursor = &cursor;
  game.is_mute = false;
  GRRLIB_texImg *tex_wallpaper = GRRLIB_LoadTexture(wall_jpg);
  game.tex_wallpaper = tex_wallpaper;
			
	
  voice = AESND_AllocateVoice(aesnd_callback);
  AESND_SetVoiceVolume(voice, 0xFF, 0xFF);
  AESND_SetVoiceStream(voice, true);

  cui_menu current_state = CUI_MENU_MAIN;
	 
  while(current_state != CUI_MENU_EXIT) {
    switch(current_state){
    case CUI_MENU_MAIN:	current_state=menu_main(&game);break;
    case CUI_MENU_PLAY:	current_state=menu_play(&game);break;
    case CUI_MENU_OPTION:current_state=menu_option(&game);break;
    case CUI_MENU_OPTION_GENERAL:current_state=menu_option_general(&game);break;
    case CUI_MENU_OPTION_GFX:current_state=menu_option_gfx(&game);break;
    case CUI_MENU_OPTION_SND:current_state=menu_option_snd(&game);break;
    case CUI_MENU_CREDITS:current_state=menu_credits(&game);break;
    case CUI_MENU_PAUSE:current_state=menu_pause(&game);break;
    case CUI_MENU_HOME:current_state=menu_home(&game);break;
    case CUI_MENU_EXIT:current_state=menu_exit(&game);break;
    default:break;
    }
  }
	
  GRRLIB_FreeTexture(tex_wallpaper);
  GRRLIB_FreeTexture(cursor.tex[0]);
  GRRLIB_FreeTexture(cursor.tex[1]);
  GRRLIB_Exit();
  return 0;
}