MCPcopy Create free account
hub / github.com/RobLoach/raylib-cpp / main

Function main

examples/core/core_random_values.cpp:14–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

ShouldCloseMethod · 0.80
DrawTextFunction · 0.50

Tested by

no test coverage detected