Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
while (!r.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
r.UpdateCamera(camera); // Update camera
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
r.BeginDrawing();
r.ClearBackground(r.RAYWHITE);
r.BeginMode3D(camera);
r.DrawPlane(r.Vector3(), r.Vector2(32, 32), r.LIGHTGRAY); // Draw ground
r.DrawCube(r.Vector3(-16, 2.5, 0), 1, 5, 32, r.BLUE); // Draw a blue wall
r.DrawCube(r.Vector3(16, 2.5, 0), 1, 5, 32, r.LIME); // Draw a green wall
r.DrawCube(r.Vector3(0, 2.5, 16), 32, 5, 1, r.GOLD); // Draw a yellow wall
// Draw some cubes around
for (let i = 0; i < MAX_COLUMNS; i++)
{
r.DrawCube(positions[i], 2, heights[i], 2, colors[i]);
r.DrawCubeWires(positions[i], 2, heights[i], 2, r.MAROON);
}
r.EndMode3D();
r.DrawRectangle( 10, 10, 220, 70, r.Fade(r.SKYBLUE, 0.5));
r.DrawRectangleLines( 10, 10, 220, 70, r.BLUE);
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))
{
player.x += 2; // Player movement
camera.offset.x -= 2; // Camera displacement with player movement
}
{
// Update
//----------------------------------------------------------------------------------
if (r.IsKeyDown(r.KEY_RIGHT))
{
player.x += 2; // Player movement
camera.offset.x -= 2; // Camera displacement with player movement
}
else if (r.IsKeyDown(r.KEY_LEFT))
{
player.x -= 2; // Player movement
camera.offset.x += 2; // Camera displacement with player movement
}
// Camera target follows player
camera.target = r.Vector2(player.x + 20, player.y + 20)
// Camera rotation controls
if (r.IsKeyDown(r.KEY_A)) {
camera.rotation--;
}
else if (r.IsKeyDown(r.KEY_S)) {
camera.rotation++;
}
// Limit camera rotation to 80 degrees (-40 to 40)
if (camera.rotation > 40) {
camera.rotation = 40
}
else if (camera.rotation < -40) {
camera.rotation = -40
}
const screenWidth = 800;
const screenHeight = 450;
r.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free")
// Define the camera to look into our 3d world
const camera = r.Camera(
r.Vector3(10, 10, 10),
r.Vector3(0, 0, 0),
r.Vector3(0, 1, 0),
45,
r.CAMERA_PERSPECTIVE
)
const cubePosition = r.Vector3()
let cubeScreenPosition = r.Vector2()
r.SetCameraMode(camera, r.CAMERA_FREE); // Set a free 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
// Calculate cube screen space position (with a little offset to be in top)
const cubePositionVector = r.Vector3(cubePosition.x, cubePosition.y + 2.5, cubePosition.z)
cubeScreenPosition = r.GetWorldToScreen(cubePositionVector, camera)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
const r = require('raylib')
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450
r.InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input")
var ballPosition = r.Vector2(-100, -100)
var ballColor = r.DARKBLUE
r.SetTargetFPS(60)
//---------------------------------------------------------------------------------------
// Main game loop
while (!r.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
ballPosition = r.GetMousePosition()
if (r.IsMouseButtonPressed(r.MOUSE_LEFT_BUTTON)) {
ballColor = r.MAROON
}
else if (r.IsMouseButtonPressed(r.MOUSE_MIDDLE_BUTTON)) {
{
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))
{
player.x += 2; // Player movement
camera.offset.x -= 2; // Camera displacement with player movement
}
else if (r.IsKeyDown(r.KEY_LEFT))