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.

58 lines
2.2 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Keyboard 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 - keyboard input");
  19. Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 };
  20. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  21. //--------------------------------------------------------------------------------------
  22. // Main game loop
  23. while (!WindowShouldClose()) // Detect window close button or ESC key
  24. {
  25. // Update
  26. //----------------------------------------------------------------------------------
  27. if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 2.0f;
  28. if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 2.0f;
  29. if (IsKeyDown(KEY_UP)) ballPosition.y -= 2.0f;
  30. if (IsKeyDown(KEY_DOWN)) ballPosition.y += 2.0f;
  31. //----------------------------------------------------------------------------------
  32. // Draw
  33. //----------------------------------------------------------------------------------
  34. BeginDrawing();
  35. ClearBackground(RAYWHITE);
  36. DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY);
  37. DrawCircleV(ballPosition, 50, MAROON);
  38. EndDrawing();
  39. //----------------------------------------------------------------------------------
  40. }
  41. // De-Initialization
  42. //--------------------------------------------------------------------------------------
  43. CloseWindow(); // Close window and OpenGL context
  44. //--------------------------------------------------------------------------------------
  45. return 0;
  46. }