Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

57 lignes
914 B

  1. //
  2. // Deus Hax (working title)
  3. // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
  4. //
  5. #if defined HAVE_CONFIG_H
  6. # include "config.h"
  7. #endif
  8. #include <SDL.h>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cmath>
  12. #include "core.h"
  13. /*
  14. * Input implementation class
  15. */
  16. static class InputData
  17. {
  18. friend class Input;
  19. public:
  20. int dummy;
  21. }
  22. inputdata;
  23. static InputData * const data = &inputdata;
  24. /*
  25. * Public Input class
  26. */
  27. Float2 Input::GetAxis(int axis)
  28. {
  29. float invsqrt2 = sqrtf(0.5f);
  30. Float2 f;
  31. /* Simulate a joystick using the keyboard. This SDL call is free. */
  32. Uint8 *keystate = SDL_GetKeyState(NULL);
  33. int left = keystate[SDLK_d] - (keystate[SDLK_a] | keystate[SDLK_q]);
  34. int up = (keystate[SDLK_w] | keystate[SDLK_z]) - keystate[SDLK_s] ;
  35. f.x += left;
  36. f.y += up;
  37. if (left && up)
  38. {
  39. f.x *= invsqrt2;
  40. f.y *= invsqrt2;
  41. }
  42. return f;
  43. }