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.

71 lines
2.8 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Generate random values
  4. *
  5. * Example originally created with raylib 1.1, last time updated with raylib 1.1
  6. *
  7. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  8. * BSD-like license that allows static linking with closed source software
  9. *
  10. * Copyright (c) 2014-2024 Ramon Santamaria (@raysan5)
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. //------------------------------------------------------------------------------------
  15. // Program main entry point
  16. //------------------------------------------------------------------------------------
  17. int main(void)
  18. {
  19. // Initialization
  20. //--------------------------------------------------------------------------------------
  21. const int screenWidth = 800;
  22. const int screenHeight = 450;
  23. InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values");
  24. // SetRandomSeed(0xaabbccff); // Set a custom random seed if desired, by default: "time(NULL)"
  25. int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
  26. unsigned int framesCounter = 0; // Variable used to count frames
  27. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  28. //--------------------------------------------------------------------------------------
  29. // Main game loop
  30. while (!WindowShouldClose()) // Detect window close button or ESC key
  31. {
  32. // Update
  33. //----------------------------------------------------------------------------------
  34. framesCounter++;
  35. // Every two seconds (120 frames) a new random value is generated
  36. if (((framesCounter/120)%2) == 1)
  37. {
  38. randValue = GetRandomValue(-8, 5);
  39. framesCounter = 0;
  40. }
  41. //----------------------------------------------------------------------------------
  42. // Draw
  43. //----------------------------------------------------------------------------------
  44. BeginDrawing();
  45. ClearBackground(RAYWHITE);
  46. DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON);
  47. DrawText(TextFormat("%i", randValue), 360, 180, 80, LIGHTGRAY);
  48. EndDrawing();
  49. //----------------------------------------------------------------------------------
  50. }
  51. // De-Initialization
  52. //--------------------------------------------------------------------------------------
  53. CloseWindow(); // Close window and OpenGL context
  54. //--------------------------------------------------------------------------------------
  55. return 0;
  56. }