···5757 //
5858 // If neither case applies to you, feel free to delete the declaration you
5959 // don't need and to put everything under a single module.
6060+ const raylib_dep = b.dependency("raylib_zig", .{
6161+ .target = target,
6262+ .optimize = optimize,
6363+ });
6464+6565+ const raylib = raylib_dep.module("raylib"); // main raylib module
6666+ const raygui = raylib_dep.module("raygui"); // raygui module
6767+ const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library
6868+6069 const exe = b.addExecutable(.{
6170 .name = "zig_civ",
6271 .root_module = b.createModule(.{
···7988 // can be extremely useful in case of collisions (which can happen
8089 // importing modules from different packages).
8190 .{ .name = "zig_civ", .module = mod },
9191+ .{ .name = "raylib", .module = raylib },
9292+ .{ .name = "raygui", .module = raygui },
8293 },
8394 }),
8495 });
9696+9797+ exe.linkLibrary(raylib_artifact);
85988699 // This declares intent for the executable to be installed into the
87100 // install prefix when running `zig build` (i.e. when executing the default
+4-37
build.zig.zon
···3232 // Once all dependencies are fetched, `zig build` no longer requires
3333 // internet connectivity.
3434 .dependencies = .{
3535- // See `zig fetch --save <url>` for a command-line interface for adding dependencies.
3636- //.example = .{
3737- // // When updating this field to a new URL, be sure to delete the corresponding
3838- // // `hash`, otherwise you are communicating that you expect to find the old hash at
3939- // // the new URL. If the contents of a URL change this will result in a hash mismatch
4040- // // which will prevent zig from using it.
4141- // .url = "https://example.com/foo.tar.gz",
4242- //
4343- // // This is computed from the file contents of the directory of files that is
4444- // // obtained after fetching `url` and applying the inclusion rules given by
4545- // // `paths`.
4646- // //
4747- // // This field is the source of truth; packages do not come from a `url`; they
4848- // // come from a `hash`. `url` is just one of many possible mirrors for how to
4949- // // obtain a package matching this `hash`.
5050- // //
5151- // // Uses the [multihash](https://multiformats.io/multihash/) format.
5252- // .hash = "...",
5353- //
5454- // // When this is provided, the package is found in a directory relative to the
5555- // // build root. In this case the package's hash is irrelevant and therefore not
5656- // // computed. This field and `url` are mutually exclusive.
5757- // .path = "foo",
5858- //
5959- // // When this is set to `true`, a package is declared to be lazily
6060- // // fetched. This makes the dependency only get fetched if it is
6161- // // actually used.
6262- // .lazy = false,
6363- //},
3535+ .raylib_zig = .{
3636+ .url = "git+https://github.com/raylib-zig/raylib-zig?ref=devel#a4d18b2d1cf8fdddec68b5b084535fca0475f466",
3737+ .hash = "raylib_zig-5.6.0-dev-KE8REL5MBQAf3p497t52Xw9P7ojndIkVOWPXnLiLLw2P",
3838+ },
6439 },
6565- // Specifies the set of files and directories that are included in this package.
6666- // Only files and directories listed here are included in the `hash` that
6767- // is computed for this package. Only files listed here will remain on disk
6868- // when using the zig package manager. As a rule of thumb, one should list
6969- // files required for compilation plus any license(s).
7070- // Paths are relative to the build root. Use the empty string (`""`) to refer to
7171- // the build root itself.
7272- // A directory listed here means that all files within, recursively, are included.
7340 .paths = .{
7441 "build.zig",
7542 "build.zig.zon",
+29-21
src/main.zig
···11const std = @import("std");
22const zig_civ = @import("zig_civ");
3344-pub fn main() !void {
55- // Prints to stderr, ignoring potential errors.
66- std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
77- try zig_civ.bufferedPrint();
88-}
44+const rl = @import("raylib");
951010-test "simple test" {
1111- const gpa = std.testing.allocator;
1212- var list: std.ArrayList(i32) = .empty;
1313- defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak!
1414- try list.append(gpa, 42);
1515- try std.testing.expectEqual(@as(i32, 42), list.pop());
1616-}
66+pub fn main() anyerror!void {
77+ // Initialization
88+ //--------------------------------------------------------------------------------------
99+ const screenWidth = 800;
1010+ const screenHeight = 450;
17111818-test "fuzz example" {
1919- const Context = struct {
2020- fn testOne(context: @This(), input: []const u8) anyerror!void {
2121- _ = context;
2222- // Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case!
2323- try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input));
2424- }
2525- };
2626- try std.testing.fuzz(Context{}, Context.testOne, .{});
1212+ rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
1313+ defer rl.closeWindow(); // Close window and OpenGL context
1414+1515+ rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
1616+ //--------------------------------------------------------------------------------------
1717+1818+ // Main game loop
1919+ while (!rl.windowShouldClose()) { // Detect window close button or ESC key
2020+ // Update
2121+ //----------------------------------------------------------------------------------
2222+ // TODO: Update your variables here
2323+ //----------------------------------------------------------------------------------
2424+2525+ // Draw
2626+ //----------------------------------------------------------------------------------
2727+ rl.beginDrawing();
2828+ defer rl.endDrawing();
2929+3030+ rl.clearBackground(.white);
3131+3232+ rl.drawText("Congrats! You created your first window!", 190, 200, 20, .light_gray);
3333+ //----------------------------------------------------------------------------------
3434+ }
2735}