Some work on the examples
This commit is contained in:
parent
ffe8091bc4
commit
42671d0195
14 changed files with 349 additions and 287 deletions
|
|
@ -1,14 +1,8 @@
|
|||
//
|
||||
// input_mouse
|
||||
// Zig version:
|
||||
// Author: Nikolas Wipper
|
||||
// Date: 2020-02-16
|
||||
//
|
||||
// raylib-zig (c) Nikolas Wipper 2023
|
||||
|
||||
const rl = @import("raylib");
|
||||
|
||||
pub fn main() anyerror!void
|
||||
{
|
||||
pub fn main() anyerror!void {
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const screenWidth = 800;
|
||||
|
|
@ -16,36 +10,39 @@ pub fn main() anyerror!void
|
|||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - mouse input");
|
||||
|
||||
var ballPosition = rl.Vector2 { .x = -100.0, .y = -100.0 };
|
||||
var ballPosition = rl.Vector2{ .x = -100.0, .y = -100.0 };
|
||||
var ballColor = rl.DARKBLUE;
|
||||
|
||||
rl.SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
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
|
||||
{
|
||||
while (!rl.WindowShouldClose()) { // Detect window close button or ESC key
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
ballPosition = rl.GetMousePosition();
|
||||
ballPosition.x = @intToFloat(f32, rl.GetMouseX());
|
||||
ballPosition.y = @intToFloat(f32, rl.GetMouseY());
|
||||
|
||||
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) { ballColor = rl.MAROON; }
|
||||
else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) { ballColor = rl.LIME; }
|
||||
else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) { ballColor = rl.DARKBLUE; }
|
||||
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
|
||||
ballColor = rl.MAROON;
|
||||
} else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
|
||||
ballColor = rl.LIME;
|
||||
} else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
|
||||
ballColor = rl.DARKBLUE;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl.BeginDrawing();
|
||||
|
||||
rl.ClearBackground(rl.RAYWHITE);
|
||||
rl.ClearBackground(rl.RAYWHITE);
|
||||
|
||||
rl.DrawCircle(@floatToInt(c_int, ballPosition.x), @floatToInt(c_int, ballPosition.y), 50, ballColor);
|
||||
//DrawCircleV(ballPosition, 40, ballColor);
|
||||
rl.DrawCircle(@floatToInt(c_int, ballPosition.x), @floatToInt(c_int, ballPosition.y), 50, ballColor);
|
||||
//DrawCircleV(ballPosition, 40, ballColor);
|
||||
|
||||
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.DARKGRAY);
|
||||
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.DARKGRAY);
|
||||
|
||||
rl.EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -53,7 +50,6 @@ pub fn main() anyerror!void
|
|||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue