Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include "raylib.h"
  2.  
  3. int main()
  4. {
  5. // Initialization
  6. //--------------------------------------------------------------------------------------
  7. int screenWidth = 800;
  8. int screenHeight = 450;
  9.  
  10. InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input");
  11.  
  12. Vector2 snakePos = { (float)screenWidth/2, (float)screenHeight/2 };
  13. Vector2 blockSize = { (float)screenWidth/32, (float)screenWidth/32 };
  14.  
  15. SetTargetFPS(60);
  16. //--------------------------------------------------------------------------------------
  17.  
  18. // Main game loop
  19. while (!WindowShouldClose())
  20. {
  21. // Update
  22. //----------------------------------------------------------------------------------
  23. if (IsKeyDown(KEY_RIGHT)) snakePos.x += 2.0f;
  24. if (IsKeyDown(KEY_LEFT)) snakePos.x -= 2.0f;
  25. if (IsKeyDown(KEY_UP)) snakePos.y -= 2.0f;
  26. if (IsKeyDown(KEY_DOWN)) snakePos.y += 2.0f;
  27. //----------------------------------------------------------------------------------
  28.  
  29. // Draw
  30. //----------------------------------------------------------------------------------
  31. BeginDrawing();
  32.  
  33. ClearBackground(RAYWHITE);
  34.  
  35. DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY);
  36.  
  37. DrawRectangleV(snakePos, blockSize, MAROON);
  38.  
  39. EndDrawing();
  40. //----------------------------------------------------------------------------------
  41. }
  42.  
  43. // De-Initialization
  44. //--------------------------------------------------------------------------------------
  45. CloseWindow();
  46. //--------------------------------------------------------------------------------------
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement