B:BD[
2.432] → [
2.432:468]
x := 10;
fmt.println("Hellope!");
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera")
exitWindowRequested := false // Flag to request window to exit
exitWindow := false // Flag to set window to exit
player: Player = {400, 280, 40, 40}
buildings, buildColors := generate_buildings()
camera: rl.Camera2D
camera.target = rl.Vector2({player.x + 20.0, player.y + 20.0})
camera.offset = rl.Vector2({screenWidth / 2.0, screenHeight / 2.0})
camera.rotation = 0.0
camera.zoom = 1.0
rl.SetTargetFPS(60)
for !exitWindow {
// Update
//----------------------------------------------------------------------------------
// Detect if X-button or KEY_ESCAPE have been pressed to close window
if (rl.WindowShouldClose() || rl.IsKeyPressed(rl.KeyboardKey.ESCAPE)) do exitWindowRequested = true
if (exitWindowRequested) {
// A request for close window has been issued, we can save data before closing
// or just show a message asking for confirmation
if (rl.IsKeyPressed(rl.KeyboardKey.Y) || rl.IsKeyPressed(rl.KeyboardKey.Z)) do exitWindow = true
else if (rl.IsKeyPressed(rl.KeyboardKey.N)) do exitWindowRequested = false
} else {
handle_input(&player)
}
//----------------------------------------------------------------------------------
camera.target = rl.Vector2({player.x + 20, player.y + 20})
camera.zoom += f32(rl.GetMouseWheelMove() * 0.05)
if camera.zoom > 3.0 do camera.zoom = 3.0
else if camera.zoom < 0.1 do camera.zoom = 0.1
if rl.IsKeyPressed(rl.KeyboardKey.R) {
camera.zoom = 1.0
camera.rotation = 0.0
}
rl.BeginDrawing()
rl.ClearBackground(rl.RAYWHITE)
rl.BeginMode2D(camera)
rl.DrawRectangle(-6000, 320, 13000, 8000, rl.DARKGRAY)
for i in 0 ..< MAX_BUILDINGS do rl.DrawRectangleRec(buildings[i], buildColors[i])
rl.DrawRectangleRec(rl.Rectangle(player), rl.RED)
rl.DrawLine(
i32(camera.target.x),
-screenHeight * 10,
i32(camera.target.x),
screenHeight * 10,
rl.GREEN,
)
rl.DrawLine(
-screenWidth * 10,
i32(camera.target.y),
screenWidth * 10,
i32(camera.target.y),
rl.GREEN,
)
rl.EndMode2D()
rl.DrawText("SCREEN AREA", 640, 10, 20, rl.RED)
rl.DrawRectangle(0, 0, screenWidth, 5, rl.RED)
rl.DrawRectangle(0, 5, 5, screenHeight - 10, rl.RED)
rl.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, rl.RED)
rl.DrawRectangle(0, screenHeight - 5, screenWidth, 5, rl.RED)
rl.DrawRectangle(10, 10, 250, 80, rl.Fade(rl.SKYBLUE, 0.5))
rl.DrawRectangleLines(10, 10, 250, 80, rl.BLUE)
rl.DrawText("Free 2d camera controls:", 20, 20, 10, rl.BLACK)
rl.DrawText("- WASD to move", 40, 40, 10, rl.DARKGRAY)
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rl.DARKGRAY)
if (exitWindowRequested) {
rl.DrawRectangle(0, 100, screenWidth, 200, rl.BLACK)
rl.DrawText("Are you sure you want to exit program? [Y/N]", 40, 180, 30, rl.WHITE)
}
rl.EndDrawing()
}
rl.CloseWindow()