test_random.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*******************************************************************************************
  2. *
  3. * raylib test - Testing GetRandomValue()
  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) 2013 Ramon Santamaria (Ray San - [email protected])
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. int framesCounter = 0;
  19. InitWindow(screenWidth, screenHeight, "raylib test - Random numbers");
  20. int randValue = GetRandomValue(-8,5);
  21. SetTargetFPS(60);
  22. //--------------------------------------------------------------------------------------
  23. // Main game loop
  24. while (!WindowShouldClose()) // Detect window close button or ESC key
  25. {
  26. // Update
  27. //----------------------------------------------------------------------------------
  28. framesCounter++;
  29. if ((framesCounter/60)%2)
  30. {
  31. randValue = GetRandomValue(-8,5);
  32. framesCounter = 0;
  33. }
  34. //----------------------------------------------------------------------------------
  35. // Draw
  36. //----------------------------------------------------------------------------------
  37. BeginDrawing();
  38. ClearBackground(RAYWHITE);
  39. DrawText(FormatText("%i", randValue), 120, 120, 60, LIGHTGRAY);
  40. EndDrawing();
  41. //----------------------------------------------------------------------------------
  42. }
  43. // De-Initialization
  44. //--------------------------------------------------------------------------------------
  45. CloseWindow(); // Close window and OpenGL context
  46. //--------------------------------------------------------------------------------------
  47. return 0;
  48. }