Include and link physfs properly.
[tuxanci.git] / src / client / control.c
blobbfc2428cbf2ad2eb4d97596c71ccefec02313030
1 #include <SDL.h>
2 #include <limits.h>
3 #include <assert.h>
5 #include "main.h"
6 #include "control.h"
8 control_t *control_new(SDLKey arg_up, SDLKey arg_right, SDLKey arg_left,
9 SDLKey arg_down, SDLKey arg_shot, SDLKey arg_switch)
11 control_t *tmp;
13 tmp = malloc(sizeof(control_t));
14 memset(tmp, 0, sizeof(control_t));
15 tmp->key[CONTROL_UP] = arg_up;
16 tmp->key[CONTROL_RIGHT] = arg_right;
17 tmp->key[CONTROL_LEFT] = arg_left;
18 tmp->key[CONTROL_DOWN] = arg_down;
19 tmp->key[CONTROL_SHOT] = arg_shot;
20 tmp->key[CONTROL_SWITCH] = arg_switch;
22 return tmp;
25 int control_get_key_route(control_t *my_control)
27 Uint8 *map;
28 SDLKey ret_key;
29 int z;
30 int i;
32 assert(my_control != NULL);
34 ret_key = CONTROL_NONE;
36 map = SDL_GetKeyState(NULL);
38 for (i = 0; i < CONTROL_KEY_COUNT_ROUTE; i++) {
39 if (map[my_control->key[i]] == SDL_PRESSED) {
40 my_control->count[i]++;
41 } else {
42 my_control->count[i] = 0;
46 z = INT_MAX;
48 for (i = 0; i < CONTROL_KEY_COUNT_ROUTE; i++) {
49 if (my_control->count[i] > 0 &&
50 my_control->count[i] < z &&
51 map[my_control->key[i]] == SDL_PRESSED) {
52 z = my_control->count[i];
53 ret_key = i;
57 return ret_key;
60 int control_get_key_action(control_t *my_control)
62 Uint8 *map;
64 assert(my_control != NULL);
66 map = SDL_GetKeyState(NULL);
68 if (map[my_control->key[CONTROL_SHOT]] == SDL_PRESSED) {
69 return CONTROL_SHOT;
72 if (map[my_control->key[CONTROL_SWITCH]] == SDL_PRESSED) {
73 return CONTROL_SWITCH;
76 return CONTROL_NONE;
79 void control_destroy(control_t *my_control)
81 assert(my_control != NULL);
83 free(my_control);