2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

IZ_keyboard.c 1.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "IZ_keyboard.h"
  2. void IZ_HandleKeyboardEvents(SDL_Event e, IZ_KeyboardState* state, IZ_Action* action) {
  3. for (uint8_t i = 0; i < CONTROLS; i += 1) {
  4. if (e.key.keysym.sym == state->config.control_mapping[i]) {
  5. const uint16_t bitflag = (0x1 << i);
  6. if (e.type == SDL_KEYDOWN) {
  7. *action |= bitflag;
  8. } else if (e.type == SDL_KEYUP) {
  9. *action &= ~bitflag;
  10. }
  11. }
  12. }
  13. }
  14. void IZ_SaveKeyboardConfig(IZ_KeyboardConfig* config, uint8_t p) {
  15. char config_path[128];
  16. IZ_GetConfigPath(config_path, 128);
  17. char keyboard_section_name[] = "Keyboard.0.ControlMapping";
  18. keyboard_section_name[9] = (char) (48 + p);
  19. for (uint8_t i = 0; i < CONTROLS; i += 1) {
  20. ini_puts(keyboard_section_name, ACTION_NAMES[i], SDL_GetKeyName(config->control_mapping[i]), config_path);
  21. }
  22. }
  23. void IZ_LoadKeyboardConfig(IZ_KeyboardConfig* config, uint8_t p) {
  24. char config_path[128];
  25. IZ_GetConfigPath(config_path, 128);
  26. char buffer[128];
  27. char keyboard_section_name[] = "Keyboard.0.ControlMapping";
  28. keyboard_section_name[9] = (char) (48 + p);
  29. for (uint8_t i = 0; i < CONTROLS; i += 1) {
  30. ini_gets(
  31. keyboard_section_name,
  32. ACTION_NAMES[i],
  33. SDL_GetKeyName(IZ_DEFAULT_KEYBOARD_CONTROLS[p][i]),
  34. buffer,
  35. 128,
  36. config_path
  37. );
  38. config->control_mapping[i] = SDL_GetKeyFromName(buffer);
  39. }
  40. }