core_input_gamepad_info.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Gamepad information
  4. *
  5. * NOTE: This example requires a Gamepad connected to the system
  6. * Check raylib.h for buttons configuration
  7. *
  8. * Example originally created with raylib 4.6, last time updated with raylib 4.6
  9. *
  10. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  11. * BSD-like license that allows static linking with closed source software
  12. *
  13. * Copyright (c) 2013-2024 Ramon Santamaria (@raysan5)
  14. *
  15. ********************************************************************************************/
  16. #include "raylib.h"
  17. //------------------------------------------------------------------------------------
  18. // Program main entry point
  19. //------------------------------------------------------------------------------------
  20. int main(void)
  21. {
  22. // Initialization
  23. //--------------------------------------------------------------------------------------
  24. const int screenWidth = 800;
  25. const int screenHeight = 450;
  26. SetConfigFlags(FLAG_MSAA_4X_HINT); // Set MSAA 4X hint before windows creation
  27. InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad information");
  28. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  29. //--------------------------------------------------------------------------------------
  30. // Main game loop
  31. while (!WindowShouldClose()) // Detect window close button or ESC key
  32. {
  33. // Update
  34. //----------------------------------------------------------------------------------
  35. // TODO: Update your variables here
  36. //----------------------------------------------------------------------------------
  37. // Draw
  38. //----------------------------------------------------------------------------------
  39. BeginDrawing();
  40. ClearBackground(RAYWHITE);
  41. for (int i = 0, y = 5; i < 4; i++) // MAX_GAMEPADS = 4
  42. {
  43. if (IsGamepadAvailable(i))
  44. {
  45. DrawText(TextFormat("Gamepad name: %s", GetGamepadName(i)), 10, y, 10, BLACK);
  46. y += 11;
  47. DrawText(TextFormat("\tAxis count: %d", GetGamepadAxisCount(i)), 10, y, 10, BLACK);
  48. y += 11;
  49. for (int axis = 0; axis < GetGamepadAxisCount(i); axis++)
  50. {
  51. DrawText(TextFormat("\tAxis %d = %f", axis, GetGamepadAxisMovement(i, axis)), 10, y, 10, BLACK);
  52. y += 11;
  53. }
  54. for (int button = 0; button < 32; button++)
  55. {
  56. DrawText(TextFormat("\tButton %d = %d", button, IsGamepadButtonDown(i, button)), 10, y, 10, BLACK);
  57. y += 11;
  58. }
  59. }
  60. }
  61. DrawFPS(GetScreenWidth() - 100, 100);
  62. EndDrawing();
  63. //----------------------------------------------------------------------------------
  64. }
  65. // De-Initialization
  66. //--------------------------------------------------------------------------------------
  67. CloseWindow(); // Close window and OpenGL context
  68. //--------------------------------------------------------------------------------------
  69. }