aboutsummaryrefslogtreecommitdiff
path: root/src/gunner/controller.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gunner/controller.c')
-rw-r--r--src/gunner/controller.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/gunner/controller.c b/src/gunner/controller.c
new file mode 100644
index 0000000..4e56a27
--- /dev/null
+++ b/src/gunner/controller.c
@@ -0,0 +1,92 @@
+// 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};
+}