diff --git a/build.zig b/build.zig index 82e070b..803412a 100644 --- a/build.zig +++ b/build.zig @@ -65,6 +65,17 @@ pub fn build(b: *std.Build) void { .root_module = exe_mod, }); + const raylib_dep = b.dependency("raylib_zig", .{ + .target = target, + .optimize = optimize, + }); + + const raylib = raylib_dep.module("raylib"); // main raylib module + const raylib_artifact = raylib_dep.artifact("raylib"); // raylib c library + + exe.linkLibrary(raylib_artifact); + exe.root_module.addImport("raylib", raylib); + // This declares intent for the executable to be installed into the // standard location when the user invokes the "install" step (the default // step when running `zig build`). diff --git a/build.zig.zon b/build.zig.zon index 3157ba9..bc9065e 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -36,45 +36,11 @@ // Once all dependencies are fetched, `zig build` no longer requires // internet connectivity. .dependencies = .{ - // See `zig fetch --save ` for a command-line interface for adding dependencies. - //.example = .{ - // // When updating this field to a new URL, be sure to delete the corresponding - // // `hash`, otherwise you are communicating that you expect to find the old hash at - // // the new URL. If the contents of a URL change this will result in a hash mismatch - // // which will prevent zig from using it. - // .url = "https://example.com/foo.tar.gz", - // - // // This is computed from the file contents of the directory of files that is - // // obtained after fetching `url` and applying the inclusion rules given by - // // `paths`. - // // - // // This field is the source of truth; packages do not come from a `url`; they - // // come from a `hash`. `url` is just one of many possible mirrors for how to - // // obtain a package matching this `hash`. - // // - // // Uses the [multihash](https://multiformats.io/multihash/) format. - // .hash = "...", - // - // // When this is provided, the package is found in a directory relative to the - // // build root. In this case the package's hash is irrelevant and therefore not - // // computed. This field and `url` are mutually exclusive. - // .path = "foo", - // - // // When this is set to `true`, a package is declared to be lazily - // // fetched. This makes the dependency only get fetched if it is - // // actually used. - // .lazy = false, - //}, + .raylib_zig = .{ + .url = "git+https://github.com/Not-Nik/raylib-zig?ref=devel#5013830647196ba938a3a25a36b8245606e9a9cd", + .hash = "raylib_zig-5.6.0-dev-KE8REM0tBQAHVn9Xjqlgu9l1qgfTmP8aJa1kLhD584bV", + }, }, - - // Specifies the set of files and directories that are included in this package. - // Only files and directories listed here are included in the `hash` that - // is computed for this package. Only files listed here will remain on disk - // when using the zig package manager. As a rule of thumb, one should list - // files required for compilation plus any license(s). - // Paths are relative to the build root. Use the empty string (`""`) to refer to - // the build root itself. - // A directory listed here means that all files within, recursively, are included. .paths = .{ "build.zig", "build.zig.zon", diff --git a/src/car.zig b/src/car.zig new file mode 100644 index 0000000..b28d98a --- /dev/null +++ b/src/car.zig @@ -0,0 +1,8 @@ +const rl = @import("raylib"); + +const Car = struct { + location: rl.Vector2, + color: rl.Color, + fuel: u7, + speed: u8, +}; diff --git a/src/globals.zig b/src/globals.zig new file mode 100644 index 0000000..b08f9d3 --- /dev/null +++ b/src/globals.zig @@ -0,0 +1,13 @@ +const rl = @import("raylib"); + +pub var screen_width = 1920; +pub var screen_height = 1080; + +fn setWindowSize(new_width: usize, new_height: usize) void { + screen_width = new_width; + screen_height = new_height; +} + +fn checkWindowSizeChanged(new_width: usize, new_height: usize) bool { + return screen_width != new_width or screen_height != new_height; +} diff --git a/src/main.zig b/src/main.zig index f7af4de..84ff9d0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,26 @@ const std = @import("std"); +const rl = @import("raylib"); pub fn main() !void { - std.debug.print("Hello World", .{}); + const size = .{ 1920, 1080 }; + + rl.setConfigFlags(.{ + .msaa_4x_hint = true, + .window_resizable = true, + .window_maximized = true, + }); + + rl.initWindow(size[0], size[1], "Promet SIM"); + defer rl.closeWindow(); + + rl.maximizeWindow(); + + rl.setTargetFPS(60); + + while (!rl.windowShouldClose()) { + rl.beginDrawing(); + defer rl.endDrawing(); + + rl.clearBackground(.light_gray); + } } diff --git a/src/spawn-area.zig b/src/spawn-area.zig new file mode 100644 index 0000000..b868aca --- /dev/null +++ b/src/spawn-area.zig @@ -0,0 +1,18 @@ +const rl = @import("raylib"); + +const AreaLocation = enum { + TopLeft, + TopRight, + BottomLeft, + BottomRihgt, +}; + +const SpawnArea = struct { + location: rl.Vector2, + // cars + size: .{ i32, i32 }, + + pub fn init(loc: AreaLocation) SpawnArea { + return SpawnArea{ .location = loc, .size = .{ undefined, undefined } }; + } +};