Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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.DrawText("SCREEN AREA", 640, 10, 20, r.RED);
r.DrawRectangle(0, 0, screenWidth, 5, r.RED);
r.DrawRectangle(0, 5, 5, screenHeight - 10, r.RED);
r.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, r.RED);
r.DrawRectangle(0, screenHeight - 5, screenWidth, 5, r.RED);
r.DrawRectangle( 10, 10, 250, 113, r.Fade(r.SKYBLUE, 0.5));
r.DrawRectangleLines( 10, 10, 250, 113, r.BLUE);
r.DrawText("Free 2d camera controls:", 20, 20, 10, r.BLACK);
r.DrawText("- Right/Left to move Offset", 40, 40, 10, r.DARKGRAY);
r.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, r.DARKGRAY);
r.DrawText("- A / S to Rotate", 40, 80, 10, r.DARKGRAY);
r.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, r.DARKGRAY);
r.EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
r.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
const nativeKeyMap = require('../data/nativeKeyMap')
const multiplier = 10
const screenWidth = DISPLAY_WIDTH * multiplier
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) {
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);
r.DrawText("First person camera default controls:", 20, 20, 10, r.BLACK);
r.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, r.DARKGRAY);
r.DrawText("- Mouse move to look around", 40, 60, 10, r.DARKGRAY);
r.EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
r.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
// 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();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
r.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
x: j * multiplier,
y: i * multiplier,
width: multiplier,
height: multiplier,
},
r.GREEN
)
} else {
r.DrawRectangleRec(
{
x: j * multiplier,
y: i * multiplier,
width: multiplier,
height: multiplier,
},
r.BLACK
)
}
})
})