Map C pointers to Zig and functions names use Zig naming conventions
This commit is contained in:
parent
c564af4f61
commit
e29e012981
18 changed files with 3510 additions and 879 deletions
|
|
@ -11,7 +11,7 @@ pub fn main() anyerror!void {
|
|||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - 2d camera");
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - 2d camera");
|
||||
|
||||
var player = rl.Rectangle{ .x = 400, .y = 280, .width = 40, .height = 40 };
|
||||
var buildings: [MAX_BUILDINGS]rl.Rectangle = undefined;
|
||||
|
|
@ -20,14 +20,14 @@ pub fn main() anyerror!void {
|
|||
var spacing: i32 = 0;
|
||||
|
||||
for (buildings) |_, i| {
|
||||
buildings[i].width = @intToFloat(f32, rl.GetRandomValue(50, 200));
|
||||
buildings[i].height = @intToFloat(f32, rl.GetRandomValue(100, 800));
|
||||
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;
|
||||
buildings[i].x = @intToFloat(f32, -6000 + spacing);
|
||||
|
||||
spacing += @floatToInt(i32, buildings[i].width);
|
||||
|
||||
buildColors[i] = rl.Color.init(@intCast(u8, rl.GetRandomValue(200, 240)), @intCast(u8, rl.GetRandomValue(200, 240)), @intCast(u8, rl.GetRandomValue(200, 250)), 255);
|
||||
buildColors[i] = rl.Color.init(@intCast(u8, rl.getRandomValue(200, 240)), @intCast(u8, rl.getRandomValue(200, 240)), @intCast(u8, rl.getRandomValue(200, 250)), 255);
|
||||
}
|
||||
|
||||
var camera = rl.Camera2D{
|
||||
|
|
@ -37,18 +37,18 @@ pub fn main() anyerror!void {
|
|||
.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)) {
|
||||
if (rl.isKeyDown(rl.KeyboardKey.KEY_RIGHT)) {
|
||||
player.x += 2;
|
||||
} else if (rl.IsKeyDown(rl.KeyboardKey.KEY_LEFT)) {
|
||||
} else if (rl.isKeyDown(rl.KeyboardKey.KEY_LEFT)) {
|
||||
player.x -= 2;
|
||||
}
|
||||
|
||||
|
|
@ -56,22 +56,22 @@ pub fn main() anyerror!void {
|
|||
camera.target = rl.Vector2.init(player.x + 20, player.y + 20);
|
||||
|
||||
// Camera rotation controls
|
||||
if (rl.IsKeyDown(rl.KeyboardKey.KEY_A)) {
|
||||
if (rl.isKeyDown(rl.KeyboardKey.KEY_A)) {
|
||||
camera.rotation -= 1;
|
||||
} else if (rl.IsKeyDown(rl.KeyboardKey.KEY_S)) {
|
||||
} 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);
|
||||
camera.rotation = rlm.clamp(camera.rotation, -40, 40);
|
||||
|
||||
// Camera zoom controls
|
||||
camera.zoom += rl.GetMouseWheelMove() * 0.05;
|
||||
camera.zoom += rl.getMouseWheelMove() * 0.05;
|
||||
|
||||
camera.zoom = rlm.Clamp(camera.zoom, 0.1, 3.0);
|
||||
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;
|
||||
}
|
||||
|
|
@ -79,47 +79,47 @@ pub fn main() anyerror!void {
|
|||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl.BeginDrawing();
|
||||
rl.beginDrawing();
|
||||
|
||||
rl.ClearBackground(rl.Color.RAYWHITE);
|
||||
rl.clearBackground(rl.Color.RAYWHITE);
|
||||
|
||||
camera.begin();
|
||||
|
||||
rl.DrawRectangle(-6000, 320, 13000, 8000, rl.Color.DARKGRAY);
|
||||
rl.drawRectangle(-6000, 320, 13000, 8000, rl.Color.DARKGRAY);
|
||||
|
||||
for (buildings) |building, i| {
|
||||
rl.DrawRectangleRec(building, buildColors[i]);
|
||||
rl.drawRectangleRec(building, buildColors[i]);
|
||||
}
|
||||
|
||||
rl.DrawRectangleRec(player, rl.Color.RED);
|
||||
rl.drawRectangleRec(player, rl.Color.RED);
|
||||
|
||||
rl.DrawLine(@floatToInt(c_int, camera.target.x), -screenHeight * 10, @floatToInt(c_int, camera.target.x), screenHeight * 10, rl.Color.GREEN);
|
||||
rl.DrawLine(-screenWidth * 10, @floatToInt(c_int, camera.target.y), screenWidth * 10, @floatToInt(c_int, camera.target.y), rl.Color.GREEN);
|
||||
rl.drawLine(@floatToInt(c_int, camera.target.x), -screenHeight * 10, @floatToInt(c_int, camera.target.x), screenHeight * 10, rl.Color.GREEN);
|
||||
rl.drawLine(-screenWidth * 10, @floatToInt(c_int, camera.target.y), screenWidth * 10, @floatToInt(c_int, camera.target.y), rl.Color.GREEN);
|
||||
|
||||
camera.end();
|
||||
|
||||
rl.DrawText("SCREEN AREA", 640, 10, 20, rl.Color.RED);
|
||||
rl.drawText("SCREEN AREA", 640, 10, 20, rl.Color.RED);
|
||||
|
||||
rl.DrawRectangle(0, 0, screenWidth, 5, rl.Color.RED);
|
||||
rl.DrawRectangle(0, 5, 5, screenHeight - 10, rl.Color.RED);
|
||||
rl.DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, rl.Color.RED);
|
||||
rl.DrawRectangle(0, screenHeight - 5, screenWidth, 5, rl.Color.RED);
|
||||
rl.drawRectangle(0, 0, screenWidth, 5, rl.Color.RED);
|
||||
rl.drawRectangle(0, 5, 5, screenHeight - 10, rl.Color.RED);
|
||||
rl.drawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, rl.Color.RED);
|
||||
rl.drawRectangle(0, screenHeight - 5, screenWidth, 5, rl.Color.RED);
|
||||
|
||||
rl.DrawRectangle(10, 10, 250, 113, rl.Fade(rl.Color.SKYBLUE, 0.5));
|
||||
rl.DrawRectangleLines(10, 10, 250, 113, rl.Color.BLUE);
|
||||
rl.drawRectangle(10, 10, 250, 113, rl.fade(rl.Color.SKYBLUE, 0.5));
|
||||
rl.drawRectangleLines(10, 10, 250, 113, rl.Color.BLUE);
|
||||
|
||||
rl.DrawText("Free 2d camera controls:", 20, 20, 10, rl.Color.BLACK);
|
||||
rl.DrawText("- Right/Left to move Offset", 40, 40, 10, rl.Color.DARKGRAY);
|
||||
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rl.Color.DARKGRAY);
|
||||
rl.DrawText("- A / S to Rotate", 40, 80, 10, rl.Color.DARKGRAY);
|
||||
rl.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, rl.Color.DARKGRAY);
|
||||
rl.drawText("Free 2d camera controls:", 20, 20, 10, rl.Color.BLACK);
|
||||
rl.drawText("- Right/Left to move Offset", 40, 40, 10, rl.Color.DARKGRAY);
|
||||
rl.drawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rl.Color.DARKGRAY);
|
||||
rl.drawText("- A / S to Rotate", 40, 80, 10, rl.Color.DARKGRAY);
|
||||
rl.drawText("- R to reset Zoom and Rotation", 40, 100, 10, rl.Color.DARKGRAY);
|
||||
|
||||
rl.EndDrawing();
|
||||
rl.endDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
rl.closeWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// raylib-zig (c) Nikolas Wipper 2023
|
||||
|
||||
const rl = @import("raylib");
|
||||
const rlm = @import("raylib-math");
|
||||
|
||||
const MAX_COLUMNS = 20;
|
||||
|
||||
|
|
@ -11,7 +10,7 @@ pub fn main() anyerror!void {
|
|||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - 3d camera first person");
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - 3d camera first person");
|
||||
|
||||
var camera = rl.Camera3D{
|
||||
.position = rl.Vector3.init(4, 2, 4),
|
||||
|
|
@ -26,18 +25,18 @@ pub fn main() anyerror!void {
|
|||
var colors: [MAX_COLUMNS]rl.Color = undefined;
|
||||
|
||||
for (heights) |_, i| {
|
||||
heights[i] = @intToFloat(f32, rl.GetRandomValue(1, 12));
|
||||
positions[i] = rl.Vector3.init(@intToFloat(f32, rl.GetRandomValue(-15, 15)), heights[i] / 2.0, @intToFloat(f32, rl.GetRandomValue(-15, 15)));
|
||||
colors[i] = rl.Color.init(@intCast(u8, rl.GetRandomValue(20, 255)), @intCast(u8, rl.GetRandomValue(10, 55)), 30, 255);
|
||||
heights[i] = @intToFloat(f32, rl.getRandomValue(1, 12));
|
||||
positions[i] = rl.Vector3.init(@intToFloat(f32, rl.getRandomValue(-15, 15)), heights[i] / 2.0, @intToFloat(f32, rl.getRandomValue(-15, 15)));
|
||||
colors[i] = rl.Color.init(@intCast(u8, rl.getRandomValue(20, 255)), @intCast(u8, rl.getRandomValue(10, 55)), 30, 255);
|
||||
}
|
||||
|
||||
camera.setMode(rl.CameraMode.CAMERA_FIRST_PERSON);
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
camera.update();
|
||||
|
|
@ -45,39 +44,39 @@ pub fn main() anyerror!void {
|
|||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl.BeginDrawing();
|
||||
rl.beginDrawing();
|
||||
|
||||
rl.ClearBackground(rl.Color.RAYWHITE);
|
||||
rl.clearBackground(rl.Color.RAYWHITE);
|
||||
|
||||
camera.begin();
|
||||
|
||||
// Draw ground
|
||||
rl.DrawPlane(rl.Vector3.init(0, 0, 0), rl.Vector2.init(32, 32), rl.Color.LIGHTGRAY);
|
||||
rl.DrawCube(rl.Vector3.init(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Color.BLUE); // Draw a blue wall
|
||||
rl.DrawCube(rl.Vector3.init(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Color.LIME); // Draw a green wall
|
||||
rl.DrawCube(rl.Vector3.init(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.Color.GOLD); // Draw a yellow wall
|
||||
rl.drawPlane(rl.Vector3.init(0, 0, 0), rl.Vector2.init(32, 32), rl.Color.LIGHTGRAY);
|
||||
rl.drawCube(rl.Vector3.init(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Color.BLUE); // Draw a blue wall
|
||||
rl.drawCube(rl.Vector3.init(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Color.LIME); // Draw a green wall
|
||||
rl.drawCube(rl.Vector3.init(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.Color.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.Color.MAROON);
|
||||
rl.drawCube(positions[i], 2.0, height, 2.0, colors[i]);
|
||||
rl.drawCubeWires(positions[i], 2.0, height, 2.0, rl.Color.MAROON);
|
||||
}
|
||||
|
||||
camera.end();
|
||||
|
||||
rl.DrawRectangle(10, 10, 220, 70, rl.Fade(rl.Color.SKYBLUE, 0.5));
|
||||
rl.DrawRectangleLines(10, 10, 220, 70, rl.Color.BLUE);
|
||||
rl.drawRectangle(10, 10, 220, 70, rl.fade(rl.Color.SKYBLUE, 0.5));
|
||||
rl.drawRectangleLines(10, 10, 220, 70, rl.Color.BLUE);
|
||||
|
||||
rl.DrawText("First person camera default controls:", 20, 20, 10, rl.Color.BLACK);
|
||||
rl.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, rl.Color.DARKGRAY);
|
||||
rl.DrawText("- Mouse move to look around", 40, 60, 10, rl.Color.DARKGRAY);
|
||||
rl.drawText("First person camera default controls:", 20, 20, 10, rl.Color.BLACK);
|
||||
rl.drawText("- Move with keys: W, A, S, D", 40, 40, 10, rl.Color.DARKGRAY);
|
||||
rl.drawText("- Mouse move to look around", 40, 60, 10, rl.Color.DARKGRAY);
|
||||
|
||||
rl.EndDrawing();
|
||||
rl.endDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
rl.closeWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ pub fn main() anyerror!void {
|
|||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
|
|
@ -22,18 +22,18 @@ pub fn main() anyerror!void {
|
|||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl.BeginDrawing();
|
||||
rl.beginDrawing();
|
||||
|
||||
rl.ClearBackground(rl.Color.WHITE);
|
||||
rl.clearBackground(rl.Color.WHITE);
|
||||
|
||||
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.LIGHTGRAY);
|
||||
rl.drawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.LIGHTGRAY);
|
||||
|
||||
rl.EndDrawing();
|
||||
rl.endDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
rl.closeWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,48 +8,48 @@ pub fn main() anyerror!void {
|
|||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - keyboard input");
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - keyboard input");
|
||||
|
||||
var ballPosition = rl.Vector2.init(screenWidth / 2, 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)) {
|
||||
if (rl.isKeyDown(rl.KeyboardKey.KEY_RIGHT)) {
|
||||
ballPosition.x += 2.0;
|
||||
}
|
||||
if (rl.IsKeyDown(rl.KeyboardKey.KEY_LEFT)) {
|
||||
if (rl.isKeyDown(rl.KeyboardKey.KEY_LEFT)) {
|
||||
ballPosition.x -= 2.0;
|
||||
}
|
||||
if (rl.IsKeyDown(rl.KeyboardKey.KEY_UP)) {
|
||||
if (rl.isKeyDown(rl.KeyboardKey.KEY_UP)) {
|
||||
ballPosition.y -= 2.0;
|
||||
}
|
||||
if (rl.IsKeyDown(rl.KeyboardKey.KEY_DOWN)) {
|
||||
if (rl.isKeyDown(rl.KeyboardKey.KEY_DOWN)) {
|
||||
ballPosition.y += 2.0;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl.BeginDrawing();
|
||||
rl.beginDrawing();
|
||||
|
||||
rl.ClearBackground(rl.Color.RAYWHITE);
|
||||
rl.clearBackground(rl.Color.RAYWHITE);
|
||||
|
||||
rl.DrawText("move the ball with arrow keys", 10, 10, 20, rl.Color.DARKGRAY);
|
||||
rl.drawText("move the ball with arrow keys", 10, 10, 20, rl.Color.DARKGRAY);
|
||||
|
||||
rl.DrawCircleV(ballPosition, 50, rl.Color.MAROON);
|
||||
rl.drawCircleV(ballPosition, 50, rl.Color.MAROON);
|
||||
|
||||
rl.EndDrawing();
|
||||
rl.endDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
rl.closeWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,48 +8,48 @@ pub fn main() anyerror!void {
|
|||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - mouse input");
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - mouse input");
|
||||
|
||||
var ballPosition = rl.Vector2.init(-100, -100);
|
||||
var ballColor = rl.Color.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());
|
||||
ballPosition = rl.getMousePosition();
|
||||
ballPosition.x = @intToFloat(f32, rl.getMouseX());
|
||||
ballPosition.y = @intToFloat(f32, rl.getMouseY());
|
||||
|
||||
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
|
||||
if (rl.isMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
|
||||
ballColor = rl.Color.MAROON;
|
||||
} else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
|
||||
} else if (rl.isMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
|
||||
ballColor = rl.Color.LIME;
|
||||
} else if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
|
||||
} else if (rl.isMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
|
||||
ballColor = rl.Color.DARKBLUE;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl.BeginDrawing();
|
||||
rl.beginDrawing();
|
||||
|
||||
rl.ClearBackground(rl.Color.RAYWHITE);
|
||||
rl.clearBackground(rl.Color.RAYWHITE);
|
||||
|
||||
rl.DrawCircle(@floatToInt(c_int, ballPosition.x), @floatToInt(c_int, ballPosition.y), 50, 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.Color.DARKGRAY);
|
||||
rl.drawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.Color.DARKGRAY);
|
||||
|
||||
rl.EndDrawing();
|
||||
rl.endDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
rl.closeWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,38 +8,38 @@ pub fn main() anyerror!void {
|
|||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
|
||||
|
||||
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
|
||||
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);
|
||||
boxPositionY -= (rl.getMouseWheelMove() * scrollSpeed);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl.BeginDrawing();
|
||||
rl.beginDrawing();
|
||||
|
||||
rl.ClearBackground(rl.Color.WHITE);
|
||||
rl.clearBackground(rl.Color.WHITE);
|
||||
|
||||
rl.DrawRectangle(screenWidth / 2 - 40, @floatToInt(c_int, boxPositionY), 80, 80, rl.Color.MAROON);
|
||||
rl.drawRectangle(screenWidth / 2 - 40, @floatToInt(c_int, 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", @floatToInt(c_int, boxPositionY)), 10, 40, 20, rl.Color.LIGHTGRAY);
|
||||
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", .{@floatToInt(c_int, boxPositionY)}), 10, 40, 20, rl.Color.LIGHTGRAY);
|
||||
|
||||
rl.EndDrawing();
|
||||
rl.endDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
rl.closeWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ pub fn main() anyerror!void {
|
|||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
|
||||
|
||||
var ballPosition = rl.Vector2.init(-100, -100);
|
||||
var ballColor = rl.Color.BEIGE;
|
||||
|
|
@ -16,34 +16,34 @@ pub fn main() anyerror!void {
|
|||
var touchCounter: f32 = 0;
|
||||
var touchPosition = rl.Vector2.init(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();
|
||||
ballPosition = rl.getMousePosition();
|
||||
|
||||
ballColor = rl.Color.BEIGE;
|
||||
|
||||
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
|
||||
if (rl.isMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
|
||||
ballColor = rl.Color.MAROON;
|
||||
}
|
||||
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
|
||||
if (rl.isMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
|
||||
ballColor = rl.Color.LIME;
|
||||
}
|
||||
if (rl.IsMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
|
||||
if (rl.isMouseButtonDown(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
|
||||
ballColor = rl.Color.DARKBLUE;
|
||||
}
|
||||
|
||||
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
|
||||
if (rl.isMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_LEFT)) {
|
||||
touchCounter = 10;
|
||||
}
|
||||
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
|
||||
if (rl.isMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_MIDDLE)) {
|
||||
touchCounter = 10;
|
||||
}
|
||||
if (rl.IsMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
|
||||
if (rl.isMouseButtonPressed(rl.MouseButton.MOUSE_BUTTON_RIGHT)) {
|
||||
touchCounter = 10;
|
||||
}
|
||||
|
||||
|
|
@ -54,35 +54,35 @@ pub fn main() anyerror!void {
|
|||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl.BeginDrawing();
|
||||
rl.beginDrawing();
|
||||
|
||||
rl.ClearBackground(rl.Color.RAYWHITE);
|
||||
rl.clearBackground(rl.Color.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
|
||||
touchPosition = rl.getTouchPosition(i); // Get the touch point
|
||||
|
||||
// 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.Color.ORANGE);
|
||||
rl.DrawText(rl.TextFormat("%d", i), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, rl.Color.BLACK);
|
||||
rl.drawCircleV(touchPosition, 34, rl.Color.ORANGE);
|
||||
//rl.drawText(rl.textFormat("%d", .{i}), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, rl.Color.BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the normal mouse location
|
||||
rl.DrawCircleV(ballPosition, 30 + (touchCounter * 3), ballColor);
|
||||
rl.drawCircleV(ballPosition, 30 + (touchCounter * 3), ballColor);
|
||||
|
||||
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.Color.DARKGRAY);
|
||||
rl.DrawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, rl.Color.DARKGRAY);
|
||||
rl.drawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.Color.DARKGRAY);
|
||||
rl.drawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, rl.Color.DARKGRAY);
|
||||
|
||||
rl.EndDrawing();
|
||||
rl.endDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
rl.closeWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,67 +12,67 @@ pub fn main() anyerror!void {
|
|||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Apply an outline to a texture");
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib [shaders] example - Apply an outline to a texture");
|
||||
|
||||
const texture: rl.Texture2D = rl.LoadTexture("resources/textures/fudesumi.png");
|
||||
const texture: rl.Texture2D = rl.loadTexture("resources/textures/fudesumi.png");
|
||||
|
||||
const shdrOutline: rl.Shader = rl.LoadShader(0, rl.TextFormat("resources/shaders/glsl330/outline.fs", @intCast(c_int, 330)));
|
||||
const shdrOutline: rl.Shader = rl.loadShader(null, "resources/shaders/glsl330/outline.fs");
|
||||
|
||||
var outlineSize: f32 = 2.0;
|
||||
const outlineColor = [4]f32{ 1.0, 0.0, 0.0, 1.0 }; // Normalized RED color
|
||||
const textureSize = rl.Vector2.init(@intToFloat(f32, texture.width), @intToFloat(f32, texture.height));
|
||||
|
||||
// Get shader locations
|
||||
const outlineSizeLoc = rl.GetShaderLocation(shdrOutline, "outlineSize");
|
||||
const outlineColorLoc = rl.GetShaderLocation(shdrOutline, "outlineColor");
|
||||
const textureSizeLoc = rl.GetShaderLocation(shdrOutline, "textureSize");
|
||||
const outlineSizeLoc = rl.getShaderLocation(shdrOutline, "outlineSize");
|
||||
const outlineColorLoc = rl.getShaderLocation(shdrOutline, "outlineColor");
|
||||
const textureSizeLoc = rl.getShaderLocation(shdrOutline, "textureSize");
|
||||
|
||||
// Set shader values (they can be changed later)
|
||||
rl.SetShaderValue(shdrOutline, outlineSizeLoc, &outlineSize, @enumToInt(rl.ShaderUniformDataType.SHADER_UNIFORM_FLOAT));
|
||||
rl.SetShaderValue(shdrOutline, outlineColorLoc, &outlineColor, @enumToInt(rl.ShaderUniformDataType.SHADER_UNIFORM_VEC4));
|
||||
rl.SetShaderValue(shdrOutline, textureSizeLoc, &textureSize, @enumToInt(rl.ShaderUniformDataType.SHADER_UNIFORM_VEC2));
|
||||
rl.setShaderValue(shdrOutline, outlineSizeLoc, &outlineSize, @enumToInt(rl.ShaderUniformDataType.SHADER_UNIFORM_FLOAT));
|
||||
rl.setShaderValue(shdrOutline, outlineColorLoc, &outlineColor, @enumToInt(rl.ShaderUniformDataType.SHADER_UNIFORM_VEC4));
|
||||
rl.setShaderValue(shdrOutline, textureSizeLoc, &textureSize, @enumToInt(rl.ShaderUniformDataType.SHADER_UNIFORM_VEC2));
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
outlineSize += rl.GetMouseWheelMove();
|
||||
outlineSize += rl.getMouseWheelMove();
|
||||
if (outlineSize < 1.0) outlineSize = 1.0;
|
||||
|
||||
rl.SetShaderValue(shdrOutline, outlineSizeLoc, &outlineSize, @enumToInt(rl.ShaderUniformDataType.SHADER_UNIFORM_FLOAT));
|
||||
rl.setShaderValue(shdrOutline, outlineSizeLoc, &outlineSize, @enumToInt(rl.ShaderUniformDataType.SHADER_UNIFORM_FLOAT));
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl.BeginDrawing();
|
||||
rl.beginDrawing();
|
||||
|
||||
rl.ClearBackground(rl.Color.RAYWHITE);
|
||||
rl.clearBackground(rl.Color.RAYWHITE);
|
||||
|
||||
rl.BeginShaderMode(shdrOutline);
|
||||
rl.beginShaderMode(shdrOutline);
|
||||
|
||||
rl.DrawTexture(texture, @divFloor(rl.GetScreenWidth(), 2) - @divFloor(texture.width, 2), -30, rl.Color.WHITE);
|
||||
rl.drawTexture(texture, @divFloor(rl.getScreenWidth(), 2) - @divFloor(texture.width, 2), -30, rl.Color.WHITE);
|
||||
|
||||
rl.EndShaderMode();
|
||||
rl.endShaderMode();
|
||||
|
||||
rl.DrawText("Shader-based\ntexture\noutline", 10, 10, 20, rl.Color.GRAY);
|
||||
rl.drawText("Shader-based\ntexture\noutline", 10, 10, 20, rl.Color.GRAY);
|
||||
|
||||
rl.DrawText(rl.TextFormat("Outline size: %i px", @floatToInt(i32, outlineSize)), 10, 120, 20, rl.Color.MAROON);
|
||||
//rl.drawText(rl.textFormat("Outline size: %i px", @floatToInt(i32, outlineSize)), 10, 120, 20, rl.Color.MAROON);
|
||||
|
||||
rl.DrawFPS(710, 10);
|
||||
rl.drawFPS(710, 10);
|
||||
|
||||
rl.EndDrawing();
|
||||
rl.endDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl.UnloadTexture(texture);
|
||||
rl.UnloadShader(shdrOutline);
|
||||
rl.unloadTexture(texture);
|
||||
rl.unloadShader(shdrOutline);
|
||||
|
||||
rl.CloseWindow(); // Close window and OpenGL context
|
||||
rl.closeWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ pub fn main() anyerror!void {
|
|||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
rl.InitAudioDevice(); // Initialize audio device
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [texture] example - sprite anim");
|
||||
rl.initAudioDevice(); // Initialize audio device
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib [texture] example - sprite anim");
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
const scarfy: rl.Texture2D = rl.LoadTexture("resources/textures/scarfy.png"); // Texture loading
|
||||
const scarfy: rl.Texture2D = rl.loadTexture("resources/textures/scarfy.png"); // Texture loading
|
||||
|
||||
const position = rl.Vector2.init(350.0, 280.0);
|
||||
var frameRec = rl.Rectangle{ .x = 0.0, .y = 0.0, .width = @intToFloat(f32, @divFloor(scarfy.width, 6)), .height = @intToFloat(f32, scarfy.height) };
|
||||
|
|
@ -25,11 +25,11 @@ pub fn main() anyerror!void {
|
|||
var framesCounter: u8 = 0;
|
||||
var framesSpeed: u8 = 8; // Number of spritesheet frames shown by second
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
framesCounter += 1;
|
||||
|
|
@ -44,9 +44,9 @@ pub fn main() anyerror!void {
|
|||
}
|
||||
|
||||
// Control frames speed
|
||||
if (rl.IsKeyPressed(rl.KeyboardKey.KEY_RIGHT)) {
|
||||
if (rl.isKeyPressed(rl.KeyboardKey.KEY_RIGHT)) {
|
||||
framesSpeed += 1;
|
||||
} else if (rl.IsKeyPressed(rl.KeyboardKey.KEY_LEFT)) {
|
||||
} else if (rl.isKeyPressed(rl.KeyboardKey.KEY_LEFT)) {
|
||||
framesSpeed -= 1;
|
||||
}
|
||||
|
||||
|
|
@ -60,37 +60,37 @@ pub fn main() anyerror!void {
|
|||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl.BeginDrawing();
|
||||
rl.beginDrawing();
|
||||
|
||||
rl.ClearBackground(rl.Color.RAYWHITE);
|
||||
rl.clearBackground(rl.Color.RAYWHITE);
|
||||
|
||||
rl.DrawTexture(scarfy, 15, 40, rl.Color.WHITE);
|
||||
rl.DrawRectangleLines(15, 40, scarfy.width, scarfy.height, rl.Color.LIME);
|
||||
rl.DrawRectangleLines(15 + @floatToInt(i32, frameRec.x), 40 + @floatToInt(i32, frameRec.y), @floatToInt(i32, frameRec.width), @floatToInt(i32, frameRec.height), rl.Color.RED);
|
||||
rl.drawTexture(scarfy, 15, 40, rl.Color.WHITE);
|
||||
rl.drawRectangleLines(15, 40, scarfy.width, scarfy.height, rl.Color.LIME);
|
||||
rl.drawRectangleLines(15 + @floatToInt(i32, frameRec.x), 40 + @floatToInt(i32, frameRec.y), @floatToInt(i32, frameRec.width), @floatToInt(i32, frameRec.height), rl.Color.RED);
|
||||
|
||||
rl.DrawText("FRAME SPEED: ", 165, 210, 10, rl.Color.DARKGRAY);
|
||||
rl.DrawText(rl.TextFormat("%02i FPS", framesSpeed), 575, 210, 10, rl.Color.DARKGRAY);
|
||||
rl.DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, rl.Color.DARKGRAY);
|
||||
rl.drawText("FRAME SPEED: ", 165, 210, 10, rl.Color.DARKGRAY);
|
||||
//rl.drawText(rl.textFormat("%02i FPS", .{framesSpeed}), 575, 210, 10, rl.Color.DARKGRAY);
|
||||
rl.drawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, rl.Color.DARKGRAY);
|
||||
|
||||
for ([_]u32{0} ** MAX_FRAME_SPEED) |_, i| {
|
||||
if (i < framesSpeed) {
|
||||
rl.DrawRectangle(250 + 21 * @intCast(c_int, i), 205, 20, 20, rl.Color.RED);
|
||||
rl.drawRectangle(250 + 21 * @intCast(c_int, i), 205, 20, 20, rl.Color.RED);
|
||||
}
|
||||
rl.DrawRectangleLines(250 + 21 * @intCast(c_int, i), 205, 20, 20, rl.Color.MAROON);
|
||||
rl.drawRectangleLines(250 + 21 * @intCast(c_int, i), 205, 20, 20, rl.Color.MAROON);
|
||||
}
|
||||
|
||||
rl.DrawTextureRec(scarfy, frameRec, position, rl.Color.WHITE); // Draw part of the texture
|
||||
rl.drawTextureRec(scarfy, frameRec, position, rl.Color.WHITE); // Draw part of the texture
|
||||
|
||||
rl.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, rl.Color.GRAY);
|
||||
rl.drawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, rl.Color.GRAY);
|
||||
|
||||
rl.EndDrawing();
|
||||
rl.endDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl.UnloadTexture(scarfy); // Texture unloading
|
||||
rl.unloadTexture(scarfy); // Texture unloading
|
||||
|
||||
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