void playRaw(const void *buf, const u32 len, u32 freq, u16 vol_left, u16 vol_right, u32 delay) { int i=next_voice_idx; /* for (i=0; sound[i] && i < MAX_SOUND_SLOT; i++) { u32 *pFlag = (u32 *)&(((char *)(sound[i]))[40]); // offset 40 is flags if (!(*pFlag & VOICE_RUNNING)) break; } */ if (i == MAX_SOUND_SLOT) i = 0; if (i > 0 && sound[i] == NULL) i = 0; if (sound[i]) { AESND_PlayVoice(sound[i], VOICE_MONO16, buf, len, freq, delay, 0); AESND_SetVoiceVolume(sound[i], vol_left, vol_right); next_voice_idx = i+1; } else { next_voice_idx = 0; } }
cui_menu menu_main(cui_game* p_game) { cui_menu next_state = CUI_MENU_MAIN; bool done=false; GRRLIB_ttfFont* font = GRRLIB_LoadTTF(font_ttf, font_ttf_size); GRRLIB_texImg *tex_pieces = GRRLIB_LoadTexture(chess_classic_png); GRRLIB_texImg *tex_tile = GRRLIB_LoadTexture(keyboard_key_png); GRRLIB_texImg *tex_btn = GRRLIB_LoadTexture(button_png); UI_button button_newgame; UI_InitBtn(&button_newgame, 280, 120, "New game"); button_newgame.img = tex_btn; button_newgame.font = font; UI_button button_options; UI_InitBtn(&button_options, 280, 200, "Options"); button_options.img = tex_btn; button_options.font = font; UI_button button_credit; UI_InitBtn(&button_credit, 280, 280, "credit"); button_credit.img = tex_btn; button_credit.font = font; while(!done){ cui_game_update_cursor(p_game->cursor); u32 pressed = WPAD_ButtonsDown(0); GRRLIB_PrintfTTF (5, 5, font, "ChessUI", 96, 0x424242FF); UI_UpdateBtn(&button_newgame, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); UI_UpdateBtn(&button_options, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); UI_UpdateBtn(&button_credit, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); if(button_newgame.click){ done=true; next_state=CUI_MENU_PLAY; } if(button_options.click){ done=true; next_state=CUI_MENU_OPTION; } if(button_credit.click){ done=true; next_state=CUI_MENU_CREDITS; } if ( pressed & WPAD_BUTTON_HOME ){ if(!p_game->is_mute)AESND_Pause(true); if(menu_home(p_game) == CUI_MENU_EXIT){done=true;next_state=CUI_MENU_EXIT;} if(!p_game->is_mute)AESND_Pause(false); } if ( pressed & WPAD_BUTTON_A ){ if(voice) AESND_PlayVoice(voice, VOICE_STEREO16, button_click_pcm, button_click_pcm_size, VOICE_FREQ48KHZ, 1, false); } cui_board_demo(p_game->board, tex_pieces, tex_tile, font); UI_DrawBtn(&button_newgame); UI_DrawBtn(&button_options); UI_DrawBtn(&button_credit); cui_cursor_display(p_game->cursor); GRRLIB_Render(); } GRRLIB_FreeTTF(font); GRRLIB_FreeTexture(tex_btn); free(button_newgame.text); free(button_options.text); free(button_credit.text); return next_state; }
cui_menu menu_play(cui_game* p_game) { cui_menu next_state = CUI_MENU_MAIN; bool done=false; GRRLIB_texImg *tex_pieces = GRRLIB_LoadTexture(chess_classic_png); GRRLIB_texImg *tex_tile = GRRLIB_LoadTexture(keyboard_key_png); GRRLIB_ttfFont* font = GRRLIB_LoadTTF(font_ttf, font_ttf_size); bool is_debug = false; char coords[5]; char calculated_coords[5]; strcpy(coords, "d2d20"); strcpy(calculated_coords, "d2d20"); while(!done){ WPAD_IR(0, &ir); WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); u32 released = WPAD_ButtonsUp(0); if(egg_check_s1_code(pressed, released)){ is_debug = true; p_game->board->tile_color1 = 0xc66300FF; p_game->board->tile_color2 = 0x632100FF; p_game->board->piece_color1 = 0x4242CCFF; p_game->board->piece_color2 = 0x444411FF; cui_board_init(p_game->board); if(voice) AESND_PlayVoice(voice, VOICE_STEREO8, warp, warp_size, VOICE_FREQ32KHZ, 1, false); } if ( pressed & WPAD_BUTTON_HOME ){ if(!p_game->is_mute)AESND_Pause(true); if(menu_home(p_game) == CUI_MENU_EXIT){done=true;next_state=CUI_MENU_EXIT;} if(!p_game->is_mute)AESND_Pause(false); } if ( pressed & WPAD_BUTTON_MINUS){ switch(menu_option(p_game)){ case CUI_MENU_OPTION_GFX:menu_option_gfx(p_game);break; case CUI_MENU_OPTION_SND:menu_option_snd(p_game);break; default:break; } } int index_offset_x = (p_game->cursor->hotspot_x - 40 / 2)/ 40 - 140 / 40; int index_offset_y = p_game->cursor->hotspot_y / 40 - 80 / 40; if (pressed & WPAD_BUTTON_B) { p_game->cursor->is_grabbing = true; if(index_offset_x >= 0 && index_offset_x < 8 && index_offset_y >= 0 && index_offset_y < 8){ coords[0] = 'a' + index_offset_x; coords[1] = '8' - index_offset_y; } } else if(released & WPAD_BUTTON_B){ p_game->cursor->is_grabbing = false; if(index_offset_x >= 0 && index_offset_x < 8 && index_offset_y >= 0 && index_offset_y < 8){ coords[2] = 'a' + index_offset_x; coords[3] = '8' - index_offset_y; coords[4] = 0; if(voice) AESND_PlayVoice(voice, VOICE_STEREO16, move_pcm, move_pcm_size, VOICE_FREQ48KHZ, 1, false); if(calculate_coords(coords, calculated_coords, p_game->engine)){ cui_board_read_core(p_game->board, p_game->engine); } } } cui_cursor_update(p_game->cursor, ir.x, ir.y, ir.angle); if(p_game->tex_wallpaper)GRRLIB_DrawImg(0, -50, p_game->tex_wallpaper, 1, 1, 1, 0XFFFFFFFF); cui_board_display(p_game->board, tex_pieces, tex_tile, font, index_offset_x, index_offset_y); cui_cursor_display(p_game->cursor); if(is_debug){ GRRLIB_PrintfTTF (20, 00, font, coords, 16, 0x424242FF); GRRLIB_PrintfTTF2 (20, 20, font, 16, 0xFFFFFFFF, "x:%.2f y:%.2f", ir.x, ir.y); GRRLIB_PrintfTTF2 (20, 40, font, 16, 0xFFFFFFFF, "x:%.2f y:%.2f", ir.x/40, ir.y/40); GRRLIB_PrintfTTF2 (20, 60, font, 16, 0xFFFFFFFF, "x:%d y:%d", index_offset_x, index_offset_y); GRRLIB_PrintfTTF (20, 80, font, p_game->cursor->is_grabbing?"GRAB":"POINT", 16, 0xFFFFFFFF); GRRLIB_Rectangle(p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, 4, 4, 0xFF4242FF, 1); } GRRLIB_Render(); } GRRLIB_FreeTexture(tex_pieces); GRRLIB_FreeTexture(tex_tile); GRRLIB_FreeTTF(font); return next_state; }
//------------------------------------------------------------------------------ //! \brief Play a sample (called from the game) //! //! \param id = SND_xxx id //! \param pos = Sample Position to use 0 to 255 //! \param rate = The rate //------------------------------------------------------------------------------ void CAudioDrv::PlaySample(int id, int pos, int rate) { if (m_DisableSamplesFlag) return; const void *sound_ptr = NULL; u32 sound_length = 0; if (rate == 0) rate = VOICE_FREQ32KHZ; switch(id) { case SND_CAR: sound_ptr = &car_raw; sound_length = car_raw_size; break; case SND_TRAIN: sound_ptr = &train_raw; sound_length = train_raw_size; break; case SND_DUCK: sound_ptr = &duck_raw; sound_length = duck_raw_size; break; case SND_PICKUP1: sound_ptr = &pickup1_raw; sound_length = pickup1_raw_size; break; case SND_TRIBBLE: sound_ptr = &tribble_raw; sound_length = tribble_raw_size; break; case SND_HURRY: sound_ptr = &hurry_raw; sound_length = hurry_raw_size; break; case SND_DAY: sound_ptr = &day_raw; sound_length = day_raw_size; break; case SND_CRYING: sound_ptr = &crying_raw; sound_length = crying_raw_size; break; case SND_DIE2: sound_ptr = &die2_raw; sound_length = die2_raw_size; break; case SND_SPIT: sound_ptr = &spit_raw; sound_length = spit_raw_size; break; case SND_SPLAT: sound_ptr = &splat_raw; sound_length = splat_raw_size; break; case SND_BLOW: sound_ptr = &blow_raw; sound_length = blow_raw_size; break; case SND_TWINKLE: sound_ptr = &twinkle_raw; sound_length = twinkle_raw_size; break; case SND_FINLEV1: sound_ptr = &finlev1_raw; sound_length = finlev1_raw_size; break; case SND_PSTAR: sound_ptr = &pstar_raw; sound_length = pstar_raw_size; break; case SND_XYLO: sound_ptr = &xylo_raw; sound_length = xylo_raw_size; break; case SND_CARDSOUND: sound_ptr = &card_raw; sound_length = card_raw_size; break; case SND_BOWLINGSOUND: sound_ptr = &bowling_raw; sound_length = bowling_raw_size; break; case SND_CANDLESOUND: sound_ptr = &candle_raw; sound_length = candle_raw_size; break; case SND_MARBLESOUND: sound_ptr = &marble_raw; sound_length = marble_raw_size; break; case SND_TAPSOUND: sound_ptr = &tap_raw; sound_length = tap_raw_size; break; case SND_OILSOUND: sound_ptr = &oil_raw; sound_length = oil_raw_size; break; case SND_SPININGTOPSOUND: sound_ptr = &spiningtop_raw; sound_length = spiningtop_raw_size; break; case SND_WINGSSOUND: sound_ptr = &wings_raw; sound_length = wings_raw_size; break; case SND_MOONSOUND: sound_ptr = &moon_raw; sound_length = moon_raw_size; break; case SND_MASKSOUND: sound_ptr = &mask_raw; sound_length = mask_raw_size; break; case SND_REDSTARSOUND: sound_ptr = &redstar_raw; sound_length = redstar_raw_size; break; case SND_TURBOSOUND: sound_ptr = &turbo_raw; sound_length = turbo_raw_size; break; case SND_CHICKENSOUND: sound_ptr = &chicken_raw; sound_length = chicken_raw_size; break; case SND_FEATHERSOUND: sound_ptr = &feather_raw; sound_length = feather_raw_size; break; case SND_WPOTIONSOUND: sound_ptr = &wpotion_raw; sound_length = wpotion_raw_size; break; case SND_COOKIESOUND: sound_ptr = &cookie_raw; sound_length = cookie_raw_size; break; default: // Error: unknown sample return; } // Add a voice AESNDPB* this_voice = AESND_AllocateVoice(VoiceCallBack); // Check if voice was available if (this_voice) { AESND_PlayVoice(this_voice, VOICE_STEREO16, sound_ptr, sound_length, rate, 0, 0); // Do volume math (with fake panning) int vol_l = ((255 - pos) > 0) ? (255 - pos) : 0; vol_l = (vol_l > 255) ? 255 : vol_l; vol_l = (float) sound_volume * (float) vol_l / 10.0; int vol_r = (pos > 0) ? pos : 0; vol_r = (vol_r > 255) ? 255 : vol_r; vol_r = (float) sound_volume * (float) pos / 10.0; AESND_SetVoiceVolume(this_voice, vol_l, vol_r); } }