Sprite
This commit is contained in:
72
build.zig
Normal file
72
build.zig
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const rlz = @import("raylib_zig");
|
||||||
|
|
||||||
|
pub fn build(b: *std.Build) !void {
|
||||||
|
const target = b.standardTargetOptions(.{});
|
||||||
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
|
const raylib_dep = b.dependency("raylib_zig", .{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
|
||||||
|
// Fixes panic from weird joystick OOB crap on hello world project
|
||||||
|
// panic: index -255 out of bounds for type 'int[512]'
|
||||||
|
// js->linjs.keyMap[code - BTN_MISC] in glfw/src/linux_joystick.c
|
||||||
|
.config = "-fno-sanitize=undefined",
|
||||||
|
});
|
||||||
|
const raylib = raylib_dep.module("raylib");
|
||||||
|
const raylib_artifact = raylib_dep.artifact("raylib");
|
||||||
|
|
||||||
|
const exe_mod = b.createModule(.{
|
||||||
|
.root_source_file = b.path("src/main.zig"),
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
exe_mod.addImport("raylib", raylib);
|
||||||
|
|
||||||
|
const run_step = b.step("run", "Run the app");
|
||||||
|
|
||||||
|
//web exports are completely separate
|
||||||
|
if (target.query.os_tag == .emscripten) {
|
||||||
|
const emsdk = rlz.emsdk;
|
||||||
|
const wasm = b.addLibrary(.{
|
||||||
|
.name = "zig-frugg",
|
||||||
|
.root_module = exe_mod,
|
||||||
|
});
|
||||||
|
|
||||||
|
const install_dir: std.Build.InstallDir = .{ .custom = "web" };
|
||||||
|
const emcc_flags = emsdk.emccDefaultFlags(b.allocator, .{ .optimize = optimize });
|
||||||
|
const emcc_settings = emsdk.emccDefaultSettings(b.allocator, .{ .optimize = optimize });
|
||||||
|
|
||||||
|
const emcc_step = emsdk.emccStep(b, raylib_artifact, wasm, .{
|
||||||
|
.optimize = optimize,
|
||||||
|
.flags = emcc_flags,
|
||||||
|
.settings = emcc_settings,
|
||||||
|
.shell_file_path = emsdk.shell(raylib_dep),
|
||||||
|
.install_dir = install_dir,
|
||||||
|
.embed_paths = &.{.{ .src_path = "resources/" }},
|
||||||
|
});
|
||||||
|
b.getInstallStep().dependOn(emcc_step);
|
||||||
|
|
||||||
|
const html_filename = try std.fmt.allocPrint(b.allocator, "{s}.html", .{wasm.name});
|
||||||
|
const emrun_step = emsdk.emrunStep(
|
||||||
|
b,
|
||||||
|
b.getInstallPath(install_dir, html_filename),
|
||||||
|
&.{},
|
||||||
|
);
|
||||||
|
|
||||||
|
emrun_step.dependOn(emcc_step);
|
||||||
|
run_step.dependOn(emrun_step);
|
||||||
|
} else {
|
||||||
|
const exe = b.addExecutable(.{
|
||||||
|
.name = "zig-frugg",
|
||||||
|
.root_module = exe_mod,
|
||||||
|
});
|
||||||
|
b.installArtifact(exe);
|
||||||
|
|
||||||
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
|
||||||
|
run_step.dependOn(&run_cmd.step);
|
||||||
|
}
|
||||||
|
}
|
||||||
52
build.zig.zon
Normal file
52
build.zig.zon
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
.{
|
||||||
|
// This is the default name used by packages depending on this one. For
|
||||||
|
// example, when a user runs `zig fetch --save <url>`, this field is used
|
||||||
|
// as the key in the `dependencies` table. Although the user can choose a
|
||||||
|
// different name, most users will stick with this provided value.
|
||||||
|
//
|
||||||
|
// It is redundant to include "zig" in this name because it is already
|
||||||
|
// within the Zig package namespace.
|
||||||
|
.name = .zig_frugg,
|
||||||
|
// This is a [Semantic Version](https://semver.org/).
|
||||||
|
// In a future version of Zig it will be used for package deduplication.
|
||||||
|
.version = "0.0.0",
|
||||||
|
// Together with name, this represents a globally unique package
|
||||||
|
// identifier. This field is generated by the Zig toolchain when the
|
||||||
|
// package is first created, and then *never changes*. This allows
|
||||||
|
// unambiguous detection of one package being an updated version of
|
||||||
|
// another.
|
||||||
|
//
|
||||||
|
// When forking a Zig project, this id should be regenerated (delete the
|
||||||
|
// field and run `zig build`) if the upstream project is still maintained.
|
||||||
|
// Otherwise, the fork is *hostile*, attempting to take control over the
|
||||||
|
// original project's identity. Thus it is recommended to leave the comment
|
||||||
|
// on the following line intact, so that it shows up in code reviews that
|
||||||
|
// modify the field.
|
||||||
|
.fingerprint = 0x83fd67e65259ef3a, // Changing this has security and trust implications.
|
||||||
|
// Tracks the earliest Zig version that the package considers to be a
|
||||||
|
// supported use case.
|
||||||
|
.minimum_zig_version = "0.16.0",
|
||||||
|
// This field is optional.
|
||||||
|
// Each dependency must either provide a `url` and `hash`, or a `path`.
|
||||||
|
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
|
||||||
|
// Once all dependencies are fetched, `zig build` no longer requires
|
||||||
|
// internet connectivity.
|
||||||
|
.dependencies = .{
|
||||||
|
.raylib_zig = .{
|
||||||
|
.url = "git+https://github.com/raylib-zig/raylib-zig?ref=devel#58f3c0fa328fc9ff48d17c2c3771ab9c5114aaa6",
|
||||||
|
.hash = "raylib_zig-6.0.0-KE8REMNkBQCpxwqT9ubVNf5aEOcWRUVIaH2sgt_sDDoZ",
|
||||||
|
},
|
||||||
|
.emsdk = .{
|
||||||
|
.url = "git+https://github.com/emscripten-core/emsdk?ref=4.0.9#3bcf1dcd01f040f370e10fe673a092d9ed79ebb5",
|
||||||
|
.hash = "N-V-__8AAJl1DwBezhYo_VE6f53mPVm00R-Fk28NPW7P14EQ",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.paths = .{
|
||||||
|
"build.zig",
|
||||||
|
"build.zig.zon",
|
||||||
|
"src",
|
||||||
|
// For example...
|
||||||
|
//"LICENSE",
|
||||||
|
//"README.md",
|
||||||
|
},
|
||||||
|
}
|
||||||
BIN
resources/PlayerSprite2.png
Normal file
BIN
resources/PlayerSprite2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
BIN
resources/burp.mp3
Normal file
BIN
resources/burp.mp3
Normal file
Binary file not shown.
0
resources/placeholder.txt
Normal file
0
resources/placeholder.txt
Normal file
56
src/main.zig
Normal file
56
src/main.zig
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const rl = @import("raylib");
|
||||||
|
|
||||||
|
const Vec3 = rl.Vector3;
|
||||||
|
const Vec2 = rl.Vector2;
|
||||||
|
|
||||||
|
const Frug = struct {
|
||||||
|
pos: Vec3,
|
||||||
|
radius: f32 = 24,
|
||||||
|
pub fn draw(self: @This()) void {
|
||||||
|
rl.drawCircleV(
|
||||||
|
Vec2.init(self.pos.x, self.pos.y),
|
||||||
|
self.radius,
|
||||||
|
.green,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
pub fn init() Frug {
|
||||||
|
return Frug{
|
||||||
|
.pos = .{ .x = 200, .y = 400, .z = 10 },
|
||||||
|
.radius = 24,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn main(init: std.process.Init) anyerror!void {
|
||||||
|
const io = init.io;
|
||||||
|
try std.Io.File.stdout().writeStreamingAll(io, "FRUGG!\n");
|
||||||
|
|
||||||
|
const screenWidth = 800;
|
||||||
|
const screenHeight = 600;
|
||||||
|
|
||||||
|
rl.initWindow(screenWidth, screenHeight, "Zig Frugger");
|
||||||
|
defer rl.closeWindow();
|
||||||
|
|
||||||
|
rl.initAudioDevice();
|
||||||
|
defer rl.closeAudioDevice();
|
||||||
|
const frugBurp = try rl.loadSound("resources/burp.mp3");
|
||||||
|
defer rl.unloadSound(frugBurp);
|
||||||
|
|
||||||
|
rl.setTargetFPS(60);
|
||||||
|
|
||||||
|
const frug = Frug.init();
|
||||||
|
|
||||||
|
while (!rl.windowShouldClose()) {
|
||||||
|
rl.beginDrawing();
|
||||||
|
defer rl.endDrawing();
|
||||||
|
|
||||||
|
if (rl.isKeyPressed(.space)) rl.playSound(frugBurp);
|
||||||
|
|
||||||
|
rl.clearBackground(.sky_blue);
|
||||||
|
|
||||||
|
frug.draw();
|
||||||
|
|
||||||
|
rl.drawText("FRUGG!", 10, 10, 40, .green);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user