source: trunk/src/input.cpp @ 150

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

Replace mouse scrolling with a joystick simulated by the e/s/d/f keys.

  • Property svn:keywords set to Id
File size: 926 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    f.y -= keystate[SDLK_e];
45    f.y += keystate[SDLK_d];
46    f.x -= keystate[SDLK_s];
47    f.x += keystate[SDLK_f];
48    if (keystate[SDLK_e] + keystate[SDLK_d]
49         == keystate[SDLK_s] + keystate[SDLK_f])
50    {
51        f.x *= invsqrt2;
52        f.y *= invsqrt2;
53    }
54
55    return f;
56}
57
Note: See TracBrowser for help on using the repository browser.