source: trunk/src/input.cpp @ 176

Last change on this file since 176 was 176, checked in by sam, 10 years ago

Switch from esdf controls to wasd, but support qwerty and azerty keyboards.

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