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.

60 lines
2.3 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Mouse input
  4. *
  5. * This example has been created using raylib 1.0 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main(void)
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. const int screenWidth = 800;
  17. const int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
  19. Vector2 ballPosition = { -100.0f, -100.0f };
  20. Color ballColor = DARKBLUE;
  21. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  22. //---------------------------------------------------------------------------------------
  23. // Main game loop
  24. while (!WindowShouldClose()) // Detect window close button or ESC key
  25. {
  26. // Update
  27. //----------------------------------------------------------------------------------
  28. ballPosition = GetMousePosition();
  29. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ballColor = MAROON;
  30. else if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) ballColor = LIME;
  31. else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE;
  32. //----------------------------------------------------------------------------------
  33. // Draw
  34. //----------------------------------------------------------------------------------
  35. BeginDrawing();
  36. ClearBackground(RAYWHITE);
  37. DrawCircleV(ballPosition, 40, ballColor);
  38. DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
  39. EndDrawing();
  40. //----------------------------------------------------------------------------------
  41. }
  42. // De-Initialization
  43. //--------------------------------------------------------------------------------------
  44. CloseWindow(); // Close window and OpenGL context
  45. //--------------------------------------------------------------------------------------
  46. return 0;
  47. }