add proper fnl modules to demo

This commit is contained in:
asrael 2025-10-06 18:14:07 -05:00
parent 9bb9fa5f5b
commit 47c4f2045c
14 changed files with 510 additions and 240 deletions

View file

@ -1,3 +1,4 @@
#include <ctype.h>
#include <SDL3/SDL.h>
#include "pxl8_io.h"
@ -97,12 +98,50 @@ void pxl8_io_free_binary_data(u8* data) {
}
}
bool pxl8_key_down(const pxl8_input_state* input, i32 key) {
if (!input || key < 0 || key >= 256) return false;
return input->keys[key];
static i32 pxl8_key_code(const char* key_name) {
if (!key_name || !key_name[0]) return 0;
SDL_Scancode scancode = SDL_GetScancodeFromName(key_name);
return (i32)scancode;
}
bool pxl8_key_pressed(const pxl8_input_state* input, i32 key) {
if (!input || key < 0 || key >= 256) return false;
bool pxl8_key_down(const pxl8_input_state* input, const char* key_name) {
if (!input) return false;
i32 key = pxl8_key_code(key_name);
if (key < 0 || key >= 256) return false;
return input->keys_down[key];
}
bool pxl8_key_pressed(const pxl8_input_state* input, const char* key_name) {
if (!input) return false;
i32 key = pxl8_key_code(key_name);
if (key < 0 || key >= 256) return false;
return input->keys_pressed[key];
}
bool pxl8_key_released(const pxl8_input_state* input, const char* key_name) {
if (!input) return false;
i32 key = pxl8_key_code(key_name);
if (key < 0 || key >= 256) return false;
return input->keys_released[key];
}
i32 pxl8_mouse_wheel_x(const pxl8_input_state* input) {
if (!input) return 0;
return input->mouse_wheel_x;
}
i32 pxl8_mouse_wheel_y(const pxl8_input_state* input) {
if (!input) return 0;
return input->mouse_wheel_y;
}
i32 pxl8_mouse_x(const pxl8_input_state* input) {
if (!input) return 0;
return input->mouse_x;
}
i32 pxl8_mouse_y(const pxl8_input_state* input) {
if (!input) return 0;
return input->mouse_y;
}