How to use the raylib.GetRandomValue function in raylib

To help you get started, we’ve selected a few raylib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RobLoach / node-raylib / examples / core / core_3d_camera_first_person.js View on Github external
r.Vector3(0, 1.8, 0),
  r.Vector3(0, 1, 0),
  60,
  r.CAMERA_PERSPECTIVE
);

// Generates some random columns
const heights = []
const positions = []
const colors = []

for (let i = 0; i < MAX_COLUMNS; i++)
{
  let newHeight = r.GetRandomValue(1, 12)
  heights.push(newHeight)
  positions.push(r.Vector3(r.GetRandomValue(-15, 15), newHeight / 2, r.GetRandomValue(-15, 15)))
  colors.push(r.Color(r.GetRandomValue(20, 255), r.GetRandomValue(10, 55), 30, 255))
}

r.SetCameraMode(camera, r.CAMERA_FIRST_PERSON); // Set a first person camera mode

r.SetTargetFPS(60);                           // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())                // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    r.UpdateCamera(camera);                  // Update camera
    //----------------------------------------------------------------------------------
github RobLoach / node-raylib / examples / core / core_2d_camera.js View on Github external
r.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera")

const player = r.Rectangle(400, 280, 40, 40)
const buildings = []
const buildColors = []

let spacing = 0;

for (let i = 0; i < MAX_BUILDINGS; i++)
{
  let height = r.GetRandomValue(100, 800)
  let newBuilding = r.Rectangle(
    -6000 + spacing,
    screenHeight - 130 - height,
    r.GetRandomValue(50, 200),
    height
  )
  spacing += newBuilding.width;
  buildings.push(newBuilding)
  buildColors.push(r.Color(r.GetRandomValue(200, 240), r.GetRandomValue(200, 240), r.GetRandomValue(200, 250), 255))
}

const camera = r.Camera2D(
  r.Vector2(),
  r.Vector2(player.x + 20, player.y + 20),
  0, 1)

r.SetTargetFPS(60);                   // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
github RobLoach / node-raylib / examples / core / core_2d_camera.js View on Github external
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450

r.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera")

const player = r.Rectangle(400, 280, 40, 40)
const buildings = []
const buildColors = []

let spacing = 0;

for (let i = 0; i < MAX_BUILDINGS; i++)
{
  let height = r.GetRandomValue(100, 800)
  let newBuilding = r.Rectangle(
    -6000 + spacing,
    screenHeight - 130 - height,
    r.GetRandomValue(50, 200),
    height
  )
  spacing += newBuilding.width;
  buildings.push(newBuilding)
  buildColors.push(r.Color(r.GetRandomValue(200, 240), r.GetRandomValue(200, 240), r.GetRandomValue(200, 250), 255))
}

const camera = r.Camera2D(
  r.Vector2(),
  r.Vector2(player.x + 20, player.y + 20),
  0, 1)
github RobLoach / node-raylib / examples / core / core_random_values.js View on Github external
*   Copyright (c) 2014 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

const r = require('raylib')

// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450

r.InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values")

var framesCounter = 0  // Variable used to count frames

var randValue = r.GetRandomValue(-8, 5)   // Get a random integer number between -8 and 5 (both included)

r.SetTargetFPS(60)       // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())    // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    framesCounter++

    // Every two seconds (120 frames) a new random value is generated
    if (((framesCounter/120)%2) == 1)
    {
        randValue = r.GetRandomValue(-8, 5)
        framesCounter = 0
github RobLoach / node-raylib / examples / core / core_2d_camera.js View on Github external
const buildColors = []

let spacing = 0;

for (let i = 0; i < MAX_BUILDINGS; i++)
{
  let height = r.GetRandomValue(100, 800)
  let newBuilding = r.Rectangle(
    -6000 + spacing,
    screenHeight - 130 - height,
    r.GetRandomValue(50, 200),
    height
  )
  spacing += newBuilding.width;
  buildings.push(newBuilding)
  buildColors.push(r.Color(r.GetRandomValue(200, 240), r.GetRandomValue(200, 240), r.GetRandomValue(200, 250), 255))
}

const camera = r.Camera2D(
  r.Vector2(),
  r.Vector2(player.x + 20, player.y + 20),
  0, 1)

r.SetTargetFPS(60);                   // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())        // Detect window close button or ESC key
{
  // Update
  //----------------------------------------------------------------------------------
  if (r.IsKeyDown(r.KEY_RIGHT))
github RobLoach / node-raylib / examples / core / core_random_values.js View on Github external
var randValue = r.GetRandomValue(-8, 5)   // Get a random integer number between -8 and 5 (both included)

r.SetTargetFPS(60)       // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())    // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    framesCounter++

    // Every two seconds (120 frames) a new random value is generated
    if (((framesCounter/120)%2) == 1)
    {
        randValue = r.GetRandomValue(-8, 5)
        framesCounter = 0
    }
    //----------------------------------------------------------------------------------

    // Draw
    //----------------------------------------------------------------------------------
    r.BeginDrawing()

        r.ClearBackground(r.RAYWHITE)

        r.DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, r.MAROON)

        r.DrawText(r.FormatText("%i", randValue), 360, 180, 80, r.LIGHTGRAY)

    r.EndDrawing()
    //----------------------------------------------------------------------------------
github RobLoach / node-raylib / examples / core / core_3d_camera_first_person.js View on Github external
r.Vector3(0, 1, 0),
  60,
  r.CAMERA_PERSPECTIVE
);

// Generates some random columns
const heights = []
const positions = []
const colors = []

for (let i = 0; i < MAX_COLUMNS; i++)
{
  let newHeight = r.GetRandomValue(1, 12)
  heights.push(newHeight)
  positions.push(r.Vector3(r.GetRandomValue(-15, 15), newHeight / 2, r.GetRandomValue(-15, 15)))
  colors.push(r.Color(r.GetRandomValue(20, 255), r.GetRandomValue(10, 55), 30, 255))
}

r.SetCameraMode(camera, r.CAMERA_FIRST_PERSON); // Set a first person camera mode

r.SetTargetFPS(60);                           // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())                // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    r.UpdateCamera(camera);                  // Update camera
    //----------------------------------------------------------------------------------

    // Draw
github RobLoach / node-raylib / examples / core / core_3d_camera_first_person.js View on Github external
const camera = r.Camera(
  r.Vector3(4, 2, 4),
  r.Vector3(0, 1.8, 0),
  r.Vector3(0, 1, 0),
  60,
  r.CAMERA_PERSPECTIVE
);

// Generates some random columns
const heights = []
const positions = []
const colors = []

for (let i = 0; i < MAX_COLUMNS; i++)
{
  let newHeight = r.GetRandomValue(1, 12)
  heights.push(newHeight)
  positions.push(r.Vector3(r.GetRandomValue(-15, 15), newHeight / 2, r.GetRandomValue(-15, 15)))
  colors.push(r.Color(r.GetRandomValue(20, 255), r.GetRandomValue(10, 55), 30, 255))
}

r.SetCameraMode(camera, r.CAMERA_FIRST_PERSON); // Set a first person camera mode

r.SetTargetFPS(60);                           // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose())                // Detect window close button or ESC key
{
    // Update
    //----------------------------------------------------------------------------------
    r.UpdateCamera(camera);                  // Update camera