| 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 | |
| 12 | #include "raylib.h" |
| 13 | |
| 14 | int main(void) |
| 15 | { |
| 16 | // Initialization |
| 17 | //-------------------------------------------------------------------------------------- |
| 18 | const int screenWidth = 800; |
| 19 | const int screenHeight = 450; |
| 20 | |
| 21 | InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input" ); |
| 22 | |
| 23 | Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 }; |
| 24 | |
| 25 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
| 26 | //-------------------------------------------------------------------------------------- |
| 27 | |
| 28 | // Main game loop |
| 29 | while (!WindowShouldClose()) // Detect window close button or ESC key |
| 30 | { |
| 31 | // Update |
| 32 | //---------------------------------------------------------------------------------- |
| 33 | if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 2.0f; |
| 34 | if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 2.0f; |
| 35 | if (IsKeyDown(KEY_UP)) ballPosition.y -= 2.0f; |
| 36 | if (IsKeyDown(KEY_DOWN)) ballPosition.y += 2.0f; |
| 37 | //---------------------------------------------------------------------------------- |
| 38 | |
| 39 | // Draw |
| 40 | //---------------------------------------------------------------------------------- |
| 41 | BeginDrawing(); |
| 42 | |
| 43 | ClearBackground(RAYWHITE); |
| 44 | |
| 45 | DrawText("move the ball with arrow keys" , 10, 10, 20, DARKGRAY); |
| 46 | |
| 47 | DrawCircleV(ballPosition, 50, MAROON); |
| 48 | |
| 49 | EndDrawing(); |
| 50 | //---------------------------------------------------------------------------------- |
| 51 | } |
| 52 | |
| 53 | // De-Initialization |
| 54 | //-------------------------------------------------------------------------------------- |
| 55 | CloseWindow(); // Close window and OpenGL context |
| 56 | //-------------------------------------------------------------------------------------- |
| 57 | |
| 58 | return 0; |
| 59 | } |