/* client/input.h This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ #include "client/client.h" #include "client/input.h" #include "client/console.h" #include "client/camera.h" #include "client/keyboard.h" #include "SDL/SDL.h" namespace client { namespace input { void init() { con_print << "Initializing input..." << std::endl; client::setkeyboardmode(console::visible()); } void shutdown() { con_print << "Shutting down input..." << std::endl; } // handle pressed keys for the game world void keypressed(const SDL_keysym &keysym) { switch( keysym.sym) { case SDLK_SPACE: camera::nextmode(); 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: // TODO set core entity params game.ship.set_thrust(game.ship.thrust() + 0.08f); break; case SDLK_KP_MINUS: // TODO set core entity params game.ship.set_thrust(game.ship.thrust() - 0.1f); break; case SDLK_KP4: // TODO set core entity params game.ship.set_yaw(game.ship.yaw() + 10); break; case SDLK_KP6: // TODO set core entity params game.ship.set_yaw(game.ship.yaw() - 10); break; default: break; } } void frame(float seconds) { SDL_Event event; while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: /*if (event.key.keysym.sym == SDLK_ESCAPE) { client::application.shutdown(); } else */ if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') { console::toggle(); } else if (console::visible()) { // send key events to the console console::keypressed(event.key.keysym ); } else if (core::connected()) { // send key events to the game world keypressed(event.key.keysym ); } break; case SDL_KEYUP: break; case SDL_QUIT: core::application()->shutdown(); break; } } } } // namespace input } // namespace client