diff options
author | kdx <kikoodx@paranoici.org> | 2024-01-11 06:43:48 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2024-01-11 06:43:48 +0100 |
commit | e208461e278ee4f0482dccd342935ad8a80ce59a (patch) | |
tree | 5357cd3f243c6515719a6026a5f63e9d005cfdfd | |
parent | 347e466a5c0bb55197b1dc84e6d3e1e0f896fb82 (diff) | |
download | 008-e208461e278ee4f0482dccd342935ad8a80ce59a.tar.gz |
use input module
-rw-r--r-- | src/main.c | 33 |
1 files changed, 29 insertions, 4 deletions
@@ -1,6 +1,7 @@ #include <time.h> #include <cglm/cam.h> +static void _setup_input(void); static int _main_loop(void *udata); Mesh *g_cube; @@ -23,21 +24,45 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) .mixer=0, .basepath=argv[1]) == 0); defer(TZR_Quit); + _setup_input(); + defer(input_deinit); world_init("res/world/world.csv", "res/world/%d.csv"); defer(world_deinit); TZR_MainLoop(_main_loop, nullptr); return 0; } +static void +_setup_input(void) +{ + input_new_action("cam left"); + input_bind_action_sc("cam left", SDL_SCANCODE_A); + + input_new_action("cam right"); + input_bind_action_sc("cam right", SDL_SCANCODE_D); + + input_new_action("cam up"); + input_bind_action_sc("cam up", SDL_SCANCODE_W); + + input_new_action("cam down"); + input_bind_action_sc("cam down", SDL_SCANCODE_S); + + input_new_axis("cam x"); + input_bind_axis_act("cam x", "cam left", "cam right"); + input_bind_axis_gc("cam x", SDL_CONTROLLER_AXIS_RIGHTX); + + input_new_axis("cam y"); + input_bind_axis_act("cam y", "cam up", "cam down"); + input_bind_axis_gc("cam y", SDL_CONTROLLER_AXIS_RIGHTY); +} + static int _main_loop([[maybe_unused]] void *udata) { static f64 x = 0, y = 0; - x -= TZR_IsKeyDown(SDL_SCANCODE_A) * 0.1; - x += TZR_IsKeyDown(SDL_SCANCODE_D) * 0.1; - y -= TZR_IsKeyDown(SDL_SCANCODE_W) * 0.1; - y += TZR_IsKeyDown(SDL_SCANCODE_S) * 0.1; + x += input_axisf("cam x") * 0.1; + y += input_axisf("cam y") * 0.1; assert(TZR_DrawBegin() == 0); |