Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
r.SetTargetFPS(60)
//--------------------------------------------------------------------------------------
// Main game loop
while (!r.WindowShouldClose()) {
// Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
r.BeginDrawing()
r.ClearBackground(r.RAYWHITE)
console.log('hello')
r.GetKeyPressed()
console.log(r.IsKeyDown(r.KEY_ONE))
// console.log(r.GetKeyPressed())
r.DrawText('some basic shapes available on raylib', 20, 20, 20, r.DARKGRAY)
var position = {
x: 100,
y: 100,
}
var size = {
x: 200,
y: 150,
r.SetTargetFPS(60)
//--------------------------------------------------------------------------------------
// Main game loop
while (!r.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
r.BeginDrawing()
r.ClearBackground(r.RAYWHITE)
r.DrawText("Congrats! You created your first window!", 190, 200, 20, r.LIGHTGRAY)
r.EndDrawing()
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
r.CloseWindow() // Close window and OpenGL context
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Main game loop
while (!r.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (r.IsKeyPressed(r.KEY_SPACE)) r.PlaySound(fxWav) // Play WAV sound
if (r.IsKeyPressed(r.KEY_ENTER)) r.PlaySound(fxOgg) // Play OGG sound
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
r.BeginDrawing()
r.ClearBackground(r.RAYWHITE)
r.DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, r.LIGHTGRAY)
r.DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, r.LIGHTGRAY)
r.EndDrawing()
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
r.UnloadSound(fxWav) // Unload sound data
r.UnloadSound(fxOgg) // Unload sound data
r.CloseAudioDevice() // Close audio device
r.CloseWindow() // Close window and OpenGL context
const texture = r.LoadTexture(__dirname + "/resources/raylib_logo.png") // Texture loading
//---------------------------------------------------------------------------------------
// Main game loop
while (!r.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
r.BeginDrawing()
r.ClearBackground(r.RAYWHITE)
r.DrawTexture(texture, screenWidth / 2 - texture.width / 2, screenHeight / 2 - texture.height / 2, r.WHITE)
r.DrawText("this IS a texture!", 360, 370, 10, r.GRAY)
r.EndDrawing()
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
r.UnloadTexture(texture) // Texture unloading
r.CloseWindow() // Close window and OpenGL context
//--------------------------------------------------------------------------------------
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
//----------------------------------------------------------------------------------
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();
//----------------------------------------------------------------------------------
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()
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
r.CloseWindow() // Close window and OpenGL context
//--------------------------------------------------------------------------------------
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)
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
r.BeginDrawing()
r.ClearBackground(r.RAYWHITE)
r.BeginMode3D(camera)
r.DrawCube(cubePosition, 2, 2, 2, r.RED);
r.DrawCubeWires(cubePosition, 2, 2, 2, r.MAROON);
r.DrawGrid(10, 1);
r.EndMode3D();
r.DrawText("Enemy: 100 / 100", cubeScreenPosition.x - r.MeasureText("Enemy: 100 / 100", 20) / 2, cubeScreenPosition.y, 20, r.BLACK);
r.DrawText("Text is always on top of the cube", (screenWidth - r.MeasureText("Text is always on top of the cube", 20)) / 2, 25, 20, r.GRAY);
r.EndDrawing();
//----------------------------------------------------------------------------------
}
if (camera.zoom > 3) camera.zoom = 3
else if (camera.zoom < 0.1) camera.zoom = 0.1
// Camera reset (zoom and rotation)
if (r.IsKeyPressed(r.KEY_R))
{
camera.zoom = 1.0
camera.rotation = 0
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
r.BeginDrawing();
r.ClearBackground(r.RAYWHITE);
r.BeginMode2D(camera);
r.DrawRectangle(-6000, 320, 13000, 8000, r.DARKGRAY);
for (var i = 0; i < MAX_BUILDINGS; i++) {
r.DrawRectangleRec(buildings[i], buildColors[i]);
}
r.DrawRectangleRec(player, r.RED);
r.DrawLine(camera.target.x, -screenHeight*10, camera.target.x, screenHeight*10, r.GREEN);
r.DrawLine(-screenWidth*10, camera.target.y, screenWidth*10, camera.target.y, r.GREEN);
r.EndMode2D();
r.SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!r.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
r.BeginDrawing();
r.ClearBackground(r.RAYWHITE);
r.DrawText("some basic shapes available on raylib", 20, 20, 20, r.DARKGRAY);
var position = {
x: 100,
y: 100
}
var size = {
x: 200,
y: 150
}
r.DrawRectangleV(position, size, r.DARKBLUE)
r.DrawRectangleRec({
x: 50,
y: 50,
if (r.IsMouseButtonPressed(r.MOUSE_LEFT_BUTTON)) {
ballColor = r.MAROON
}
else if (r.IsMouseButtonPressed(r.MOUSE_MIDDLE_BUTTON)) {
ballColor = r.LIME
}
else if (r.IsMouseButtonPressed(r.MOUSE_RIGHT_BUTTON)) {
ballColor = r.DARKBLUE
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
r.BeginDrawing()
r.ClearBackground(r.RAYWHITE)
r.DrawCircleV(ballPosition, 40, ballColor)
r.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, r.DARKGRAY)
r.EndDrawing()
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
r.CloseWindow() // Close window and OpenGL context
//--------------------------------------------------------------------------------------