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.

64 lines
2.4 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Generate random values
  4. *
  5. * This example has been created using raylib 1.1 (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 - generate random values");
  19. int framesCounter = 0; // Variable used to count frames
  20. int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
  21. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  22. //--------------------------------------------------------------------------------------
  23. // Main game loop
  24. while (!WindowShouldClose()) // Detect window close button or ESC key
  25. {
  26. // Update
  27. //----------------------------------------------------------------------------------
  28. framesCounter++;
  29. // Every two seconds (120 frames) a new random value is generated
  30. if (((framesCounter/120)%2) == 1)
  31. {
  32. randValue = GetRandomValue(-8, 5);
  33. framesCounter = 0;
  34. }
  35. //----------------------------------------------------------------------------------
  36. // Draw
  37. //----------------------------------------------------------------------------------
  38. BeginDrawing();
  39. ClearBackground(RAYWHITE);
  40. DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON);
  41. DrawText(FormatText("%i", randValue), 360, 180, 80, LIGHTGRAY);
  42. EndDrawing();
  43. //----------------------------------------------------------------------------------
  44. }
  45. // De-Initialization
  46. //--------------------------------------------------------------------------------------
  47. CloseWindow(); // Close window and OpenGL context
  48. //--------------------------------------------------------------------------------------
  49. return 0;
  50. }