raylib-zig/examples/core/input_mouse_wheel.zig
vent a378960088 Clean up build.zig and examples
This commit affects the build.zig and examples files. It reformats the
code to meet a 120 column limit. It also adjusts comments so that
there is a space after the comment symbol '//' and the grammar in the
comments has been fixed.
2023-09-11 16:04:32 +01:00

49 lines
1.8 KiB
Zig
Executable File

// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");
const std = @import("std");
pub fn main() anyerror!void {
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
const screenHeight = 450;
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
defer rl.closeWindow(); // Close window and OpenGL context
var boxPositionY: f32 = screenHeight / 2 - 40;
var scrollSpeed: f32 = 4; // Scrolling speed in pixels
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!rl.windowShouldClose()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
boxPositionY -= (rl.getMouseWheelMove() * scrollSpeed);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.white);
rl.drawRectangle(screenWidth / 2 - 40, @as(i32, @intFromFloat(boxPositionY)), 80, 80, rl.Color.maroon);
rl.drawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, rl.Color.gray);
rl.drawText(
rl.textFormat("Box position Y: %03i", .{@as(i32, @intFromFloat(boxPositionY))}),
10,
40,
20,
rl.Color.light_gray,
);
//----------------------------------------------------------------------------------
}
}