core_input_mouse.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. -------------------------------------------------------------------------------------------
  2. --
  3. -- raylib [core] example - Mouse input
  4. --
  5. -- This example has been created using raylib 1.6 (www.raylib.com)
  6. -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. --
  8. -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  9. --
  10. -------------------------------------------------------------------------------------------
  11. -- Initialization
  12. -------------------------------------------------------------------------------------------
  13. local screenWidth = 800
  14. local screenHeight = 450
  15. InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input")
  16. local ballPosition = Vector2(-100.0, -100.0)
  17. local ballColor = DARKBLUE
  18. SetTargetFPS(60) -- Set target frames-per-second
  19. -----------------------------------------------------------------------------------------
  20. -- Main game loop
  21. while not WindowShouldClose() do -- Detect window close button or ESC key
  22. -- Update
  23. ------------------------------------------------------------------------------------
  24. ballPosition = GetMousePosition()
  25. if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then ballColor = MAROON
  26. elseif (IsMouseButtonPressed(MOUSE.MIDDLE_BUTTON)) then ballColor = LIME
  27. elseif (IsMouseButtonPressed(MOUSE.RIGHT_BUTTON)) then ballColor = DARKBLUE
  28. end
  29. ------------------------------------------------------------------------------------
  30. -- Draw
  31. ------------------------------------------------------------------------------------
  32. BeginDrawing()
  33. ClearBackground(RAYWHITE)
  34. DrawCircleV(ballPosition, 40, ballColor)
  35. DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY)
  36. EndDrawing()
  37. ------------------------------------------------------------------------------------
  38. end
  39. -- De-Initialization
  40. ----------------------------------------------------------------------------------------
  41. CloseWindow() -- Close window and OpenGL context
  42. ----------------------------------------------------------------------------------------