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,17 +1,11 @@
//
// 2d_camera
// Zig version:
// Author: Nikolas Wipper
// Date: 2020-02-16
//
// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");
const rlm = @import("raylib-math");
const MAX_BUILDINGS = 100;
pub fn main() anyerror!void
{
pub fn main() anyerror!void {
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
@ -19,14 +13,13 @@ pub fn main() anyerror!void
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - 2d camera");
var player = rl.Rectangle { .x = 400, .y = 280, .width = 40, .height = 40 };
var player = rl.Rectangle{ .x = 400, .y = 280, .width = 40, .height = 40 };
var buildings: [MAX_BUILDINGS]rl.Rectangle = undefined;
var buildColors: [MAX_BUILDINGS]rl.Color = undefined;
var spacing: i32 = 0;
for (buildings) |_, i|
{
for (buildings) |_, i| {
buildings[i].width = @intToFloat(f32, rl.GetRandomValue(50, 200));
buildings[i].height = @intToFloat(f32, rl.GetRandomValue(100, 800));
buildings[i].y = screenHeight - 130 - buildings[i].height;
@ -34,36 +27,40 @@ pub fn main() anyerror!void
spacing += @floatToInt(i32, buildings[i].width);
buildColors[i] = rl.Color { .r = @intCast(u8, rl.GetRandomValue(200, 240)), .g = @intCast(u8, rl.GetRandomValue(200, 240)),
.b = @intCast(u8, rl.GetRandomValue(200, 250)), .a = 255 };
buildColors[i] = rl.Color{ .r = @intCast(u8, rl.GetRandomValue(200, 240)), .g = @intCast(u8, rl.GetRandomValue(200, 240)), .b = @intCast(u8, rl.GetRandomValue(200, 250)), .a = 255 };
}
var camera = rl.Camera2D {
.target = rl.Vector2 { .x = player.x + 20, .y = player.y + 20 },
.offset = rl.Vector2 { .x = screenWidth/2, .y = screenHeight/2 },
var camera = rl.Camera2D{
.target = rl.Vector2{ .x = player.x + 20, .y = player.y + 20 },
.offset = rl.Vector2{ .x = screenWidth / 2, .y = screenHeight / 2 },
.rotation = 0,
.zoom = 1,
};
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
//----------------------------------------------------------------------------------
// Player movement
if (rl.IsKeyDown(rl.KeyboardKey.KEY_RIGHT)) { player.x += 2; }
else if (rl.IsKeyDown(rl.KeyboardKey.KEY_LEFT)) { player.x -= 2; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_RIGHT)) {
player.x += 2;
} else if (rl.IsKeyDown(rl.KeyboardKey.KEY_LEFT)) {
player.x -= 2;
}
// Camera target follows player
camera.target = rl.Vector2 { .x = player.x + 20, .y = player.y + 20 };
camera.target = rl.Vector2{ .x = player.x + 20, .y = player.y + 20 };
// Camera rotation controls
if (rl.IsKeyDown(rl.KeyboardKey.KEY_A)) { camera.rotation -= 1; }
else if (rl.IsKeyDown(rl.KeyboardKey.KEY_S)) { camera.rotation += 1; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_A)) {
camera.rotation -= 1;
} else if (rl.IsKeyDown(rl.KeyboardKey.KEY_S)) {
camera.rotation += 1;
}
// Limit camera rotation to 80 degrees (-40 to 40)
camera.rotation = rlm.Clamp(camera.rotation, -40, 40);
@ -74,8 +71,7 @@ pub fn main() anyerror!void
camera.zoom = rlm.Clamp(camera.zoom, 0.1, 3.0);
// Camera reset (zoom and rotation)
if (rl.IsKeyPressed(rl.KeyboardKey.KEY_R))
{
if (rl.IsKeyPressed(rl.KeyboardKey.KEY_R)) {
camera.zoom = 1.0;
camera.rotation = 0.0;
}
@ -85,39 +81,38 @@ pub fn main() anyerror!void
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
rl.ClearBackground(rl.RAYWHITE);
camera.Begin();
camera.begin();
rl.DrawRectangle(-6000, 320, 13000, 8000, rl.DARKGRAY);
rl.DrawRectangle(-6000, 320, 13000, 8000, rl.DARKGRAY);
for (buildings) |building, i|
{
rl.DrawRectangleRec(building, buildColors[i]);
}
for (buildings) |building, i| {
rl.DrawRectangleRec(building, buildColors[i]);
}
rl.DrawRectangleRec(player, rl.RED);
rl.DrawRectangleRec(player, rl.RED);
rl.DrawLine(@floatToInt(c_int, camera.target.x), -screenHeight*10, @floatToInt(c_int, camera.target.x), screenHeight*10, rl.GREEN);
rl.DrawLine(-screenWidth*10, @floatToInt(c_int, camera.target.y), screenWidth*10, @floatToInt(c_int, camera.target.y), rl.GREEN);
rl.DrawLine(@floatToInt(c_int, camera.target.x), -screenHeight * 10, @floatToInt(c_int, camera.target.x), screenHeight * 10, rl.GREEN);
rl.DrawLine(-screenWidth * 10, @floatToInt(c_int, camera.target.y), screenWidth * 10, @floatToInt(c_int, camera.target.y), rl.GREEN);
camera.End();
camera.end();
rl.DrawText("SCREEN AREA", 640, 10, 20, rl.RED);
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(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, 113, rl.Fade(rl.SKYBLUE, 0.5));
rl.DrawRectangleLines( 10, 10, 250, 113, rl.BLUE);
rl.DrawRectangle(10, 10, 250, 113, rl.Fade(rl.SKYBLUE, 0.5));
rl.DrawRectangleLines(10, 10, 250, 113, rl.BLUE);
rl.DrawText("Free 2d camera controls:", 20, 20, 10, rl.BLACK);
rl.DrawText("- Right/Left to move Offset", 40, 40, 10, rl.DARKGRAY);
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rl.DARKGRAY);
rl.DrawText("- A / S to Rotate", 40, 80, 10, rl.DARKGRAY);
rl.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, rl.DARKGRAY);
rl.DrawText("Free 2d camera controls:", 20, 20, 10, rl.BLACK);
rl.DrawText("- Right/Left to move Offset", 40, 40, 10, rl.DARKGRAY);
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rl.DARKGRAY);
rl.DrawText("- A / S to Rotate", 40, 80, 10, rl.DARKGRAY);
rl.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, rl.DARKGRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------
@ -125,6 +120,6 @@ pub fn main() anyerror!void
// De-Initialization
//--------------------------------------------------------------------------------------
rl.CloseWindow(); // Close window and OpenGL context
rl.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View file

@ -0,0 +1,83 @@
// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");
const rlm = @import("raylib-math");
const MAX_COLUMNS = 20;
pub fn main() anyerror!void {
// Initialization
//--------------------------------------------------------------------------------------
const screenWidth = 800;
const screenHeight = 450;
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - 3d camera first person");
var camera = rl.Camera3D{
.position = rl.Vector3{ .x = 4, .y = 2, .z = 4 },
.target = rl.Vector3{ .x = 0, .y = 1.8, .z = 0 },
.up = rl.Vector3{ .x = 0, .y = 1, .z = 0 },
.fovy = 60,
.projection = rl.CameraProjection.CAMERA_PERSPECTIVE,
};
var heights: [MAX_COLUMNS]f32 = undefined;
var positions: [MAX_COLUMNS]rl.Vector3 = undefined;
var colors: [MAX_COLUMNS]rl.Color = undefined;
for (heights) |_, i| {
heights[i] = @intToFloat(f32, rl.GetRandomValue(1, 12));
positions[i] = rl.Vector3{ .x = @intToFloat(f32, rl.GetRandomValue(-15, 15)), .y = heights[i] / 2.0, .z = @intToFloat(f32, rl.GetRandomValue(-15, 15)) };
colors[i] = rl.Color{ .r = @intCast(u8, rl.GetRandomValue(20, 255)), .g = @intCast(u8, rl.GetRandomValue(10, 55)), .b = 30, .a = 255 };
}
camera.setMode(rl.CameraMode.CAMERA_FIRST_PERSON);
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
//----------------------------------------------------------------------------------
camera.update();
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
camera.begin();
// Draw ground
rl.DrawPlane(rl.Vector3{ .x = 0.0, .y = 0.0, .z = 0.0 }, rl.Vector2{ .x = 32.0, .y = 32.0 }, rl.LIGHTGRAY);
rl.DrawCube(rl.Vector3{ .x = -16.0, .y = 2.5, .z = 0.0 }, 1.0, 5.0, 32.0, rl.BLUE); // Draw a blue wall
rl.DrawCube(rl.Vector3{ .x = 16.0, .y = 2.5, .z = 0.0 }, 1.0, 5.0, 32.0, rl.LIME); // Draw a green wall
rl.DrawCube(rl.Vector3{ .x = 0.0, .y = 2.5, .z = 16.0 }, 32.0, 5.0, 1.0, rl.GOLD); // Draw a yellow wall
// Draw some cubes around
for (heights) |height, i| {
rl.DrawCube(positions[i], 2.0, height, 2.0, colors[i]);
rl.DrawCubeWires(positions[i], 2.0, height, 2.0, rl.MAROON);
}
camera.end();
rl.DrawRectangle(10, 10, 220, 70, rl.Fade(rl.SKYBLUE, 0.5));
rl.DrawRectangleLines(10, 10, 220, 70, rl.BLUE);
rl.DrawText("First person camera default controls:", 20, 20, 10, rl.BLACK);
rl.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, rl.DARKGRAY);
rl.DrawText("- Mouse move to look around", 40, 60, 10, rl.DARKGRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View file

@ -1,9 +1,4 @@
//
// basic_window
// Zig version: 0.6.0
// Author: Nikolas Wipper
// Date: 2020-02-15
//
// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");

View file

@ -1,9 +1,4 @@
//
// input_keys
// Zig version:
// Author: Nikolas Wipper
// Date: 2020-02-16
//
// raylib-zig (c) Nikolas Wipper 2023
const rl = @import("raylib");
@ -15,31 +10,39 @@ pub fn main() anyerror!void {
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - keyboard input");
var ballPosition = rl.Vector2 { .x = screenWidth/2, .y = screenHeight/2 };
var ballPosition = rl.Vector2{ .x = screenWidth / 2, .y = screenHeight / 2 };
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
//----------------------------------------------------------------------------------
if (rl.IsKeyDown(rl.KeyboardKey.KEY_RIGHT)) { ballPosition.x += 2.0; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_LEFT)) { ballPosition.x -= 2.0; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_UP)) { ballPosition.y -= 2.0; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_DOWN)) { ballPosition.y += 2.0; }
if (rl.IsKeyDown(rl.KeyboardKey.KEY_RIGHT)) {
ballPosition.x += 2.0;
}
if (rl.IsKeyDown(rl.KeyboardKey.KEY_LEFT)) {
ballPosition.x -= 2.0;
}
if (rl.IsKeyDown(rl.KeyboardKey.KEY_UP)) {
ballPosition.y -= 2.0;
}
if (rl.IsKeyDown(rl.KeyboardKey.KEY_DOWN)) {
ballPosition.y += 2.0;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.RAYWHITE);
rl.ClearBackground(rl.RAYWHITE);
rl.DrawText("move the ball with arrow keys", 10, 10, 20, rl.DARKGRAY);
rl.DrawText("move the ball with arrow keys", 10, 10, 20, rl.DARKGRAY);
rl.DrawCircleV(ballPosition, 50, rl.MAROON);
rl.DrawCircleV(ballPosition, 50, rl.MAROON);
rl.EndDrawing();
//----------------------------------------------------------------------------------
@ -47,6 +50,6 @@ pub fn main() anyerror!void {
// De-Initialization
//--------------------------------------------------------------------------------------
rl.CloseWindow(); // Close window and OpenGL context
rl.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View file

@ -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
//--------------------------------------------------------------------------------------
}

View file

@ -1,14 +1,8 @@
//
// input_mouse_wheel
// 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;
@ -17,14 +11,13 @@ pub fn main() anyerror!void
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
var boxPositionY: f32 = screenHeight / 2 - 40;
var scrollSpeed: f32 = 4; // Scrolling speed in pixels
var scrollSpeed: f32 = 4; // Scrolling speed in pixels
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
//----------------------------------------------------------------------------------
boxPositionY -= (rl.GetMouseWheelMove() * scrollSpeed);
@ -34,12 +27,12 @@ pub fn main() anyerror!void
//----------------------------------------------------------------------------------
rl.BeginDrawing();
rl.ClearBackground(rl.WHITE);
rl.ClearBackground(rl.WHITE);
rl.DrawRectangle(screenWidth/2 - 40, @floatToInt(c_int, boxPositionY), 80, 80, rl.MAROON);
rl.DrawRectangle(screenWidth / 2 - 40, @floatToInt(c_int, boxPositionY), 80, 80, rl.MAROON);
rl.DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, rl.GRAY);
rl.DrawText(rl.TextFormat("Box position Y: %03i", @floatToInt(c_int, boxPositionY)), 10, 40, 20, rl.LIGHTGRAY);
rl.DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, rl.GRAY);
rl.DrawText(rl.TextFormat("Box position Y: %03i", @floatToInt(c_int, boxPositionY)), 10, 40, 20, rl.LIGHTGRAY);
rl.EndDrawing();
//----------------------------------------------------------------------------------
@ -47,7 +40,6 @@ pub fn main() anyerror!void
// De-Initialization
//--------------------------------------------------------------------------------------
rl.CloseWindow(); // Close window and OpenGL context
rl.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

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
//--------------------------------------------------------------------------------------
}