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
12#include "raylib.h"
13
14int main(void)
15{
16 // Initialization
17 //--------------------------------------------------------------------------------------
18 const int screenWidth = 800;
19 const int screenHeight = 450;
20
21 InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values");
22
23 int framesCounter = 0; // Variable used to count frames
24
25 int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
26
27 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
28 //--------------------------------------------------------------------------------------
29
30 // Main game loop
31 while (!WindowShouldClose()) // Detect window close button or ESC key
32 {
33 // Update
34 //----------------------------------------------------------------------------------
35 framesCounter++;
36
37 // Every two seconds (120 frames) a new random value is generated
38 if (((framesCounter/120)%2) == 1)
39 {
40 randValue = GetRandomValue(-8, 5);
41 framesCounter = 0;
42 }
43 //----------------------------------------------------------------------------------
44
45 // Draw
46 //----------------------------------------------------------------------------------
47 BeginDrawing();
48
49 ClearBackground(RAYWHITE);
50
51 DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON);
52
53 DrawText(FormatText("%i", randValue), 360, 180, 80, LIGHTGRAY);
54
55 EndDrawing();
56 //----------------------------------------------------------------------------------
57 }
58
59 // De-Initialization
60 //--------------------------------------------------------------------------------------
61 CloseWindow(); // Close window and OpenGL context
62 //--------------------------------------------------------------------------------------
63
64 return 0;
65}