crocparty/sys/sys_input.c

37 lines
1019 B
C
Raw Permalink Normal View History

2024-02-28 05:07:15 +00:00
#include "device/device.h"
#include "sys/sys.h"
#include "sys_input.h"
sys_i32 sys_input_down_frames[DEVICE_BUTTON_N];
void sys_input_update() {
for (DeviceButton db = 0; db < DEVICE_BUTTON_N; db++) {
if (device_buttons[db]) {
sys_input_down_frames[db] += 1;
} else {
sys_input_down_frames[db] = 0;
}
}
}
void sys_input_reset() {
for (DeviceButton db = 0; db < DEVICE_BUTTON_N; db++) {
sys_input_down_frames[db] = 0;
}
}
bool sys_btn(DeviceButton button) {
if (button >= DEVICE_BUTTON_N) { return false; }
return sys_input_down_frames[button] >= 1;
}
2024-02-28 05:49:20 +00:00
bool sys_btnp(DeviceButton button, bool repeat) {
2024-02-28 05:07:15 +00:00
if (button >= DEVICE_BUTTON_N) { return false; }
if (sys_input_down_frames[button] == 1) { return true; }
2024-02-28 05:49:20 +00:00
if (!repeat) { return false; }
2024-02-28 05:07:15 +00:00
// 31 and every 8 frames after that
if (sys_input_down_frames[button] >= 31 && (sys_input_down_frames[button] - 31) % 8 == 0) {
return true;
}
return false;
}