/* input.cc This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ //project headers #include "client.h" #include "game/game.h" namespace client { void Input::init() { //condebug << "SDL_DEFAULT_REPEAT_DELAY " << SDL_DEFAULT_REPEAT_DELAY << std::endl; //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL); } void Input::shutdown() { } /* see http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdlevent.html */ // handle key_release events void Input::handle_keyreleased(SDL_keysym* keysym) { switch( keysym->sym ) { case SDLK_SPACE: camera.nextmode(); break; default: break; } } // handle pressed keys void Input::handle_keypressed(SDL_keysym* keysym) { switch( keysym->sym ) { case SDLK_ESCAPE: client::shutdown(); break; case SDLK_LEFT: camera.rotate_left(); break; case SDLK_RIGHT: camera.rotate_right(); break; case SDLK_UP: camera.rotate_up(); break; case SDLK_DOWN: camera.rotate_down(); break; case SDLK_KP_PLUS: game::ship.set_thrust(game::ship.thrust() + 0.08f); break; case SDLK_KP_MINUS: game::ship.set_thrust(game::ship.thrust() - 0.1f); break; case SDLK_KP4: game::ship.set_yaw(game::ship.yaw() + 10); break; case SDLK_KP6: game::ship.set_yaw(game::ship.yaw() - 10); break; default: break; } } void Input::process() { SDL_Event event; while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: handle_keypressed( &event.key.keysym ); break; case SDL_KEYUP: handle_keyreleased( &event.key.keysym ); break; case SDL_QUIT: client::shutdown(); break; } } } } // namespace client