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.

51 lines
2.1 KiB

  1. -------------------------------------------------------------------------------------------
  2. --
  3. -- raylib [core] example - Keyboard 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 - basic window")
  16. local ballPosition = Vector2(screenWidth/2, screenHeight/2)
  17. SetTargetFPS(60) -- Set target frames-per-second
  18. -------------------------------------------------------------------------------------------
  19. -- Main game loop
  20. while not WindowShouldClose() do -- Detect window close button or ESC key
  21. -- Update
  22. ---------------------------------------------------------------------------------------
  23. if (IsKeyDown(KEY.RIGHT)) then ballPosition.x = ballPosition.x + 0.8 end
  24. if (IsKeyDown(KEY.LEFT)) then ballPosition.x = ballPosition.x - 0.8 end
  25. if (IsKeyDown(KEY.UP)) then ballPosition.y = ballPosition.y - 0.8 end
  26. if (IsKeyDown(KEY.DOWN)) then ballPosition.y = ballPosition.y + 0.8 end
  27. ---------------------------------------------------------------------------------------
  28. -- Draw
  29. ---------------------------------------------------------------------------------------
  30. BeginDrawing()
  31. ClearBackground(RAYWHITE)
  32. DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY)
  33. DrawCircleV(ballPosition, 50, MAROON)
  34. EndDrawing()
  35. ---------------------------------------------------------------------------------------
  36. end
  37. -- De-Initialization
  38. -------------------------------------------------------------------------------------------
  39. CloseWindow() -- Close window and OpenGL context
  40. -------------------------------------------------------------------------------------------