Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
********************************************************************************************/
const r = require('raylib')
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450
r.InitWindow(screenWidth, screenHeight, 'raylib [shapes] example - basic shapes drawing')
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))
********************************************************************************************/
const r = require('raylib')
// Initialization
//--------------------------------------------------------------------------------------
var screenWidth = 800
var screenHeight = 450
r.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window")
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()
//----------------------------------------------------------------------------------
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
//----------------------------------------------------------------------------------
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
// 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
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
r.BeginDrawing()
********************************************************************************************/
const r = require('raylib')
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
const screenHeight = 450;
r.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing");
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,
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450
r.InitWindow(screenWidth, screenHeight, "raylib template - simple game")
var currentScreen = 'LOGO'
// TODO: Initialize all required variables and load all required data here!
var framesCounter = 0 // Useful to count frames
r.SetTargetFPS(60) // Set desired framerate (frames-per-second)
//--------------------------------------------------------------------------------------
// Main game loop
while (!r.WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
switch(currentScreen)
{
case 'LOGO':
{
// TODO: Update LOGO screen variables here!
framesCounter++ // Count frames
// Wait for 2 seconds (120 frames) before jumping to TITLE screen
if (framesCounter > 120)
{
currentScreen = 'TITLE'
}
const r = require('raylib')
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450
r.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
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)
const screenHeight = DISPLAY_HEIGHT * multiplier
// Instantiation
const cpu = new CPU(cpuInterface)
const romBuffer = new RomBuffer(fileContents)
const cpuInterface = new NativeCpuInterface()
cpu.load(romBuffer)
r.InitWindow(screenWidth, screenHeight, 'Chip8.js')
r.SetTargetFPS(60)
r.ClearBackground(r.BLACK)
let timer = 0
while (!r.WindowShouldClose()) {
timer++
if (timer % 5 === 0) {
cpu.tick()
timer = 0
}
// Interpret key data
const rawKeyPressed = r.GetKeyPressed()
const keyIndex = nativeKeyMap.findIndex(key => rawKeyPressed === key)
// Keydown event
if (keyIndex) {
cpu.interface.setKeys(keyIndex)
} else {
// Keyup event
cpu.interface.resetKeys()
)
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))
{
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)
//--------------------------------------------------------------------------------------
const screenWidth = 800
const screenHeight = 450
r.InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing")
r.InitAudioDevice() // Initialize audio device
const fxWav = r.LoadSound(__dirname + "/resources/sound.wav") // Load WAV audio file
const fxOgg = r.LoadSound(__dirname + "/resources/tanatana.ogg") // Load OGG audio file
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.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)