ex03b_input_mouse.c 2.2 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. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. Vector2 ballPosition = { -100.0, -100.0 };
  19. int counter = 0;
  20. int mouseX, mouseY;
  21. InitWindow(screenWidth, screenHeight, "raylib example 06 - mouse input");
  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, DARKGRAY);
  42. EndDrawing();
  43. //----------------------------------------------------------------------------------
  44. }
  45. // De-Initialization
  46. //--------------------------------------------------------------------------------------
  47. CloseWindow(); // Close window and OpenGL context
  48. //--------------------------------------------------------------------------------------
  49. return 0;
  50. }