Home

Awesome

zplay

A simple framework intended for game/tool creation.

Features

Getting started

Copy zplay folder or clone repo (recursively) into libs subdirectory of the root of your project.

Install SDL2 library, please refer to docs of SDL2.zig

Then in your build.zig add:

const std = @import("std");
const zplay = @import("libs/zplay/build.zig");

pub fn build(b: *std.build.Builder) void {
    const exe = b.addExecutable("your_bin", "src/main.zig");

    exe.setBuildMode(b.standardReleaseOptions());
    exe.setTarget(b.standardTargetOptions(.{}));
    exe.install();

    zplay.link(exe, .{
      // choose graphics api (gl33/gles3)
      // link optional modules (imgui/nanovg etc)
    });

    const run_cmd = exe.run();
    run_cmd.step.dependOn(b.getInstallStep());

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
}

Now in your code you may import and use zplay:

const std = @import("std");
const zp = @import("zplay");

fn init(ctx: *zp.Context) anyerror!void {
    _ = ctx;
    std.log.info("game init", .{});

    // your init code
}

fn loop(ctx: *zp.Context) anyerror!void {
    while (ctx.pollEvent()) |e| {
        switch (e) {
            .quit_event => ctx.kill(),
            else => {},
        }
    }

    // your game loop
}

fn quit(ctx: *zp.Context) void {
    _ = ctx;
    std.log.info("game quit", .{});

    // your deinit code
}

pub fn main() anyerror!void {
    try zp.run(.{
        .initFn = init,
        .loopFn = loop,
        .quitFn = quit,
    });
}

Third-Party Libraries