您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

64 行
2.6 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_BUTTON_LEFT)) ballColor = MAROON;
  30. else if (IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE)) ballColor = LIME;
  31. else if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) ballColor = DARKBLUE;
  32. else if (IsMouseButtonPressed(MOUSE_BUTTON_SIDE)) ballColor = PURPLE;
  33. else if (IsMouseButtonPressed(MOUSE_BUTTON_EXTRA)) ballColor = YELLOW;
  34. else if (IsMouseButtonPressed(MOUSE_BUTTON_FORWARD)) ballColor = ORANGE;
  35. else if (IsMouseButtonPressed(MOUSE_BUTTON_BACK)) ballColor = BEIGE;
  36. //----------------------------------------------------------------------------------
  37. // Draw
  38. //----------------------------------------------------------------------------------
  39. BeginDrawing();
  40. ClearBackground(RAYWHITE);
  41. DrawCircleV(ballPosition, 40, ballColor);
  42. DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
  43. EndDrawing();
  44. //----------------------------------------------------------------------------------
  45. }
  46. // De-Initialization
  47. //--------------------------------------------------------------------------------------
  48. CloseWindow(); // Close window and OpenGL context
  49. //--------------------------------------------------------------------------------------
  50. return 0;
  51. }