mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 12:07:27 +00:00

some restructuring due to the recent changes to usingnamespace. also cleaned up some deprecated stuff from raylib 3.7. - appended the contents of raylib-wa.zig into raylib-zig.zig - using raylib functions requires `const rl = @import("raylib");` (and accesing the identifiers inside rl, like `rl.InitWindow`) only the basic_window example was updated, and it looks like it crashes on keyboard inputs. many thanks to @nektro :)
60 lines
2.2 KiB
Zig
Executable File
60 lines
2.2 KiB
Zig
Executable File
//
|
|
// input_mouse
|
|
// Zig version:
|
|
// Author: Nikolas Wipper
|
|
// Date: 2020-02-16
|
|
//
|
|
|
|
usingnamespace @import("raylib");
|
|
|
|
pub fn main() anyerror!void
|
|
{
|
|
// Initialization
|
|
//--------------------------------------------------------------------------------------
|
|
const screenWidth = 800;
|
|
const screenHeight = 450;
|
|
|
|
InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - mouse input");
|
|
|
|
var ballPosition = Vector2 { .x = -100.0, .y = -100.0 };
|
|
var ballColor = DARKBLUE;
|
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
// Main game loop
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
{
|
|
// Update
|
|
//----------------------------------------------------------------------------------
|
|
ballPosition = GetMousePosition();
|
|
ballPosition.x = @intToFloat(f32, GetMouseX());
|
|
ballPosition.y = @intToFloat(f32, GetMouseY());
|
|
|
|
if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) { ballColor = MAROON; }
|
|
else if (IsMouseButtonPressed(MouseButton.MOUSE_MIDDLE_BUTTON)) { ballColor = LIME; }
|
|
else if (IsMouseButtonPressed(MouseButton.MOUSE_RIGHT_BUTTON)) { ballColor = DARKBLUE; }
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Draw
|
|
//----------------------------------------------------------------------------------
|
|
BeginDrawing();
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
DrawCircle(@floatToInt(c_int, ballPosition.x), @floatToInt(c_int, ballPosition.y), 50, ballColor);
|
|
//DrawCircleV(ballPosition, 40, ballColor);
|
|
|
|
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
|
|
|
|
EndDrawing();
|
|
//----------------------------------------------------------------------------------
|
|
}
|
|
|
|
// De-Initialization
|
|
//--------------------------------------------------------------------------------------
|
|
CloseWindow(); // Close window and OpenGL context
|
|
//--------------------------------------------------------------------------------------
|
|
}
|
|
|