void IngameState::handlePlayerInput(const sf::Event& event) { auto player = game->getPlayer(); switch(event.type) { case sf::Event::KeyPressed: switch(event.key.code) { case sf::Keyboard::Space: if( player->getCharacter()->getCurrentVehicle() ) { player->getCharacter()->getCurrentVehicle()->setHandbraking(true); } else { player->jump(); } break; case sf::Keyboard::LShift: player->setRunning(true); break; case sf::Keyboard::F: if( player->getCharacter()->getCurrentVehicle()) { player->exitVehicle(); } else { player->enterNearestVehicle(); } break; default: break; } break; case sf::Event::KeyReleased: switch(event.key.code) { case sf::Keyboard::LShift: player->setRunning(false); break; default: break; } break; case sf::Event::MouseButtonPressed: switch(event.mouseButton.button) { case sf::Mouse::Left: player->getCharacter()->useItem(true, true); break; default: break; } break; case sf::Event::MouseButtonReleased: switch(event.mouseButton.button) { case sf::Mouse::Left: player->getCharacter()->useItem(false, true); break; default: break; } break; case sf::Event::MouseWheelMoved: player->getCharacter()->cycleInventory(event.mouseWheel.delta > 0); break; default: break; } }
void IngameState::handlePlayerInput(const SDL_Event& event) { auto player = game->getPlayer(); switch(event.type) { case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_SPACE: if( player->getCharacter()->getCurrentVehicle() ) { player->getCharacter()->getCurrentVehicle()->setHandbraking(true); } else { player->jump(); } break; case SDLK_f: if( player->getCharacter()->getCurrentVehicle()) { player->exitVehicle(); } else if (player->isCurrentActivity( Activities::EnterVehicle::ActivityName)) { // Give up entering a vehicle if we're alreadying doing so player->skipActivity(); } else { player->enterNearestVehicle(); } break; case SDLK_LSHIFT: player->setRunning(true); break; default: break; } break; case SDL_KEYUP: switch (event.key.keysym.sym) { case SDLK_LSHIFT: player->setRunning(false); break; default: break; } break; case SDL_MOUSEBUTTONDOWN: switch(event.button.button) { case SDL_BUTTON_LEFT: player->getCharacter()->useItem(true, true); break; default: break; } break; case SDL_MOUSEBUTTONUP: switch(event.button.button) { case SDL_BUTTON_LEFT: player->getCharacter()->useItem(false, true); break; default: break; } break; case SDL_MOUSEWHEEL: player->getCharacter()->cycleInventory(event.wheel.y > 0); break; case SDL_MOUSEMOTION: if (game->hasFocus()) { glm::ivec2 screenSize = getWindow().getSize(); glm::vec2 mouseMove(event.motion.xrel / static_cast<float>(screenSize.x), event.motion.yrel / static_cast<float>(screenSize.y)); autolookTimer = kAutoLookTime; if (!m_invertedY) { mouseMove.y = -mouseMove.y; } m_cameraAngles += glm::vec2(mouseMove.x, mouseMove.y); m_cameraAngles.y = glm::clamp(m_cameraAngles.y, kCameraPitchLimit, glm::pi<float>() - kCameraPitchLimit); } break; default: break; } }