File: input.c

package info (click to toggle)
stax 1.0-13
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 836 kB
  • ctags: 258
  • sloc: ansic: 3,209; makefile: 56; sh: 2
file content (64 lines) | stat: -rw-r--r-- 1,527 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <allegro.h>
#include "stax.h"

static void get_input_kb1(Input *input, int input_type, int timer_tick)
{
	poll_keyboard();

	input->left = key[KEY_A];
	input->right = key[KEY_D];
	input->up = key[KEY_W];
	input->down = key[KEY_S];
	input->button = key[KEY_SPACE];
}

static void get_input_kb2(Input *input, int input_type, int timer_tick)
{
	poll_keyboard();

	input->left = key[KEY_LEFT];
	input->right = key[KEY_RIGHT];
	input->up = key[KEY_UP];
	input->down = key[KEY_DOWN];
	input->button = key[KEY_RCONTROL];
}

static void get_input_joy1(Input *input, int input_type, int timer_tick)
{
	poll_joystick();

	input->left = joy[0].stick[0].axis[0].d1;
	input->right = joy[0].stick[0].axis[0].d2;
	input->up = joy[0].stick[0].axis[1].d1;
	input->down = joy[0].stick[0].axis[1].d2;
	input->button = joy[0].button[0].b;
}

static void get_input_joy2(Input *input, int input_type, int timer_tick)
{
	poll_joystick();

	input->left = joy[1].stick[0].axis[0].d1;
	input->right = joy[1].stick[0].axis[0].d2;
	input->up = joy[1].stick[0].axis[1].d1;
	input->down = joy[1].stick[0].axis[1].d2;
	input->button = joy[1].button[0].b;
}

void get_input(Input *input, int input_type, int timer_tick)
{
	switch (input_type) {
	case INPUT_KB1:
		get_input_kb1(input, input_type, timer_tick);
		break;
	case INPUT_KB2:
		get_input_kb2(input, input_type, timer_tick);
		break;
	case INPUT_JOY1:
		get_input_joy1(input, input_type, timer_tick);
		break;
	case INPUT_JOY2:
		get_input_joy2(input, input_type, timer_tick);
		break;
	}
}