You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.9 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Mouse input
  4. *
  5. * Example originally created with raylib 1.0, last time updated with raylib 4.0
  6. *
  7. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  8. * BSD-like license that allows static linking with closed source software
  9. *
  10. * Copyright (c) 2014-2024 Ramon Santamaria (@raysan5)
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. //------------------------------------------------------------------------------------
  15. // Program main entry point
  16. //------------------------------------------------------------------------------------
  17. int main(void)
  18. {
  19. // Initialization
  20. //--------------------------------------------------------------------------------------
  21. const int screenWidth = 800;
  22. const int screenHeight = 450;
  23. InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
  24. Vector2 ballPosition = { -100.0f, -100.0f };
  25. Color ballColor = DARKBLUE;
  26. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  27. //---------------------------------------------------------------------------------------
  28. // Main game loop
  29. while (!WindowShouldClose()) // Detect window close button or ESC key
  30. {
  31. // Update
  32. //----------------------------------------------------------------------------------
  33. ballPosition = GetMousePosition();
  34. if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) ballColor = MAROON;
  35. else if (IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE)) ballColor = LIME;
  36. else if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) ballColor = DARKBLUE;
  37. else if (IsMouseButtonPressed(MOUSE_BUTTON_SIDE)) ballColor = PURPLE;
  38. else if (IsMouseButtonPressed(MOUSE_BUTTON_EXTRA)) ballColor = YELLOW;
  39. else if (IsMouseButtonPressed(MOUSE_BUTTON_FORWARD)) ballColor = ORANGE;
  40. else if (IsMouseButtonPressed(MOUSE_BUTTON_BACK)) ballColor = BEIGE;
  41. //----------------------------------------------------------------------------------
  42. // Draw
  43. //----------------------------------------------------------------------------------
  44. BeginDrawing();
  45. ClearBackground(RAYWHITE);
  46. DrawCircleV(ballPosition, 40, ballColor);
  47. DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
  48. EndDrawing();
  49. //----------------------------------------------------------------------------------
  50. }
  51. // De-Initialization
  52. //--------------------------------------------------------------------------------------
  53. CloseWindow(); // Close window and OpenGL context
  54. //--------------------------------------------------------------------------------------
  55. return 0;
  56. }