Some work on the examples

This commit is contained in:
Not-Nik 2023-07-09 18:45:15 +02:00
parent ffe8091bc4
commit 42671d0195
Failed to generate hash of commit
14 changed files with 349 additions and 287 deletions

View file

@ -1,14 +1,8 @@
//
// input_multitouch
// 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,59 +10,72 @@ pub fn main() anyerror!void
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
var ballPosition = rl.Vector2 { .x = -100.0, .y = -100.0 };
var ballPosition = rl.Vector2{ .x = -100.0, .y = -100.0 };
var ballColor = rl.BEIGE;
var touchCounter: f32 = 0;
var touchPosition = rl.Vector2 { .x = 0.0, .y = 0.0 };
var touchPosition = rl.Vector2{ .x = 0.0, .y = 0.0 };
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();
ballColor = rl.BEIGE;
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_LEFT)) { ballColor = rl.MAROON; }
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) { ballColor = rl.LIME; }
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_RIGHT)) { ballColor = rl.DARKBLUE; }
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
ballColor = rl.MAROON;
}
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
ballColor = rl.LIME;
}
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
ballColor = rl.DARKBLUE;
}
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) { touchCounter = 10; }
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) { touchCounter = 10; }
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) { touchCounter = 10; }
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
touchCounter = 10;
}
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
touchCounter = 10;
}
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
touchCounter = 10;
}
if (touchCounter > 0) { touchCounter -= 1; }
if (touchCounter > 0) {
touchCounter -= 1;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
rl.ClearBackground(rl.RAYWHITE);
const nums = [_]i32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for (nums) |i|
{
touchPosition = rl.GetTouchPosition(i); // Get the touch point
const nums = [_]i32{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (nums) |i| {
touchPosition = rl.GetTouchPosition(i); // Get the touch point
if ((touchPosition.x >= 0) and (touchPosition.y >= 0)) // Make sure point is not (-1,-1) as this means there is no touch for it
{
// Draw circle and touch index number
rl.DrawCircleV(touchPosition, 34, rl.ORANGE);
rl.DrawText(rl.TextFormat("%d", i), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, rl.BLACK);
}
// Make sure point is not (-1,-1) as this means there is no touch for it
if ((touchPosition.x >= 0) and (touchPosition.y >= 0)) {
// Draw circle and touch index number
rl.DrawCircleV(touchPosition, 34, rl.ORANGE);
rl.DrawText(rl.TextFormat("%d", i), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, rl.BLACK);
}
}
// Draw the normal mouse location
rl.DrawCircleV(ballPosition, 30 + (touchCounter*3), ballColor);
// Draw the normal mouse location
rl.DrawCircleV(ballPosition, 30 + (touchCounter * 3), ballColor);
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.DARKGRAY);
rl.DrawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, rl.DARKGRAY);
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.DARKGRAY);
rl.DrawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, rl.DARKGRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------
@ -76,7 +83,6 @@ pub fn main() anyerror!void
// De-Initialization
//--------------------------------------------------------------------------------------
rl.CloseWindow(); // Close window and OpenGL context
rl.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}