blob: 434e3d60bff08bee2017374d710c5d67b21e30c3 (
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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include "controller.h"
#include <raylib.h>
// Keyboard things
b32 is_key_pressed(i32 btn)
{
return IsKeyPressed(btn);
}
b32 is_key_held(i32 btn)
{
return IsKeyDown(btn);
}
b32 is_key_released(i32 btn)
{
return IsKeyReleased(btn);
}
// Mouse things
b32 is_mouse_pressed(i32 btn)
{
return IsMouseButtonPressed(btn);
}
b32 is_mouse_held(i32 btn)
{
return IsMouseButtonDown(btn);
}
b32 is_mouse_released(i32 btn)
{
return IsMouseButtonReleased(btn);
}
void set_mouse_scale(f32 x, f32 y)
{
SetMouseScale(x, y);
}
vec2 get_mouse_pos(void)
{
Vector2 pos = GetMousePosition();
return (vec2){FP_TO_FIXED(pos.x), FP_TO_FIXED(pos.y)};
}
fx32 get_wheel_movement(void)
{
return FP_TO_FIXED(GetMouseWheelMove());
}
// Gamepad things
b32 is_button_pressed(i32 btn)
{
return IsGamepadButtonPressed(0, btn);
}
b32 is_button_held(i32 btn)
{
return IsGamepadButtonDown(0, btn);
}
b32 is_button_released(i32 btn)
{
return IsGamepadButtonReleased(0, btn);
}
i32 last_button_press(void)
{
return GetGamepadButtonPressed();
}
// Movement things
vec2 get_dir_input(void)
{
fx32 cont_x = FP_TO_FIXED(GetGamepadAxisMovement(0, 0));
fx32 cont_y = FP_TO_FIXED(GetGamepadAxisMovement(0, 1));
fx32 key_w = IsKeyDown(KEY_W) ? FIXED_POINT_ONE : 0;
fx32 key_s = IsKeyDown(KEY_S) ? FIXED_POINT_ONE : 0;
fx32 key_a = IsKeyDown(KEY_A) ? FIXED_POINT_ONE : 0;
fx32 key_d = IsKeyDown(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};
}
|