From 83505b7be49dbf7789deb814bd159d9c37181d05 Mon Sep 17 00:00:00 2001 From: Uneven Prankster Date: Sun, 27 Aug 2023 20:15:02 -0300 Subject: Now with keyboard/mouse things! --- src/audio.h | 26 ------------------------- src/audio_sys.h | 26 +++++++++++++++++++++++++ src/controller.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/controller.h | 16 +++++++++++++-- 4 files changed, 99 insertions(+), 28 deletions(-) delete mode 100644 src/audio.h create mode 100644 src/audio_sys.h diff --git a/src/audio.h b/src/audio.h deleted file mode 100644 index 8a5b6cc..0000000 --- a/src/audio.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "config.h" - -// 8 max -i32 load_audio(const char* path); -void play_audio(i32 idx); -void pause_audio(i32 idx); - -// Only one at any given time. -// In the future you can load a second one -// It'll be a copy of the one from my Godot games -i32 load_music(const char* path); -void play_music(void); - -// It would be more convenient if the files had this info -// But it's better to just let you control this for now. -void set_music_loop(b32 loop); -void set_music_loop_point(f32 point); - -void pause_music(void); -void replay_music(void); - -void update_audio_sys(void); -void unload_active_audio(void); -void unload_current_music(void); \ No newline at end of file diff --git a/src/audio_sys.h b/src/audio_sys.h new file mode 100644 index 0000000..8a5b6cc --- /dev/null +++ b/src/audio_sys.h @@ -0,0 +1,26 @@ +#pragma once + +#include "config.h" + +// 8 max +i32 load_audio(const char* path); +void play_audio(i32 idx); +void pause_audio(i32 idx); + +// Only one at any given time. +// In the future you can load a second one +// It'll be a copy of the one from my Godot games +i32 load_music(const char* path); +void play_music(void); + +// It would be more convenient if the files had this info +// But it's better to just let you control this for now. +void set_music_loop(b32 loop); +void set_music_loop_point(f32 point); + +void pause_music(void); +void replay_music(void); + +void update_audio_sys(void); +void unload_active_audio(void); +void unload_current_music(void); \ No newline at end of file diff --git a/src/controller.c b/src/controller.c index e52eec5..434e3d6 100644 --- a/src/controller.c +++ b/src/controller.c @@ -2,6 +2,8 @@ #include +// Keyboard things + b32 is_key_pressed(i32 btn) { return IsKeyPressed(btn); @@ -17,6 +19,63 @@ 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)); diff --git a/src/controller.h b/src/controller.h index e4a7683..3476641 100644 --- a/src/controller.h +++ b/src/controller.h @@ -2,12 +2,24 @@ #include "config.h" -// TODO: Controller button presses you DINGUS - b32 is_key_pressed(i32 btn); b32 is_key_held(i32 btn); b32 is_key_released(i32 btn); +b32 is_mouse_pressed(i32 btn); +b32 is_mouse_held(i32 btn); +b32 is_mouse_released(i32 btn); + +void set_mouse_scale(f32 x, f32 y); +vec2 get_mouse_pos(void); +fx32 get_wheel_movement(void); + +b32 is_button_pressed(i32 btn); +b32 is_button_held(i32 btn); +b32 is_button_released(i32 btn); + +i32 last_button_press(void); + vec2 get_dir_input(void); // This portion is implemented in rumble.c! // -- cgit v1.2.3