Advertisement
Guest User

pong

a guest
Nov 26th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 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 ballPosition = { screenWidth/2, screenHeight/2 };    
  13.  
  14.     SetTargetFPS(60);       // Set target frames-per-second
  15.     //--------------------------------------------------------------------------------------
  16.    
  17.     // Main game loop
  18.     while (!WindowShouldClose())    // Detect window close button or ESC key
  19.     {
  20.         // Update
  21.         //----------------------------------------------------------------------------------
  22.         if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8;
  23.         if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8;
  24.         if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8;
  25.         if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8;
  26.         //----------------------------------------------------------------------------------
  27.        
  28.         // Draw
  29.         //----------------------------------------------------------------------------------
  30.         BeginDrawing();
  31.        
  32.             ClearBackground(RAYWHITE);
  33.            
  34.             DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY);
  35.            
  36.             DrawCircleV(ballPosition, 50, MAROON);
  37.        
  38.         EndDrawing();
  39.         //----------------------------------------------------------------------------------
  40.     }
  41.  
  42.     // De-Initialization
  43.     //--------------------------------------------------------------------------------------
  44.     CloseWindow();        // Close window and OpenGL context
  45.     //--------------------------------------------------------------------------------------
  46.    
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement