static void GetUsedGameInputs( vector<GameInput> &vGameInputsOut ) { vGameInputsOut.clear(); set<GameInput> vGIs; vector<const Style*> vStyles; GAMEMAN->GetStylesForGame( GAMESTATE->m_pCurGame, vStyles ); FOREACH( const Style*, vStyles, style ) { bool bFound = find( STEPS_TYPES_TO_SHOW.GetValue().begin(), STEPS_TYPES_TO_SHOW.GetValue().end(), (*style)->m_StepsType ) != STEPS_TYPES_TO_SHOW.GetValue().end(); if( !bFound ) continue; FOREACH_PlayerNumber( pn ) { for( int i=0; i<(*style)->m_iColsPerPlayer; i++ ) { StyleInput si( pn, i ); GameInput gi = (*style)->StyleInputToGameInput( si ); if( gi.IsValid() ) { vGIs.insert( gi ); } } } }
GameInput InventoryScreen::recupInput() { sf::Event event; GameInput input; while (!input.isValid()) { GameWindow::window.waitEvent(event); input.treatEvent(event); } return input; }
void ScreenTestLights::Update( float fDeltaTime ) { Screen::Update( fDeltaTime ); if( m_timerBackToAutoCycle.Ago() > 20 ) { m_timerBackToAutoCycle.Touch(); LIGHTSMAN->SetLightsMode( LIGHTSMODE_TEST_AUTO_CYCLE ); } CabinetLight cl = LIGHTSMAN->GetFirstLitCabinetLight(); GameInput gi = LIGHTSMAN->GetFirstLitGameButtonLight(); RString s; switch( LIGHTSMAN->GetLightsMode() ) { case LIGHTSMODE_TEST_AUTO_CYCLE: s += AUTO_CYCLE.GetValue()+"\n"; break; case LIGHTSMODE_TEST_MANUAL_CYCLE: s += MANUAL_CYCLE.GetValue()+"\n"; break; default: break; } if( cl == CabinetLight_Invalid ) s += CABINET_LIGHT.GetValue()+": -----\n"; else s += ssprintf( "%s: %d %s\n", CABINET_LIGHT.GetValue().c_str(), cl, CabinetLightToString(cl).c_str() ); if( !gi.IsValid() ) { s += CONTROLLER_LIGHT.GetValue()+": -----\n"; } else { RString sGameButton = GameButtonToLocalizedString( INPUTMAPPER->GetInputScheme(), gi.button ); PlayerNumber pn = (PlayerNumber)(gi.controller); s += ssprintf( "%s: %s %d %s\n", CONTROLLER_LIGHT.GetValue().c_str(), PlayerNumberToString(pn).c_str(), gi.button, sGameButton.c_str() ); } m_textInputs.SetText( s ); }
void InputMapper::ClearFromInputMap( GameInput GameI, int iSlotIndex ) { if( !GameI.IsValid() ) return; m_GItoDI[GameI.controller][GameI.button][iSlotIndex].MakeInvalid(); UpdateTempDItoGI(); }
void InputMapper::ReadMappingsFromDisk() { ASSERT( GAMEMAN != NULL ); ClearAllMappings(); IniFile ini; if( !ini.ReadFile( KEYMAPS_PATH ) ) LOG->Trace( "Couldn't open mapping file \"%s\": %s.", KEYMAPS_PATH, ini.GetError().c_str() ); const Game *pGame = GAMESTATE->GetCurrentGame(); const XNode *Key = ini.GetChild( pGame->m_szName ); if( Key ) { FOREACH_CONST_Attr( Key, i ) { const CString &name = i->m_sName; const CString &value = i->m_sValue; GameInput GameI; GameI.fromString( pGame, name ); CStringArray sDeviceInputStrings; split( value, ",", sDeviceInputStrings, false ); for( unsigned i=0; i<sDeviceInputStrings.size() && i<unsigned(NUM_GAME_TO_DEVICE_SLOTS); i++ ) { DeviceInput DeviceI; DeviceI.fromString( sDeviceInputStrings[i] ); if( DeviceI.IsValid() ) SetInputMap( DeviceI, GameI, i ); } } } AddDefaultMappingsForCurrentGameIfUnmapped(); }
void InputMapper::ReadMappingsFromDisk() { ASSERT( GAMEMAN != NULL ); ClearAllMappings(); IniFile ini; if( !ini.ReadFile( KEYMAPS_PATH ) ) LOG->Trace( "Couldn't open mapping file \"%s\": %s.", KEYMAPS_PATH, ini.GetError().c_str() ); const IniFile::key *Key = ini.GetKey( GAMESTATE->GetCurrentGame()->m_szName ); if( Key ) { for( IniFile::key::const_iterator i = Key->begin(); i != Key->end(); ++i ) { const CString &name = i->first; const CString &value = i->second; GameInput GameI; GameI.fromString( name ); CStringArray sDeviceInputStrings; split( value, ",", sDeviceInputStrings, false ); for( unsigned i=0; i<sDeviceInputStrings.size() && i<unsigned(NUM_GAME_TO_DEVICE_SLOTS); i++ ) { DeviceInput DeviceI; DeviceI.fromString( sDeviceInputStrings[i] ); if( DeviceI.IsValid() ) SetInputMap( DeviceI, GameI, i ); } } } AddDefaultMappingsForCurrentGameIfUnmapped(); }
int InventoryController::launch(Character &character) { //Juste display the inventory until you press I, Escape or Close inventoryScreen.display(character); GameInput input = this->inventoryScreen.recupInput(); while (input.getValue() != I_INPUT) { if (input.getValue() == ESCAPE_INPUT) return I_INPUT; if (input.getValue() == CLOSE_INPUT) return input.getValue(); input = this->inventoryScreen.recupInput(); } return input.getValue(); }
void Journal::add_input(GameInput input) { Log::trace("Journal add_input: %s.", input.to_string().c_str()); const long itime = input.game_time; enforce(itime > 0); if(m_earliest_undiscovered > itime) m_earliest_undiscovered = itime; // ordered insert of the input into the record const auto after = std::find_if(m_inputs.begin(), m_inputs.end(), greater_time(itime)); m_inputs.insert(after, InputDiscovered{input, false}); // prune checkpoints to maintain integrity auto is_obsolete = [itime](const GameState& s) { return s.game_time() >= itime; }; auto obs_it = std::remove_if(m_checkpoint.begin(), m_checkpoint.end(), is_obsolete); m_checkpoint.erase(obs_it, m_checkpoint.end()); }
/* handleKeyEvent - this method handles all keyboard interactions. Note that every frame this method gets called and it can respond to key interactions in any custom way. Ask the GameInput class for key states since the last frame, which can allow us to respond to key presses, including when keys are held down for multiple frames. */ void BugsKeyEventHandler::handleKeyEvents(Game *game) { // WE CAN QUERY INPUT TO SEE WHAT WAS PRESSED GameInput *input = game->getInput(); // LET'S GET THE PLAYER'S PHYSICAL PROPERTIES, IN CASE WE WANT TO CHANGE THEM GameStateManager *gsm = game->getGSM(); AnimatedSprite *player = gsm->getSpriteManager()->getPlayer(); PhysicalProperties *pp = player->getPhysicalProperties(); Viewport *viewport = game->getGUI()->getViewport(); // IF THE GAME IS IN PROGRESS if (gsm->isGameInProgress()) { if (input->isKeyDownForFirstTime(D_KEY)) { viewport->toggleDebugView(); game->getGraphics()->toggleDebugTextShouldBeRendered(); } if (input->isKeyDownForFirstTime(L_KEY)) { game->getGraphics()->togglePathfindingGridShouldBeRendered(); } if (input->isKeyDownForFirstTime(F_KEY)) { game->getGraphics()->togglePathfindingPathShouldBeRendered(); } if (input->isKeyDownForFirstTime(R_KEY)) { if (wcscmp(player->getCurrentState().c_str(), L"RUNNING") == 0) player->setCurrentState(L"WALKING"); else if ((wcscmp(player->getCurrentState().c_str(), L"IDLE") != 0) && (wcscmp(player->getCurrentState().c_str(), L"DANCING") != 0)) player->setCurrentState(L"RUNNING"); } if (input->isKeyDownForFirstTime(Y_KEY)){ player->setCurrentState(DYING); } if (input->isKeyDownForFirstTime(I_KEY)){ player->setCurrentState(IDLE); } bool viewportMoved = false; float viewportVx = 0.0f; float viewportVy = 0.0f; float vX = pp->getVelocityX(); float vY = pp->getVelocityY(); if (input->isKeyDown(UP_KEY)) { if (pp->getY() < (viewport->getViewportY() + 0.5f * viewport->getViewportHeight())) viewportVy -= MAX_PLAYER_VELOCITY; vY = -1 * MAX_PLAYER_VELOCITY; vX = 0; viewportMoved = true; } else if (input->isKeyDown(DOWN_KEY)) { if (pp->getY() > (viewport->getViewportY() + 0.5f * viewport->getViewportHeight())) viewportVy += MAX_PLAYER_VELOCITY; vY = MAX_PLAYER_VELOCITY; vX = 0; viewportMoved = true; } else if (input->isKeyDown(LEFT_KEY)) { if (pp->getX() < (viewport->getViewportX() + 0.5f * viewport->getViewportWidth())) viewportVx -= MAX_PLAYER_VELOCITY; vX = -1 * MAX_PLAYER_VELOCITY; vY = 0; viewportMoved = true; } else if (input->isKeyDown(RIGHT_KEY)) { if (pp->getX() > (viewport->getViewportX() + 0.5f * viewport->getViewportWidth())) viewportVx += MAX_PLAYER_VELOCITY; vX = MAX_PLAYER_VELOCITY; vY = 0; viewportMoved = true; } else { vX = 0.0f; vY = 0.0f; } if (viewportMoved) viewport->moveViewport((int)floor(viewportVx+0.5f), (int)floor(viewportVy+0.5f), game->getGSM()->getWorld()->getWorldWidth(), game->getGSM()->getWorld()->getWorldHeight()); pp->setVelocity(vX, vY); } // 0X43 is HEX FOR THE 'C' VIRTUAL KEY // THIS CHANGES THE CURSOR IMAGE if ((input->isKeyDownForFirstTime(C_KEY)) && input->isKeyDown(VK_SHIFT)) { Cursor *cursor = game->getGUI()->getCursor(); unsigned int id = cursor->getActiveCursorID(); id++; if (id == cursor->getNumCursorIDs()) id = 0; cursor->setActiveCursorID(id); } // LET'S MESS WITH THE TARGET FRAME RATE IF THE USER PRESSES THE HOME OR END KEYS WindowsTimer *timer = (WindowsTimer*)game->getTimer(); int fps = timer->getTargetFPS(); // THIS SPEEDS UP OUR GAME LOOP AND THUS THE GAME, NOTE THAT WE COULD ALTERNATIVELY SCALE // DOWN THE GAME LOGIC (LIKE ALL VELOCITIES) AS WE SPEED UP THE GAME. THAT COULD PROVIDE // A BETTER PLAYER EXPERIENCE if (input->isKeyDown(VK_HOME) && (fps < MAX_FPS)) timer->setTargetFPS(fps + FPS_INC); // THIS SLOWS DOWN OUR GAME LOOP, BUT WILL NOT GO BELOW 5 FRAMES PER SECOND else if (input->isKeyDown(VK_END) && (fps > MIN_FPS)) timer->setTargetFPS(fps - FPS_INC); }
void GroceryDashKeyEventHandler::handleKeyEvents(Game *game){ // WE CAN QUERY INPUT TO SEE WHAT WAS PRESSED GameInput *input = game->getInput(); // LET'S GET THE PLAYER'S PHYSICAL PROPERTIES, IN CASE WE WANT TO CHANGE THEM GameStateManager *gsm = game->getGSM(); TopDownSprite *player = gsm->getSpriteManager()->getPlayer(); b2Body *playerBody = game->getGSM()->getSpriteManager()->playerBody; PhysicalProperties *pp = player->getPhysicalProperties(); Viewport *viewport = game->getGUI()->getViewport(); GroceryDashDataLoader* dataLoader = dynamic_cast<GroceryDashDataLoader*>(game->getDataLoader()); if (!gsm->isGameInProgress()){ if (input->isKeyDownForFirstTime(ESC_KEY)){ if (gsm->isAtInGameHelp() == true){ gsm->goToPauseMenu(); } else{ if (gsm->isAtSettingsScreen() == true || gsm->isAtAboutScreen() == true || gsm->isAtAchievementsScreen() == true || gsm->isAtHelpScreen() == true || gsm->isAtLevelSelect() == true || gsm->isAtStatsScreen() == true){ gsm->goToMainMenu(); } } } }//BRACKET -- !isGameInProgress if (gsm->isAtPauseMenu()){ if (input->isKeyDownForFirstTime(R_KEY)) { gsm->goToGame(); } } if (gsm->isGameInProgress()) { if (input->isKeyDownForFirstTime(P_KEY)) { gsm->goToPauseMenu(); } if (input->isKeyDownForFirstTime(L_KEY)) { if ( gsm->isAtItemList() == false){ gsm->goToItemList(); } else{ gsm->goToGame(); } } if (input->isKeyDownForFirstTime(C_KEY)) { if (gsm->isAtCartScreen() == false){ gsm->goToCartScreen(); } else{ gsm->goToGame(); } } if (input->isKeyDownForFirstTime(M_KEY)){ runScript(game); } // ARROW KEYS PRESSES WILL CONTROL THE PLAYER // THE USER MOVES VIA MOUSE BUTTON PRESSES if (input->isKeyDown(MOVE_LEFT_CONTROL) && gsm->isPlayerControlDisabled() == false && dataLoader->getIsPayingCashier() == false) { player->clearPath(); b2Vec2 moveLeft(-PLAYER_SPEED, 0.0f); playerBody->ApplyForceToCenter(moveLeft, true); playerBody->SetTransform(playerBody->GetPosition(), (1.0f * PI)); } else if (input->isKeyDown(MOVE_RIGHT_CONTROL) && gsm->isPlayerControlDisabled() == false && dataLoader->getIsPayingCashier() == false) { player->clearPath(); b2Vec2 moveRight(PLAYER_SPEED, 0.0f); playerBody->ApplyForceToCenter(moveRight, true); playerBody->SetTransform(playerBody->GetPosition(), (0.0f * PI)); } else if (input->isKeyDown(MOVE_UP_CONTROL) && gsm->isPlayerControlDisabled() == false && dataLoader->getIsPayingCashier() == false) { player->clearPath(); b2Vec2 moveUp(0.0f, -PLAYER_SPEED); playerBody->ApplyForceToCenter(moveUp, true); playerBody->SetTransform(playerBody->GetPosition(), (1.5f * PI)); } else if (input->isKeyDown(MOVE_DOWN_CONTROL) && gsm->isPlayerControlDisabled() == false && dataLoader->getIsPayingCashier() == false) { player->clearPath(); b2Vec2 moveDown(0.0f, PLAYER_SPEED); playerBody->ApplyForceToCenter(moveDown, true); playerBody->SetTransform(playerBody->GetPosition(), (0.5f * PI)); } else if (input->isKeyDownForFirstTime(G_KEY)) { viewport->toggleDebugView(); game->getGraphics()->toggleDebugTextShouldBeRendered(); } else if (input->isKeyDownForFirstTime(H_KEY)) { game->getGraphics()->toggleB2DrawDebugShouldBeRendered(); } else { b2Vec2 stay(0.0f, 0.0f); playerBody->ApplyForceToCenter(stay, false); } if (input->isKeyDownForFirstTime(ESC_KEY) && (gsm->isPlayerAtShelf() == true || gsm->isAtItemList() == true)){ gsm->goToGame(); } if (gsm->isPlayerAtShelf() == true){ // LEAVE THE SHELF SCREEN without TAKING ANY ITEMS if (input->isKeyDownForFirstTime(ESC_KEY)){ gsm->goToGame(); } int isItemTaken = false; if (input->isKeyDownForFirstTime(NUM_1) ^ input->isKeyDownForFirstTime(NUMPAD_1)){ isItemTaken = dataLoader->takeItemFromShelf(game, gsm->getGameStateShelfAsNumber(), 1); runScript_LookUpShelfItemInfo(game, gsm->getGameStateShelfAsNumber(), 1, isItemTaken); gsm->goToGame(); } else{ if (input->isKeyDownForFirstTime(NUM_2) ^ input->isKeyDownForFirstTime(NUMPAD_2)){ isItemTaken = dataLoader->takeItemFromShelf(game, gsm->getGameStateShelfAsNumber(), 2); runScript_LookUpShelfItemInfo(game, gsm->getGameStateShelfAsNumber(), 2, isItemTaken); gsm->goToGame(); } else{ if (input->isKeyDownForFirstTime(NUM_3) ^ input->isKeyDownForFirstTime(NUMPAD_3)){ isItemTaken = dataLoader->takeItemFromShelf(game, gsm->getGameStateShelfAsNumber(), 3); runScript_LookUpShelfItemInfo(game, gsm->getGameStateShelfAsNumber(), 3, isItemTaken); gsm->goToGame(); } else{ if (input->isKeyDownForFirstTime(NUM_4) ^ input->isKeyDownForFirstTime(NUMPAD_4)){ isItemTaken = dataLoader->takeItemFromShelf(game, gsm->getGameStateShelfAsNumber(), 4); runScript_LookUpShelfItemInfo(game, gsm->getGameStateShelfAsNumber(), 4, isItemTaken); gsm->goToGame(); } else{ if (input->isKeyDownForFirstTime(NUM_5) ^ input->isKeyDownForFirstTime(NUMPAD_5)){ isItemTaken = dataLoader->takeItemFromShelf(game, gsm->getGameStateShelfAsNumber(), 5); runScript_LookUpShelfItemInfo(game, gsm->getGameStateShelfAsNumber(), 5, isItemTaken); gsm->goToGame(); } else{ if (input->isKeyDownForFirstTime(NUM_6) ^ input->isKeyDownForFirstTime(NUMPAD_6)){ isItemTaken = dataLoader->takeItemFromShelf(game, gsm->getGameStateShelfAsNumber(), 6); runScript_LookUpShelfItemInfo(game, gsm->getGameStateShelfAsNumber(), 6, isItemTaken); gsm->goToGame(); } else{ if (input->isKeyDownForFirstTime(NUM_7) ^ input->isKeyDownForFirstTime(NUMPAD_7)){ isItemTaken = dataLoader->takeItemFromShelf(game, gsm->getGameStateShelfAsNumber(), 7); runScript_LookUpShelfItemInfo(game, gsm->getGameStateShelfAsNumber(), 7, isItemTaken); gsm->goToGame(); } else{ if (input->isKeyDownForFirstTime(NUM_8) ^ input->isKeyDownForFirstTime(NUMPAD_8)){ isItemTaken = dataLoader->takeItemFromShelf(game, gsm->getGameStateShelfAsNumber(), 8); runScript_LookUpShelfItemInfo(game, gsm->getGameStateShelfAsNumber(), 8, isItemTaken); gsm->goToGame(); } else{ //DO NOTHING } } } } } } } } } bool viewportMoved = false; float viewportVx = 0.0f; float viewportVy = 0.0f; if (input->isKeyDown(VIEWPORT_UP_CONTROL) && gsm->isPlayerControlDisabled() == false) { viewportVy -= MAX_VIEWPORT_AXIS_VELOCITY; viewportMoved = true; } if (input->isKeyDown(VIEWPORT_DOWN_CONTROL) && gsm->isPlayerControlDisabled() == false) { viewportVy += MAX_VIEWPORT_AXIS_VELOCITY; viewportMoved = true; } if (input->isKeyDown(VIEWPORT_LEFT_CONTROL) && gsm->isPlayerControlDisabled() == false) { viewportVx -= MAX_VIEWPORT_AXIS_VELOCITY; viewportMoved = true; } if (input->isKeyDown(VIEWPORT_RIGHT_CONTROL) && gsm->isPlayerControlDisabled() == false) { viewportVx += MAX_VIEWPORT_AXIS_VELOCITY; viewportMoved = true; } if (!viewportMoved){ b2Vec2 playerPos = playerBody->GetPosition(); float playerX = playerPos.x * SCALING_FACTOR; float playerY = playerPos.y * SCALING_FACTOR; int SCREEN_WIDTH = 1024; int SCREEN_HEIGHT = 768; if (viewport->getViewportX() + (viewport->getViewportWidth() * 15 / 32) < playerX){ viewportVx += MAX_VIEWPORT_AXIS_VELOCITY * abs(viewport->getViewportX() + (viewport->getViewportWidth() / 2) - playerX) / (SCREEN_WIDTH / 2); viewportMoved = true; } if (viewport->getViewportX() + (viewport->getViewportWidth() * 17 / 32) > playerX){ viewportVx -= MAX_VIEWPORT_AXIS_VELOCITY * abs(viewport->getViewportX() + (viewport->getViewportWidth() / 2) - playerX) / (SCREEN_WIDTH / 2); viewportMoved = true; } if (viewport->getViewportY() + (viewport->getViewportHeight() * 15 / 32) < playerY){ viewportVy += MAX_VIEWPORT_AXIS_VELOCITY * abs(viewport->getViewportY() + (viewport->getViewportHeight() / 2) - playerY) / (SCREEN_HEIGHT / 2); viewportMoved = true; } if (viewport->getViewportY() + (viewport->getViewportHeight() * 17 / 32) > playerY){ viewportVy -= MAX_VIEWPORT_AXIS_VELOCITY * abs(viewport->getViewportY() + (viewport->getViewportHeight() / 2) - playerY) / (SCREEN_HEIGHT / 2); viewportMoved = true; } } //Viewport *viewport = game->getGUI()->getViewport(); if (viewportMoved){ viewport->moveViewport((int)floor(viewportVx + 0.5f), (int)floor(viewportVy + 0.5f), game->getGSM()->getWorld()->getWorldWidth(), game->getGSM()->getWorld()->getWorldHeight()); } /*********** CHEAT CODES LISTED BELOW ******* ************************************************/ // INCREASE TIME REMAINING if (input->isKeyDownForFirstTime(I_KEY)){ runScript_TimeCheat(game, true); }//isIncreasingTime // DECREASE TIME REMAINING if (input->isKeyDownForFirstTime(O_KEY)){ runScript_TimeCheat(game, false); } // INCREASE SPENDING LIMIT if (input->isKeyDownForFirstTime(Y_KEY)){ if ((dataLoader->spendingLimit + MONEY_CHEAT_INCREASE) > (dataLoader->levelItemsCost * 2) + MONEY_CHEAT_INCREASE){ dataLoader->spendingLimit = (dataLoader->levelItemsCost * 2) + MONEY_CHEAT_INCREASE; } else{ dataLoader->spendingLimit += MONEY_CHEAT_INCREASE; } }//isIncreasingSpendingLimit // DECREASE SPENDING LIMIT if (input->isKeyDownForFirstTime(U_KEY)){ if ((dataLoader->spendingLimit - MONEY_CHEAT_DECREASE) < dataLoader->levelItemsCost){ dataLoader->spendingLimit = dataLoader->levelItemsCost; } else{ dataLoader->spendingLimit -= MONEY_CHEAT_DECREASE; } }//isDecreasingSpendingLimit }// BRACKET -- if (gsm->isGameInProgress()) }
/* handleKeyEvent - this method handles all keyboard interactions. Note that every frame this method gets called and it can respond to key interactions in any custom way. Ask the GameInput class for key states since the last frame, which can allow us to respond to key presses, including when keys are held down for multiple frames. */ void SoSKeyEventHandler::handleKeyEvents(Game *game) { // WE CAN QUERY INPUT TO SEE WHAT WAS PRESSED GameInput *input = game->getInput(); // LET'S GET THE PLAYER'S PHYSICAL PROPERTIES, IN CASE WE WANT TO CHANGE THEM GameStateManager *gsm = game->getGSM(); AnimatedSprite *player = gsm->getSpriteManager()->getPlayer(); PhysicalProperties *pp = player->getPhysicalProperties(); if(gsm->isAtSplashScreen()) { if(input->isKeyDown(ENTER_KEY)) { gsm->goToMainMenu(); } } // IF THE GAME IS IN PROGRESS if (gsm->isGameInProgress()) { // CHECK FOR WASD KEYS FOR MOVEMENT int incX = 0; int incY = 0; bool movingLR = false; bool attacking = false; if(!pp->isStunned()) { if(input->isKeyDown(SPACE_KEY)) { attacking = true; if(input->isKeyDownForFirstTime(SPACE_KEY)) { player->setCurrentState(L"ATTACK_STATE"); if(!pp->isOrientedRight()) player->setCurrentState(L"ATTACKL_STATE"); } } // WASD AND DIRECTION KEY PRESSES WILL CONTROL THE PLAYER, // SO WE'LL UPDATE THE PLAYER VELOCITY WHEN THESE KEYS ARE // PRESSED, THAT WAY PHYSICS CAN CORRECT AS NEEDED float vX = pp->getVelocityX(); float vY = pp->getVelocityY(); if (input->isKeyDown(A_KEY) || input->isKeyDown(LEFT_KEY)) { movingLR = true; pp->setOrientedLeft(); vX = -PLAYER_SPEED; if (vY == 0 && player->getCurrentState().compare(L"LEFT_STATE") != 0) player->setCurrentState(L"LEFT_STATE"); else if(vY != 0 && player->getCurrentState().compare(L"JUMPL_STATE") != 0) player->setCurrentState(L"JUMPL_STATE"); } if (input->isKeyDown(D_KEY) || input->isKeyDown(RIGHT_KEY)) { movingLR = true; pp->setOrientedRight(); vX = PLAYER_SPEED; if (vY == 0 && player->getCurrentState().compare(L"RIGHT_STATE") != 0) player->setCurrentState(L"RIGHT_STATE"); else if(vY != 0 && player->getCurrentState().compare(L"JUMP_STATE") != 0) player->setCurrentState(L"JUMP_STATE"); } /*if (input->isKeyDown(S_KEY) || input->isKeyDown(DOWN_KEY)) { vY = PLAYER_SPEED; }*/ if (input->isKeyDown(W_KEY) || input->isKeyDown(UP_KEY)) { if ((input->isKeyDownForFirstTime(W_KEY) || input->isKeyDownForFirstTime(UP_KEY)) && pp->hasDoubleJumped() == false) { if(pp->hasJumped() == true) pp->setDoubleJumped(true); pp->setJumped(true); vY = -PLAYER_SPEED; player->setCurrentState(L"JUMP_STATE"); if(vX < 0) player->setCurrentState(L"JUMPL_STATE"); } } if(!movingLR) { vX = 0; } if(vY == 0 && vX == 0 && !attacking && player->getCurrentState().compare(L"IDLE_STATE") != 0 && player->getCurrentState().compare(L"IDLEL_STATE") != 0 ) { player->setCurrentState(L"IDLE_STATE"); if(!pp->isOrientedRight()) player->setCurrentState(L"IDLEL_STATE"); } // NOW SET THE ACTUAL VELOCITY Physics *physics = gsm->getPhysics(); pp->setVelocitySafely(physics, vX, vY); } // NOTE THAT THE VIEWPORT SHOULD FOLLOW THE PLAYER, AND SO SHOULD BE CORRECTED AFTER PHYSICS // ARE APPLIED. I HAVE PROVIDED A SIMPLE WAY OF DOING SO, WHICH SHOULD BE IMPROVED, DEPENDING // ON THE GAME'S NEED if(input->isKeyDownForFirstTime(TAB_KEY)) { gsm->goToPaused(); } } else if(gsm->isGamePaused() && input->isKeyDownForFirstTime(TAB_KEY)) { gsm->goToGame(); } // 0X43 is HEX FOR THE 'C' VIRTUAL KEY // THIS CHANGES THE CURSOR IMAGE if ((input->isKeyDownForFirstTime(C_KEY)) && input->isKeyDown(VK_SHIFT)) { Cursor *cursor = game->getGUI()->getCursor(); unsigned int id = cursor->getActiveCursorID(); id++; if (id == cursor->getNumCursorIDs()) id = 0; cursor->setActiveCursorID(id); } // LET'S MESS WITH THE TARGET FRAME RATE IF THE USER PRESSES THE HOME OR END KEYS WindowsTimer *timer = (WindowsTimer*)game->getTimer(); int fps = timer->getTargetFPS(); // THIS SPEEDS UP OUR GAME LOOP AND THUS THE GAME, NOTE THAT WE COULD ALTERNATIVELY SCALE // DOWN THE GAME LOGIC (LIKE ALL VELOCITIES) AS WE SPEED UP THE GAME. THAT COULD PROVIDE // A BETTER PLAYER EXPERIENCE if (input->isKeyDown(VK_HOME) && (fps < MAX_FPS)) timer->setTargetFPS(fps + FPS_INC); // THIS SLOWS DOWN OUR GAME LOOP, BUT WILL NOT GO BELOW 5 FRAMES PER SECOND else if (input->isKeyDown(VK_END) && (fps > MIN_FPS)) timer->setTargetFPS(fps - FPS_INC); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { // Init globals from config file Gbls::initFromConfig(); // Create window if(D3DWindow::Create(hInstance)) { //init space if(SUCCEEDED(GameResources::initState())) { ofstream error_f("client_error.log"); cerr.rdbuf(error_f.rdbuf()); GameInput input; GameResources::input = &input; #ifndef MYNETWORKOFF // defined in Gbls //networking init int c_port = DEFAULT_PORT-1; ConfigSettings::config->getValue("network_clientPort", c_port); NetworkClient nc(c_port); int s_port = DEFAULT_PORT; ConfigSettings::config->getValue("network_serverPort", s_port); string server_ip = "127.0.0.1"; ConfigSettings::config->getValue("network_serverIP", server_ip); try { nc.bindToServer(server_ip, (unsigned short) s_port); GameResources::playerNum = nc.getClientID(); } catch (runtime_error &e) { cerr << e.what() << endl; bool exception_occured_check_error_log = false; assert(exception_occured_check_error_log); } #else MessageBox( NULL, L"Network not enabled.\nRecompile with MYNETWORKOFF undefined to enable.", L"CRUSH.exe", MB_OK ); #endif // Main loop MSG msg; //for checking fps //DWORD startTime = timeGetTime(); //DWORD count = 0; GameState<Entity> newGameState; float framesRendered = 0.0f; float updatesReceived = 0.0f; for(;;) // "forever" { input.refreshState(); input.vibrateThrust(input.input.thrust); //for checking fps //count++; //if(!(count%600)) { // DWORD x = count / ((timeGetTime() - startTime)/1000.0); // std::stringstream os; // os << "FPS:" << x; // string s =os.str(); // std::wstring wsTmp(s.begin(), s.end()); // MessageBox( NULL, wsTmp.c_str(), wsTmp.c_str(), MB_OK ); //} #ifndef MYNETWORKOFF // defined in Gbls try { if (!GameResources::debugCamOn) { nc.sendToServer(&(input.input)); } } catch (runtime_error &e) { cerr << e.what() << endl; bool exception_occured_check_error_log = false; assert(exception_occured_check_error_log); } // Get game state from network if(nc.newStateAvailable()) { try{ newGameState = nc.getGameState(); updatesReceived++; } catch (runtime_error &e) { cerr << e.what() << endl; bool exception_occured_check_error_log = false; assert(exception_occured_check_error_log); } } #endif framesRendered++; Gbls::percentMissedFrames = framesRendered - updatesReceived; // Process all pending window messages while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } GameResources::updateGameState(newGameState); // Render if(D3DWindow::Tick()) break; } } } D3DWindow::Destroy(); // See if there's any error messsage pending const std::wstring& strError = D3DWindow::GetError(); if(!strError.empty()) { MessageBox(NULL, strError.c_str(), L"Error", MB_OK | MB_ICONERROR); } return 0; }
void InGameState::Update() { GameInput *gameInput = GameInput::GetGameInput(); //LOGE("%3d%3d%3d%3d\n", posTouch1[I], posTouch1[J], posTouch2[I], posTouch2[J]); if (gameInput->GetPointerState() == POINTER_DOWN && turn) // Ben nguoi choi di { for(int i = 0; i < TOUCH_I * TOUCH_J; i += TOUCH_J) { if (gameInput->pointerX >= touch[i + dX1] && gameInput->pointerX <= touch[i + dX2] && gameInput->pointerY >= touch[i + dY1] && gameInput->pointerY <= touch[i + dY2]) { //printf("%6d%6d\n",touch[i],touch[i+1]); // Luu toa do touch1 cua ma tran if (mapMatrix[touch[i]][touch[i + 1]] == IS_CHESS) { posTouch1[I] = touch[i]; // row posTouch1[J] = touch[i + 1]; // column LOGE("TOUCH 1\n"); } // Luu toa do touch2 cua ma tran else if (posTouch1[I] != NOTHING && mapMatrix[touch[i]][touch[i + 1]] == IS_EMPTY) { posTouch2[I] = touch[i]; posTouch2[J] = touch[i + 1]; LOGE("TOUCH 2\n"); } break; } } } else if (!turn) { // XU LY AI TAI DAY if (posTouch1[I] == NOTHING) { this->SearchBestPath(); } } // Kich hoat duong di sau khi da tim duoc duong if (posTouch1[I] != NOTHING && posTouch1[J] != NOTHING && posTouch2[I] != NOTHING && posTouch2[J] != NOTHING) { for(interator = scene->models.begin(); interator != scene->models.end(); interator++) { if((*interator)->position.x == (float)(posTouch1[J] * STEP) && (*interator)->position.z == (float)(posTouch1[I] * STEP) && ((*interator)->typeObject == IS_CHESS || (*interator)->typeObject == IS_CHESS_AI) && ((*interator)->IsLeft() || (*interator)->IsRight() || (*interator)->IsUp() || (*interator)->IsDown() || (*interator)->IsLeftUp() || (*interator)->IsLeftDown() || (*interator)->IsRightDown() || (*interator)->IsRightUp())) { (*interator)->activation = true; break; } } } /*if(posTouch1[I] != -1 && posTouch2[I] != -1) { printf("%6d%6d\n%6d%6d\n\n", posTouch1[I], posTouch1[J], posTouch2[I], posTouch2[J]); }*/ // Xu ly an quan khi bi het duong di bool haveway; for(int i = 0; i < ROW; i++) { for(int j = 0; j < COLUMN; j++) { if (mapMatrix[i][j] == IS_CHESS_AI) { haveway = false; NoWayIsDead(i, j, IS_CHESS_AI, haveway); //LOGE("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA %3d%3d%3d\n", haveway, i, j); ChangeChess(haveway); } else if (mapMatrix[i][j] == IS_CHESS) { haveway = false; NoWayIsDead(i, j, IS_CHESS, haveway); //LOGE("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB %d\n", haveway); ChangeChess(haveway); } leave = true; } } if (dragone && gameInput->GetPointerState() == POINTER_DRAGGED) { direction++; if (direction == 12) { direction = 0; } if (direction == 0) { dragone = false; camera.position.x = 6; camera.position.y = 30; camera.position.z = 18; camera.rotation.x = -75; loadData->LoadTouch(touch, TOUCH_I, TOUCH_J); } else if (direction == 11) { dragone = false; camera.position.x = 10; camera.position.y = 30; camera.position.z = 10; camera.rotation.x = -90; loadData->LoadTouch2(touch, TOUCH_I, TOUCH_J); } } if (gameInput->GetPointerState() == POINTER_UP && !dragone) { dragone = true; } if (count == 0) { application->SetState(new MainMenuState()); } if ( gameInput->GetPointerState() == POINTER_DOWN ) { if((gameInput->pointerX >= 698) && (gameInput->pointerX <= 786) && (gameInput->pointerY >= 11) && (gameInput->pointerY <= 66)) { //pause game pauseState = true; application->SetState(new InGameMenuState()); } } }
/* handleKeyEvent - this method handles all keyboard interactions. Note that every frame this method gets called and it can respond to key interactions in any custom way. Ask the GameInput class for key states since the last frame, which can allow us to respond to key presses, including when keys are held down for multiple frames. */ void BugginOutKeyEventHandler::handleKeyEvents(Game *game) { // WE CAN QUERY INPUT TO SEE WHAT WAS PRESSED GameInput *input = game->getInput(); // LET'S GET THE PLAYER'S PHYSICAL PROPERTIES, IN CASE WE WANT TO CHANGE THEM GameStateManager *gsm = game->getGSM(); AnimatedSprite *player = gsm->getSpriteManager()->getPlayer(); list<AnimatedSprite*>::iterator blocks; PhysicalProperties *pp = player->getPhysicalProperties(); Viewport *viewport = game->getGUI()->getViewport(); // IF THE GAME IS IN PROGRESS if (gsm->isGameInProgress()) { Physics *phy = game->getGSM()->getPhysics(); // WASD KEY PRESSES WILL CONTROL THE PLAYER // SO WE'LL UPDATE THE PLAYER VELOCITY WHEN THESE KEYS ARE // PRESSED, THAT WAY PHYSICS CAN CORRECT AS NEEDED float vX = pp->getVelocityX(); float vY = pp->getVelocityY(); // YOU MIGHT WANT TO UNCOMMENT THIS FOR SOME TESTING, b2Body *body = player->body; if (game->getGSM()->levelSwitchTrigger == true) { game->quitGame(); if (game->getCurrentLevelFileName() == W_LEVEL_1_NAME) game->setCurrentLevelFileName(W_LEVEL_2_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_2_NAME) game->setCurrentLevelFileName(W_LEVEL_3_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_3_NAME) game->setCurrentLevelFileName(W_LEVEL_4_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_4_NAME) game->setCurrentLevelFileName(W_LEVEL_5_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_5_NAME) game->setCurrentLevelFileName(W_LEVEL_6_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_6_NAME) game->setCurrentLevelFileName(W_LEVEL_7_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_7_NAME) game->setCurrentLevelFileName(W_LEVEL_8_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_8_NAME) game->setCurrentLevelFileName(W_LEVEL_9_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_9_NAME) game->setCurrentLevelFileName(W_LEVEL_10_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_10_NAME) game->setCurrentLevelFileName(W_LEVEL_1_NAME); game->startGame(); game->getGSM()->levelSwitchTrigger = false; } if (game->getGSM()->levelResetTrigger == true) { game->quitGame(); if (game->getCurrentLevelFileName() == W_LEVEL_1_NAME) game->setCurrentLevelFileName(W_LEVEL_1_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_2_NAME) game->setCurrentLevelFileName(W_LEVEL_2_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_3_NAME) game->setCurrentLevelFileName(W_LEVEL_3_NAME); else if (game->getCurrentLevelFileName() == W_LEVEL_4_NAME) game->setCurrentLevelFileName(W_LEVEL_4_NAME); game->startGame(); game->getGSM()->levelResetTrigger = false; } if (input->isKeyDown('1')){ game->quitGame(); game->setCurrentLevelFileName(W_LEVEL_1_NAME); game->startGame(); //game->getGSM()->unloadCurrentLevel(); //game->getGSM()->loadLevel(game, W_LEVEL_1_DIR + W_LEVEL_1_NAME); /*game->setCurrentLevelFileName(W_LEVEL_1_NAME); game->startGame();*/ } else if (input->isKeyDown('2')){ game->quitGame(); game->setCurrentLevelFileName(W_LEVEL_2_NAME); game->startGame(); //game->getGSM()->unloadCurrentLevel(); //game->getGSM()->loadLevel(game, W_LEVEL_1_DIR + W_LEVEL_2_NAME); } else if (input->isKeyDown('3')){ game->quitGame(); game->setCurrentLevelFileName(W_LEVEL_3_NAME); game->startGame(); //game->getGSM()->unloadCurrentLevel(); //game->getGSM()->loadLevel(game, W_LEVEL_1_DIR + W_LEVEL_3_NAME); } else if (input->isKeyDown('4')) { game->quitGame(); game->setCurrentLevelFileName(W_LEVEL_4_NAME); game->startGame(); //game->getGSM()->unloadCurrentLevel(); //game->getGSM()->loadLevel(game, W_LEVEL_1_DIR + W_LEVEL_4_NAME); } else if (input->isKeyDown('5')) { game->quitGame(); game->setCurrentLevelFileName(W_LEVEL_5_NAME); game->startGame(); //game->getGSM()->unloadCurrentLevel(); //game->getGSM()->loadLevel(game, W_LEVEL_1_DIR + W_LEVEL_4_NAME); } else if (input->isKeyDown('6')) { game->quitGame(); game->setCurrentLevelFileName(W_LEVEL_6_NAME); game->startGame(); //game->getGSM()->unloadCurrentLevel(); //game->getGSM()->loadLevel(game, W_LEVEL_1_DIR + W_LEVEL_4_NAME); } else if (input->isKeyDown('7')) { game->quitGame(); game->setCurrentLevelFileName(W_LEVEL_7_NAME); game->startGame(); //game->getGSM()->unloadCurrentLevel(); //game->getGSM()->loadLevel(game, W_LEVEL_1_DIR + W_LEVEL_4_NAME); } else if (input->isKeyDown('8')) { game->quitGame(); game->setCurrentLevelFileName(W_LEVEL_8_NAME); game->startGame(); //game->getGSM()->unloadCurrentLevel(); //game->getGSM()->loadLevel(game, W_LEVEL_1_DIR + W_LEVEL_4_NAME); } else if (input->isKeyDown('9')) { game->quitGame(); game->setCurrentLevelFileName(W_LEVEL_9_NAME); game->startGame(); //game->getGSM()->unloadCurrentLevel(); //game->getGSM()->loadLevel(game, W_LEVEL_1_DIR + W_LEVEL_4_NAME); } else if (input->isKeyDown('0')) { game->quitGame(); game->setCurrentLevelFileName(W_LEVEL_10_NAME); game->startGame(); //game->getGSM()->unloadCurrentLevel(); //game->getGSM()->loadLevel(game, W_LEVEL_1_DIR + W_LEVEL_4_NAME); } else if (input->isKeyDown(A_KEY)) { if (player->dead == false) { pp->facing = 1; if ((phy->CurrentGrav == phy->Normal_Grav || phy->CurrentGrav == phy->Reverse_Grav)) { if (player->onGround()) body->ApplyForce(b2Vec2(body->GetMass() * -0.1 / (1 / 60.0), 0), body->GetWorldCenter(), true); else body->ApplyForce(b2Vec2(body->GetMass() * -0.1 / (1 / 60.0), 0), body->GetWorldCenter(), true); } if ((phy->CurrentGrav == phy->Left_Grav || phy->CurrentGrav == phy->Right_Grav)) { if (player->onGround()) body->ApplyForce(b2Vec2(0, body->GetMass() * -0.1 / (1 / 60.0)), body->GetWorldCenter(), true); else body->ApplyForce(b2Vec2(0, body->GetMass() * -0.1 / (1 / 60.0)), body->GetWorldCenter(), true); } if (player->onGround()) { if (phy->CurrentGrav == phy->Normal_Grav) player->setCurrentState(LWALK); else if (phy->CurrentGrav == phy->Reverse_Grav) player->setCurrentState(ULWALK); else if (phy->CurrentGrav == phy->Right_Grav) player->setCurrentState(RLWALK); else if (phy->CurrentGrav == phy->Left_Grav) player->setCurrentState(LLWALK); } else { if (phy->CurrentGrav == phy->Normal_Grav) player->setCurrentState(LFALL); else if (phy->CurrentGrav == phy->Reverse_Grav) player->setCurrentState(ULFALL); else if (phy->CurrentGrav == phy->Right_Grav) player->setCurrentState(RLFALL); else if (phy->CurrentGrav == phy->Left_Grav) player->setCurrentState(LLFALL); } } } else if (input->isKeyDown(D_KEY)) { if (player->dead == false) { pp->facing = 0; if ((phy->CurrentGrav == phy->Normal_Grav || phy->CurrentGrav == phy->Reverse_Grav)) { if (player->onGround()) body->ApplyForce(b2Vec2(body->GetMass() * 0.1 / (1 / 60.0), 0), body->GetWorldCenter(), true); else body->ApplyForce(b2Vec2(body->GetMass() * 0.1 / (1 / 60.0), 0), body->GetWorldCenter(), true); } if ((phy->CurrentGrav == phy->Left_Grav || phy->CurrentGrav == phy->Right_Grav)) { if (player->onGround()) body->ApplyForce(b2Vec2(0, body->GetMass() * 0.1 / (1 / 60.0)), body->GetWorldCenter(), true); else body->ApplyForce(b2Vec2(0, body->GetMass() * 0.1 / (1 / 60.0)), body->GetWorldCenter(), true); } if (player->onGround()) { if (phy->CurrentGrav == phy->Normal_Grav) player->setCurrentState(RWALK); else if (phy->CurrentGrav == phy->Reverse_Grav) player->setCurrentState(URWALK); else if (phy->CurrentGrav == phy->Right_Grav) player->setCurrentState(RRWALK); else if (phy->CurrentGrav == phy->Left_Grav) player->setCurrentState(LRWALK); } else { if (phy->CurrentGrav == phy->Normal_Grav) player->setCurrentState(RFALL); else if (phy->CurrentGrav == phy->Reverse_Grav) player->setCurrentState(URFALL); else if (phy->CurrentGrav == phy->Right_Grav) player->setCurrentState(RRFALL); else if (phy->CurrentGrav == phy->Left_Grav) player->setCurrentState(LRFALL); } } } else if (input->isKeyDownForFirstTime(G_KEY)) { /*((BugginOutDataLoader*)game->getDataLoader())->remotePlaySound(((BugginOutDataLoader*)game->getDataLoader())->gravSound); b2World *world = game->getGSM()->getPhysics()->getBoxWorld(); if (phy->CurrentGrav == phy->Normal_Grav) { player->body->SetTransform(player->body->GetPosition(), 0.0f); blocks = gsm->getSpriteManager()->getBlocksIterator(); while (blocks != gsm->getSpriteManager()->getEndOfBlocksIterator()) { (*blocks)->body->SetGravityScale(1); blocks++; } world->SetGravity(phy->Reverse_Grav); phy->CurrentGrav = phy->Reverse_Grav; } else if (phy->CurrentGrav == phy->Reverse_Grav) { player->body->SetTransform(player->body->GetPosition(), 270.0f); blocks = gsm->getSpriteManager()->getBlocksIterator(); while (blocks != gsm->getSpriteManager()->getEndOfBlocksIterator()) { (*blocks)->body->SetGravityScale(0); blocks++; } world->SetGravity(phy->Left_Grav); phy->CurrentGrav = phy->Left_Grav; } else if (phy->CurrentGrav == phy->Left_Grav) { player->body->SetTransform(player->body->GetPosition(), 270.0f); blocks = gsm->getSpriteManager()->getBlocksIterator(); while (blocks != gsm->getSpriteManager()->getEndOfBlocksIterator()) { (*blocks)->body->SetGravityScale(0); blocks++; } world->SetGravity(phy->Right_Grav); phy->CurrentGrav = phy->Right_Grav; } else if (phy->CurrentGrav == phy->Right_Grav) { player->body->SetTransform(player->body->GetPosition(), 0.0f); blocks = gsm->getSpriteManager()->getBlocksIterator(); while (blocks != gsm->getSpriteManager()->getEndOfBlocksIterator()) { (*blocks)->body->SetGravityScale(1); blocks++; } world->SetGravity(phy->Normal_Grav); phy->CurrentGrav = phy->Normal_Grav; } player->setGrounded(false);*/ } else if (player->onGround()) { if (player->dead == false) { if (pp->facing == 0) { if (phy->CurrentGrav == phy->Normal_Grav) player->setCurrentState(RIDLE); else if (phy->CurrentGrav == phy->Reverse_Grav) player->setCurrentState(URIDLE); else if (phy->CurrentGrav == phy->Right_Grav) player->setCurrentState(RRIDLE); else if (phy->CurrentGrav == phy->Left_Grav) player->setCurrentState(LRIDLE); } else { if (phy->CurrentGrav == phy->Normal_Grav) player->setCurrentState(LIDLE); else if (phy->CurrentGrav == phy->Reverse_Grav) player->setCurrentState(ULIDLE); else if (phy->CurrentGrav == phy->Right_Grav) player->setCurrentState(RLIDLE); else if (phy->CurrentGrav == phy->Left_Grav) player->setCurrentState(LLIDLE); } } else { if (player->getCurrentState() != L"LDEATH") { if (pp->facing == 0){ if (phy->CurrentGrav == phy->Normal_Grav) player->setCurrentState(RFALL); else if (phy->CurrentGrav == phy->Reverse_Grav) player->setCurrentState(URFALL); else if (phy->CurrentGrav == phy->Right_Grav) player->setCurrentState(RRFALL); else if (phy->CurrentGrav == phy->Left_Grav) player->setCurrentState(LRFALL); } else{ if (phy->CurrentGrav == phy->Normal_Grav) player->setCurrentState(LFALL); else if (phy->CurrentGrav == phy->Reverse_Grav) player->setCurrentState(ULFALL); else if (phy->CurrentGrav == phy->Right_Grav) player->setCurrentState(RLFALL); else if (phy->CurrentGrav == phy->Left_Grav) player->setCurrentState(LLFALL); } } } } if (input->isKeyDownForFirstTime(SPACE_KEY) && player->onGround() && player->dead == false) { ((BugginOutDataLoader*)game->getDataLoader())->remotePlaySound(((BugginOutDataLoader*)game->getDataLoader())->jumpSound); //float mass = body->GetMass(); float impulse = 3.0f; if (phy->CurrentGrav == phy->Normal_Grav) { body->SetLinearVelocity(b2Vec2(body->GetLinearVelocity().x, -impulse)); } if (phy->CurrentGrav == phy->Reverse_Grav) { body->SetLinearVelocity(b2Vec2(body->GetLinearVelocity().x, impulse)); } if (phy->CurrentGrav == phy->Right_Grav) { body->SetLinearVelocity(b2Vec2(-impulse, body->GetLinearVelocity().y)); } if (phy->CurrentGrav == phy->Left_Grav) { body->SetLinearVelocity(b2Vec2(impulse, body->GetLinearVelocity().y)); } if (pp->facing == 0) { if (phy->CurrentGrav == phy->Normal_Grav) player->setCurrentState(RJUMP); else if (phy->CurrentGrav == phy->Reverse_Grav) player->setCurrentState(URJUMP); else if (phy->CurrentGrav == phy->Right_Grav) player->setCurrentState(RRJUMP); else if (phy->CurrentGrav == phy->Left_Grav) player->setCurrentState(LRJUMP); } else { if (phy->CurrentGrav == phy->Normal_Grav) player->setCurrentState(LJUMP); else if (phy->CurrentGrav == phy->Reverse_Grav) player->setCurrentState(ULJUMP); else if (phy->CurrentGrav == phy->Right_Grav) player->setCurrentState(RLJUMP); else if (phy->CurrentGrav == phy->Left_Grav) player->setCurrentState(LLJUMP); } player->setGrounded(false); } if (input->isKeyDownForFirstTime(P_KEY)) { game->getGSM()->getPhysics()->activated = !(game->getGSM()->getPhysics()->activated); } if (input->isKeyDownForFirstTime(R_KEY)) { game->getGSM()->levelResetTrigger = true; } // NOW SET THE ACTUAL PLAYER VELOCITY pp->setVelocity(vX, vY); // 0X43 is HEX FOR THE 'C' VIRTUAL KEY // THIS CHANGES THE CURSOR IMAGE if ((input->isKeyDownForFirstTime(C_KEY)) && input->isKeyDown(VK_SHIFT)) { Cursor *cursor = game->getGUI()->getCursor(); unsigned int id = cursor->getActiveCursorID(); id++; if (id == cursor->getNumCursorIDs()) id = 0; cursor->setActiveCursorID(id); } // LET'S MESS WITH THE TARGET FRAME RATE IF THE USER PRESSES THE HOME OR END KEYS WindowsTimer *timer = (WindowsTimer*)game->getTimer(); int fps = timer->getTargetFPS(); // THIS SPEEDS UP OUR GAME LOOP AND THUS THE GAME, NOTE THAT WE COULD ALTERNATIVELY SCALE // DOWN THE GAME LOGIC (LIKE ALL VELOCITIES) AS WE SPEED UP THE GAME. THAT COULD PROVIDE // A BETTER PLAYER EXPERIENCE if (input->isKeyDown(VK_HOME) && (fps < MAX_FPS)) timer->setTargetFPS(fps + FPS_INC); // THIS SLOWS DOWN OUR GAME LOOP, BUT WILL NOT GO BELOW 5 FRAMES PER SECOND else if (input->isKeyDown(VK_END) && (fps > MIN_FPS)) timer->setTargetFPS(fps - FPS_INC); } }
int SessionController::launch(Character &character, Interface &interface) { //Initialization Map map = SaveUtils::loadMap(character.getName(), character.getMap()); SessionScreen sessionScreen; character.checkView(map); sessionScreen.display(character, interface, map); GameInput input; //Game Loop while (input.getValue() != CLOSE_INPUT) { //To know if we have to count the current turn. bool played = false; //To know if we have to refresh the screen. bool toRefresh = true; //To know if the player have changed his position. bool moved = false; input = sessionScreen.recupInput(); switch (input.getValue()) { moved = false; //Quit Game case ESCAPE_INPUT : { interface.write("Return to the menu (y or n)?"); sessionScreen.display(character, interface, map); GameInput tmpInput; int tmpValue; do { tmpInput = sessionScreen.recupInput(); tmpValue = tmpInput.getValue(); } while ((tmpValue != N_INPUT) && (tmpValue != Y_INPUT)); if (tmpValue == N_INPUT) interface.write("Okay then."); else { SaveUtils::save(character, interface); SaveUtils::saveMap(character.getName(), character.getMap(), map); return TO_MAIN_MENU; } break; } //Display Map case M_INPUT : { MapController mapController(map, character); input.setValue(mapController.launch(map, character)); break; } //Display Inventory case I_INPUT : { InventoryController inventoryController; input.setValue(inventoryController.launch(character)); break; } //Pick Item case P_INPUT : { /*if (map.cell[character.getX()][character.getY()].drops.empty()) interface.write("There's nothing here."); else { //character.equipement.legs = &map.cell[character.getX()][character.getY()].drops.front(); }*/ break; } //Change map case Q_INPUT : { if (changeMap(character, map, interface)) { SaveUtils::save(character, interface); return REDO; } else interface.write("You cannot exit from here !"); break; } //Moving inputs case UP_INPUT : { moved = character.move(0,-1,map); played = true; break; } case DOWN_INPUT : { moved = character.move(0,1,map); played = true; break; } case RIGHT_INPUT : { moved = character.move(1,0,map); played = true; break; } case LEFT_INPUT : { moved = character.move(-1,0,map); played = true; break; } default: toRefresh = false; } if (moved) { interface.showItems(map.cell[character.getX()][character.getY()]); interface.showDestination(map.cell[character.getX()][character.getY()]); } if (played) { map.refreshCells(character.getX(), character.getY()); character.checkView(map); } if (toRefresh) sessionScreen.display(character, interface, map); } SaveUtils::save(character, interface); SaveUtils::saveMap(character.getName(), character.getMap(), map); return CLOSE_INPUT; }