Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
//----------------------------------------------------------------------------------
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
// 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)
* 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
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))
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()
//----------------------------------------------------------------------------------
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
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