bool keyPressEvent(ALLEGRO_EVENT ev){ bool temp = false; // Temporary bool for returning if player wnts to end game if(ev.type == ALLEGRO_EVENT_KEY_DOWN){ // Check if player presses keyboard button switch(ev.keyboard.keycode){ // Switch for selecting which button was pressed // ESCAPE button case ALLEGRO_KEY_ESCAPE:{ // If gamePos equals to 3 (ingame) then set it to 1(menu) and destroy groundvector and ssop ingamesong from looping if (gamePos == 3){ gamePos = 1; groundVectorDestroy(); audio->stopLoopInGame(); } // gamePos equals to 1 (menu) else if(gamePos == 1) // menutext equals to 1 (main menu) if(menuText == 1) temp = true; // set temp value to true (for ending game) else // Return to last menu if(menuText != 4) menuText -= 1; else menuText = 2; break; } // SPACE button case ALLEGRO_KEY_SPACE:{ // gamePOs equalt to 3 (ingame) if(gamePos == 3) { // If player is in ground then player jumpsound and start uptimer so player will go up if (player->getGround()){ audio->jump(Volume, Pan); startTimer(1); // 1 (upTimer) } } break; } // ENTER button case ALLEGRO_KEY_ENTER:{ // Switch gamePos to do different thisg on different situations switch(gamePos){ // menu case(1):{ // switch to select in which menu we are switch(menuText){ case(1):{ // Main menu // switch to select in which position selection is switch (menuSelect){ case(1):{ // top gamePos = 2; // start game menuSelect = 0; break; } case(2):{ // middle menuText = 2; // set menutext to 2 (settings menu) menuSelect = 0; break; } case(3):{ //down temp = true; // Set temp to true (end game) break; } } break; } case(2):{ // Settings menu switch (menuSelect){ case(1):{ // top menuText = 3; // set menutext to 3 (graphics menu) menuSelect = 0; break; } case(2):{ // middle menuText = 4; // set menutext to 4 (audio menu) menuSelect = 0; break; } case(3):{ //down menuText = 1; // set menutext to 1 (main menu) menuSelect = 0; break; } } break; } case(3):{ // Graphics menu switch (menuSelect){ case(1):{ // top // Save values currently shown in screen to ini file and initialize game again iniWrite("Display", "Width", to_string(resWidth[resPos])); iniWrite("Display", "Height", to_string(resHeight[resPos])); iniWrite("Display", "FPS", to_string(tempFPS)); destroy(); initialize(); break; } case(2):{ // middle // Save values currently shown in screen to ini file and initialize game again iniWrite("Display", "Width", to_string(resWidth[resPos])); iniWrite("Display", "Height", to_string(resHeight[resPos])); iniWrite("Display", "FPS", to_string(tempFPS)); destroy(); initialize(); break; } case(3):{ //down menuText = 2; // Return to settings menu menuSelect = 0; break; } } break; } case(4):{ // Audio menu switch (menuSelect){ case(1):{ // top // Save values currently shown in screen to ini file and initialize game again iniWrite("Audio", "Volume", to_string(tempVolume)); iniWrite("Audio", "Pan", round(tempPan)); destroy(); initialize(); break; } case(2):{ // middle // Save values currently shown in screen to ini file and initialize game again iniWrite("Audio", "Volume", to_string(tempVolume)); iniWrite("Audio", "Pan", round(tempPan)); destroy(); initialize(); break; } case(3):{ //down menuText = 2; // Return to settings menu menuSelect = 0; break; } } break; } } break; } case(4):{ // End screen // Get to menu and destroy ground vector gamePos = 1; menuText = 1; groundVectorDestroy(); break; } } } // DOWN button case ALLEGRO_KEY_DOWN:{ if (gamePos == 1) { // if in menu if(menuSelect != 3) // if menuselect is not 3 menuSelect += 1; // then add 1 } break; } // UP button case ALLEGRO_KEY_UP:{ if (gamePos == 1) { // if in menu if(menuSelect != 1) // if menuselect is not 1 menuSelect -= 1; // then minus 1 } break; } // LEFT button case ALLEGRO_KEY_LEFT:{ if(gamePos == 1) { // if in menu switch(menuText){ case(3):{ // Graphics switch(menuSelect){ case(1):{ // top if(resPos != 0) // if not 0 resPos -= 1; // then minus 1 break; } case(2):{ // middle if(tempFPS != 5) // if not 5 tempFPS -= 5; // then minus 5 break; } } break; } case(4):{ // Audio switch(menuSelect){ case(1):{ // top if(tempVolume != 0) // if not 0 tempVolume -= 1; // then minus 1 break; } case(2):{ // middle if(tempPan > -1) // if bigger -1 tempPan -= 0.1; // then minus 0.1 else tempPan = -1; // else set to -1 break; } } break; } } } break; } case ALLEGRO_KEY_RIGHT:{ if(gamePos == 1) { switch(menuText){ case(3):{ // Graphics switch(menuSelect){ case(1):{ // top if(resPos != resolutions - 1) // if not end of list resPos += 1; // then add 1 break; } case(2):{ // middle tempFPS += 5; // add 5 break; } } break; } case(4):{ // Audio switch(menuSelect){ case(1):{ if(tempVolume != 100) // if not 100 tempVolume += 1; // add 1 break; } case(2):{ if(tempPan < 1) // if smaller than 1 tempPan += 0.1; // then add 0.1 else tempPan = 1; // else set to 1 break; } } break; } } break; } } } } return temp; }
bool CapApp::onInit(int argc, char* argv[]) { (void)argc; (void)argv; // ---------------------------------------------- // FTP cellSysmoduleLoadModule(CELL_SYSMODULE_NET); cellNetCtlInit(); cellSysmoduleLoadModule(CELL_SYSMODULE_HTTP); sys_net_initialize_network(); ftp_on(); // Load settings... if(!iniRead()) { iniWrite(); // create settings file... } cellSysmoduleLoadModule(CELL_SYSMODULE_FS); cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_SCREENSHOT); cellScreenShotEnable(); InputInit(); while(!videoOutIsReady()) { // ... } PSGLinitOptions options = { enable: PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS, maxSPUs: 1, initializeSPUs: GL_FALSE, persistentMemorySize: 0, transientMemorySize: 0, errorConsole: 0, fifoSize: 0, hostMemorySize: 128* 1024*1024, // 128 mbs for host memory }; #if CELL_SDK_VERSION < 0x340000 options.enable |= PSGL_INIT_HOST_MEMORY_SIZE; #endif // Initialize 6 SPUs but reserve 1 SPU as a raw SPU for PSGL sys_spu_initialize(6, 1); psglInit(&options); const unsigned int resolutions[] = { CELL_VIDEO_OUT_RESOLUTION_1080, CELL_VIDEO_OUT_RESOLUTION_960x1080, CELL_VIDEO_OUT_RESOLUTION_720, CELL_VIDEO_OUT_RESOLUTION_480 }; const int numResolutions = sizeof(resolutions) / sizeof(resolutions[0]); int bestResolution = chooseBestResolution(resolutions,numResolutions); getResolutionWidthHeight(bestResolution, deviceWidth, deviceHeight); if(bestResolution) { PSGLdeviceParameters params; params.enable = PSGL_DEVICE_PARAMETERS_COLOR_FORMAT | PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT | PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE; params.colorFormat = GL_ARGB_SCE; params.depthFormat = GL_NONE; params.multisamplingMode = GL_MULTISAMPLING_NONE_SCE; params.enable |= PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT; params.width = deviceWidth; params.height = deviceHeight; device = psglCreateDeviceExtended(¶ms); context = psglCreateContext(); psglMakeCurrent(context, device); psglResetCurrentContext(); initGraphics(); if( cellSysutilRegisterCallback( 0, callback_sysutil_exit, NULL ) < 0 ) { //... } dbgFontInit(); fbaRL = new c_fbaRL(); while(bRun) { onRender(); onUpdate(); cellSysutilCheckCallback(); } } else { // resolution error... } ftp_off(); onShutdown(); return false; } void CapApp::onRender() { if(fbaRL) { fbaRL->DlgDisplayFrame(); } // get render target buffer dimensions and set viewport psglGetRenderBufferDimensions(device,&app.renderWidth,&app.renderHeight); glViewport(0, 0, app.renderWidth, app.renderHeight); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(fbaRL) { fbaRL->RenderBackground(); } if(fbaRL) { fbaRL->nFrameStep = 0; fbaRL->DisplayFrame(); } if(fbaRL) { fbaRL->nFrameStep = 1; fbaRL->DisplayFrame(); } dbgFontDraw(); psglSwap(); } bool CapApp::onUpdate() { if(!mFrame) mFrame = 0; mFrame++; InputFrameStart(); if(fbaRL) fbaRL->InputFrame(); InputFrameEnd(); return true; } void CapApp::onShutdown() { iniWrite(); // save settings if(context) psglDestroyContext(context); if(device) psglDestroyDevice(device); InputExit(); psglExit(); }
bool mouseEvent(ALLEGRO_EVENT ev){ bool mouseTemp = false; // Temprary bool to return if player wants to quit if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN){ // if event is mouse button is pressed if(gamePos == 1){ // menu if(ev.mouse.x <= (WIDTH/2 + 150) && ev.mouse.x >= (WIDTH/2 - 150)){ // if mouse is in middle of screen if(ev.mouse.y <= (HEIGHT/8*3 + 50) && ev.mouse.y >= (HEIGHT/8*3 - 50)){ // if mouse is in top Y position switch(menuText){ case(1):{ // main menu gamePos = 2; // start game break; } case(2):{ // settings menu menuText = 3; // go to graphics menu break; } case(3):{ // graphics menu // Save values to ini and reinitialize game iniWrite("Display", "Width", to_string(resWidth[resPos])); iniWrite("Display", "Height", to_string(resHeight[resPos])); iniWrite("Display", "FPS", to_string(tempFPS)); destroy(); initialize(); break; } case(4):{ // audio menu // Save values to ini and reinitialize game iniWrite("Audio", "Volume", to_string(tempVolume)); iniWrite("Audio", "Pan", round(tempPan)); destroy(); initialize(); break; } } } if(ev.mouse.y <= (HEIGHT/8*4 + 50) && ev.mouse.y >= (HEIGHT/8*4 - 50)){ // if mouse is in middle Y position switch(menuText){ case(1):{ // main menu menuText = 2; // go to settings menu break; } case(2):{ // settings menu menuText = 4; // got to audio menu break; } case(3):{ // graphics menu // Save values to ini and reinitialize game iniWrite("Display", "Width", to_string(resWidth[resPos])); iniWrite("Display", "Height", to_string(resHeight[resPos])); iniWrite("Display", "FPS", to_string(tempFPS)); destroy(); initialize(); break; } case(4):{ // audio menu // Save values to ini and reinitialize game iniWrite("Audio", "Volume", to_string(tempVolume)); iniWrite("Audio", "Pan", round(tempPan)); destroy(); initialize(); break; } } } if(ev.mouse.y <= (HEIGHT/8*5 + 50) && ev.mouse.y >= (HEIGHT/8*5 - 50)){ // if mouse is in bottom Y position switch(menuText){ case(1):{ // main menu mouseTemp = true; // set exit temp to true break; } case(2):{ // settings menu menuText = 1; // go to main menu break; } case(3):{ // graphics menu menuText = 2; // go to setting menu break; } case(4):{ // audio menu menuText = 2; // go to setting menu break; } } } } } else if(gamePos == 3){ // ingame // if player in ground then jump and play jump sound if (player->getGround()){ audio->jump(Volume, Pan); startTimer(1); } } else if(gamePos == 4){ // end screen // Go to menu and destroy ground vector gamePos = 1; menuText = 1; groundVectorDestroy(); } } else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES || ev.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY){ // if mouse moves or enters display if(ev.mouse.x <= (WIDTH/2 + 150) && ev.mouse.x >= (WIDTH/2 - 150)){ // if mouse in middle if(ev.mouse.y <= (HEIGHT/8*3 + 50) && ev.mouse.y >= (HEIGHT/8*3 - 50)){ //if mouse in top y Position switch(menuText){ case(3):{ // graphics menu if(ev.mouse.dz > 0) // mouse scroll forward if(resPos != resolutions - 1) // if not last of list resPos += 1; // then add 1 else resPos = 0; // add to start else if(ev.mouse.dz < 0) // mouse scroll backward if(resPos != 0) // if not 0 resPos -= 1; // minus 1 else resPos = resolutions - 1; // set to end break; } case(4):{ // audio menu if(ev.mouse.dz > 0) // mouse scroll forward if(tempVolume != 100) // if not 100 tempVolume += 1; // add 1 else tempVolume = 100; // set to 100 else if(ev.mouse.dz < 0) // mouse scroll backward if(resPos != 0) // if not 0 tempVolume -= 1; // minus 1 else tempVolume = 0; // set to 0 break; } } menuSelect = 1; // set menuselect to top } if(ev.mouse.y <= (HEIGHT/8*4 + 50) && ev.mouse.y >= (HEIGHT/8*4 - 50)){ switch(menuText){ case(3):{ if(ev.mouse.dz > 0) // mouse scroll forward tempFPS += 5; // add 5 else if(ev.mouse.dz < 0) // mouse scroll backward if(tempFPS != 5) // if not 5 tempFPS -= 5; // minus 5 else tempFPS = 5; // set to 5 break; } case(4):{ if(ev.mouse.dz > 0) // mouse scroll forward if(tempPan < 1) // if smaller than 1 tempPan += 0.1; // add 0.1 else tempPan = 1; // set to 1 else if(ev.mouse.dz < 0) // mouse scroll backward if(tempPan > -1) // if bigger than -1 tempPan -= 0.1; // minus 1 else tempPan = -1; // set to -1 break; } } menuSelect = 2; // set menuselect to middle } if(ev.mouse.y <= (HEIGHT/8*5 + 50) && ev.mouse.y >= (HEIGHT/8*5 - 50)){ menuSelect = 3; // set menuselect to bottom } } } return mouseTemp; }
void ExitDlgCallbackFunction(int buttonType, void *userData) { int nDialog = (int)userData; switch( buttonType ) { case CELL_MSGDIALOG_BUTTON_YES: { if(nDialog == STATUS_ROMSCAN_DLG) { cellMsgDialogAbort(); iniWrite(); // save settings // delete old cache cellFsUnlink("/dev_hdd0/game/FBAL00123/USRDIR/FBA.GAMELIST.CACHE.DAT"); fbaRL->RefreshGameList(); // Refresh gamelist break; } if(nDialog == STATUS_EXIT_MMAN) { cellMsgDialogAbort(); iniWrite(); // save settings app.onShutdown(); char path[] = "/dev_hdd0/game/BLES80608/USRDIR/RELOAD.SELF"; if(fbaRL->FileExist(path)) { sys_game_process_exitspawn(path, NULL, NULL, NULL, 0, 1000, SYS_PROCESS_PRIMARY_STACK_SIZE_1M); } fbaRL->EndMainMenu(); break; } if(nDialog == STATUS_EXIT_IMANAGER) { cellMsgDialogAbort(); iniWrite(); // save settings app.onShutdown(); char path[] = "/dev_hdd0/game/IMANAGER4/USRDIR/iris_manager.self"; if(fbaRL->FileExist(path)) { sys_game_process_exitspawn(path, NULL, NULL, NULL, 0, 1000, SYS_PROCESS_PRIMARY_STACK_SIZE_1M); } fbaRL->EndMainMenu(); break; } if(nDialog == STATUS_EXIT_FBARL_RA) { cellMsgDialogAbort(); iniWrite(); // save settings app.onShutdown(); char fba_rl_path[] = "/dev_hdd0/game/FBAL00123/USRDIR/RELOAD.SELF"; char rom_path[] = "DUMMY_ARG"; char preset_cfg[] = "DUMMY_ARG"; char aspect_ratio[] = "DUMMY_ARG"; if(fbaRL->FileExist(fba_rl_path)) { fbaRL->LaunchFBACore( (char*)rom_path, (char*)fba_rl_path, (char*)preset_cfg, (char*)aspect_ratio, (char*)(g_opt_bUseAltMenuKeyCombo ? "yes" : "no") ); } fbaRL->EndMainMenu(); break; } if(nDialog == STATUS_EXIT) { cellMsgDialogAbort(); iniWrite(); // save settings app.onShutdown(); exit(0); fbaRL->EndMainMenu(); break; } break; } case CELL_MSGDIALOG_BUTTON_NO: case CELL_MSGDIALOG_BUTTON_ESCAPE: case CELL_MSGDIALOG_BUTTON_NONE: break; default: break; } }