aboutsummaryrefslogtreecommitdiff
path: root/src/controller.c
blob: cacada366fdb868041e64e53da7aa48177e2cede (plain)
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
#include "controller.h"

#include <raylib.h>

b32 is_button_pressed(i32 btn)
{
	return IsKeyPressed(btn);
}

b32 is_button_held(i32 btn)
{
	return IsKeyDown(btn);
}

b32 is_button_released(i32 btn)
{
	return IsKeyReleased(btn);
}

vec2 get_dir_input(void)
{
	fx32 cont_x = (fx32)(FIXED_POINT_ONE * GetGamepadAxisMovement(0, 0));
	fx32 cont_y = (fx32)(FIXED_POINT_ONE * GetGamepadAxisMovement(0, 1));
	
	fx32 key_w = is_button_held(KEY_W) ? FIXED_POINT_ONE : 0;
	fx32 key_s = is_button_held(KEY_S) ? FIXED_POINT_ONE : 0;
	fx32 key_a = is_button_held(KEY_A) ? FIXED_POINT_ONE : 0;
	fx32 key_d = is_button_held(KEY_D) ? FIXED_POINT_ONE : 0;
	
	// Either Gamepad or Keyboard control, not both!
	if(key_w != 0 || key_s != 0 || key_a != 0 || key_d != 0){
		cont_x = key_d - key_a;
		cont_y = key_s - key_w;
	}
	
	return (vec2){cont_x, cont_y};
}