ex03b_input_mouse.c 1.8 KB

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