source: trunk/src/input.cpp @ 221

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

Complete Lol Engine / Deus Hax / Monsterz split.

  • Property svn:keywords set to Id
File size: 1.1 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <SDL.h>
16
17#include <cstdio>
18#include <cstdlib>
19#include <cmath>
20
21#include "core.h"
22
23/*
24 * Input implementation class
25 */
26
27static class InputData
28{
29    friend class Input;
30
31public:
32    int dummy;
33}
34inputdata;
35
36static InputData * const data = &inputdata;
37
38/*
39 * Public Input class
40 */
41
42Float2 Input::GetAxis(int axis)
43{
44    float invsqrt2 = sqrtf(0.5f);
45    Float2 f;
46
47    /* Simulate a joystick using the keyboard. This SDL call is free. */
48    Uint8 *keystate = SDL_GetKeyState(NULL);
49    int left = keystate[SDLK_d] - (keystate[SDLK_a] | keystate[SDLK_q]);
50    int up = (keystate[SDLK_w] | keystate[SDLK_z]) - keystate[SDLK_s] ;
51    f.x += left;
52    f.y += up;
53    if (left && up)
54    {
55        f.x *= invsqrt2;
56        f.y *= invsqrt2;
57    }
58
59    return f;
60}
61
Note: See TracBrowser for help on using the repository browser.