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.

61 lines
2.1 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 (Ray San - raysan@raysanweb.com)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
  19. int mouseX, mouseY;
  20. Vector2 ballPosition = { -100.0, -100.0 };
  21. //---------------------------------------------------------------------------------------
  22. // Main game loop
  23. while (!WindowShouldClose()) // Detect window close button or ESC key
  24. {
  25. // Update
  26. //----------------------------------------------------------------------------------
  27. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  28. {
  29. mouseX = GetMouseX();
  30. mouseY = GetMouseY();
  31. ballPosition.x = (float)mouseX;
  32. ballPosition.y = (float)mouseY;
  33. }
  34. //----------------------------------------------------------------------------------
  35. // Draw
  36. //----------------------------------------------------------------------------------
  37. BeginDrawing();
  38. ClearBackground(RAYWHITE);
  39. DrawCircleV(ballPosition, 40, GOLD);
  40. DrawText("mouse click to draw the ball", 10, 10, 20, DARKGRAY);
  41. EndDrawing();
  42. //----------------------------------------------------------------------------------
  43. }
  44. // De-Initialization
  45. //--------------------------------------------------------------------------------------
  46. CloseWindow(); // Close window and OpenGL context
  47. //--------------------------------------------------------------------------------------
  48. return 0;
  49. }