diff options
| author | Radioactivity <85001747+voidwyrm-2@users.noreply.github.com> | 2025-07-27 16:51:32 -1000 |
|---|---|---|
| committer | Radioactivity <85001747+voidwyrm-2@users.noreply.github.com> | 2025-07-27 16:51:51 -1000 |
| commit | f6a1b400454a63860fe1a2af3aea4410d29a83be (patch) | |
| tree | 6c82d78288132efac375bef7fb37203ec9342fd0 | |
| parent | cf2da8fa714c9c3b5e35059090aa3f6f45031337 (diff) | |
Changes
- Removed superflous empty C library
- Rewrote build script
- Added Konami code
| -rw-r--r-- | build.zig | 149 | ||||
| -rw-r--r-- | include/lib.h | 1 | ||||
| -rw-r--r-- | src/lib.c | 1 | ||||
| -rw-r--r-- | src/main.zig | 32 |
4 files changed, 131 insertions, 52 deletions
@@ -1,10 +1,37 @@ const std = @import("std"); const rlz = @import("raylib_zig"); -pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); +const exe_name = "hackathon"; + +const targets: []const std.Target.Query = &.{ + .{ .cpu_arch = .aarch64, .os_tag = .macos }, + .{ .cpu_arch = .aarch64, .os_tag = .linux }, + .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu }, + .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl }, + .{ .cpu_arch = .x86_64, .os_tag = .windows }, + // + // TODO: add WASM support + //.{ .cpu_arch = .wasm32, .os_tag = .emscripten }, +}; + +pub fn build(b: *std.Build) !void { + const build_all = b.option(bool, "ball", "Build and package"); + const optimize = b.standardOptimizeOption(.{}); + const run_step = b.step("run", "Run the app"); + const pack_step = b.step("pack", "Build and package for each supported OS/arch"); + + try buildRun(b, run_step, optimize); + + if (build_all orelse false) { + try buildPack(b, pack_step, optimize); + } +} + +fn buildRun(b: *std.Build, parent: *std.Build.Step, optimize: std.builtin.OptimizeMode) !void { + const target = b.standardTargetOptions(.{}); + const exe_mod = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, @@ -12,11 +39,79 @@ pub fn build(b: *std.Build) void { }); const exe = b.addExecutable(.{ - .name = "hackathon", + .name = exe_name, .root_module = exe_mod, }); - // Raylib + try addRaylibDep(b, exe, target, optimize); + + b.installArtifact(exe); + + const run_cmd = b.addRunArtifact(exe); + + run_cmd.step.dependOn(b.getInstallStep()); + + parent.dependOn(&run_cmd.step); +} + +const pkg_folder = "pkg"; + +// TODO: fix this function +fn buildPack(b: *std.Build, parent: *std.Build.Step, optimize: std.builtin.OptimizeMode) !void { + const rm_pkg = b.addSystemCommand(&.{ "rm", "-rf", pkg_folder }); + + const mkdir_pkg = b.addSystemCommand(&.{ "mkdir", pkg_folder }); + mkdir_pkg.step.dependOn(&rm_pkg.step); + + for (targets) |t| { + const target = b.resolveTargetQuery(t); + const target_triple = try t.zigTriple(b.allocator); + + const exe = b.addExecutable(.{ + .name = exe_name, + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + + try addRaylibDep(b, exe, target, optimize); + + const target_output = b.addInstallArtifact(exe, .{ + .dest_dir = .{ + .override = .{ + .custom = target_triple, + }, + }, + }); + + b.getInstallStep().dependOn(&target_output.step); + + const move_output = b.addSystemCommand(&.{ + "mv", + try std.fmt.allocPrint(b.allocator, "zig-out/{s}", .{target_triple}), + ".", + }); + + move_output.step.dependOn(b.getInstallStep()); + + const zip = b.addSystemCommand(&.{ + "zip", + "-r", + try std.fmt.allocPrint(b.allocator, "{s}/{s}.zip", .{ pkg_folder, target_triple }), + target_triple, + }); + + zip.step.dependOn(&mkdir_pkg.step); + zip.step.dependOn(&move_output.step); + + const rm_exe = b.addSystemCommand(&.{ "rm", "-rf", target_triple }); + rm_exe.step.dependOn(&zip.step); + + parent.dependOn(&rm_exe.step); + } +} + +fn addRaylibDep(b: *std.Build, exe: *std.Build.Step.Compile, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !void { const raylib_dep = b.dependency("raylib_zig", .{ .target = target, .optimize = optimize, @@ -36,50 +131,4 @@ pub fn build(b: *std.Build) void { exe.linkLibrary(raylib_artifact); exe.root_module.addImport("raylib", raylib); exe.root_module.addImport("raygui", raygui); - - // Build the C library - const lib_c = b.addStaticLibrary(.{ - .name = "c_lib", - .target = target, - .optimize = optimize, - }); - - lib_c.addCSourceFile(.{ - .file = b.path("src/lib.c"), - .flags = &[_][]const u8{"-std=c99"}, - }); - lib_c.addIncludePath(b.path("include")); - lib_c.linkLibC(); - - exe.addIncludePath(b.path("include")); - exe.addIncludePath(b.path("src")); - exe.linkLibrary(lib_c); - exe.linkLibC(); - - b.installArtifact(exe); - - const run_cmd = b.addRunArtifact(exe); - - // By making the run step depend on the install step, it will be run from the - // installation directory rather than directly from within the cache directory. - // This is not necessary, however, if the application depends on other installed - // files, this ensures they will be present and in the expected location. - run_cmd.step.dependOn(b.getInstallStep()); - - // Allow passing args to the exe like this: `zig build run -- arg1 arg2 etc` - if (b.args) |args| { - run_cmd.addArgs(args); - } - - const run_step = b.step("run", "Run the app"); - run_step.dependOn(&run_cmd.step); - - const exe_tests = b.addTest(.{ - .root_module = exe_mod, - }); - - const run_exe_tests = b.addRunArtifact(exe_tests); - - const test_step = b.step("test", "Run tests"); - test_step.dependOn(&run_exe_tests.step); } diff --git a/include/lib.h b/include/lib.h deleted file mode 100644 index 6f70f09..0000000 --- a/include/lib.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/src/lib.c b/src/lib.c deleted file mode 100644 index a82b12f..0000000 --- a/src/lib.c +++ /dev/null @@ -1 +0,0 @@ -#include "lib.h" diff --git a/src/main.zig b/src/main.zig index 1b5cbf2..e8e8201 100644 --- a/src/main.zig +++ b/src/main.zig @@ -20,6 +20,20 @@ const edit = debug and false; var screen_width: i32 = 1280; var screen_height: i32 = 720; +const konami_code = [_]rl.KeyboardKey{ + .up, + .up, + .down, + .down, + .left, + .right, + .left, + .right, + .b, + .a, + .enter, +}; + // TODO: ideas for the future (after hackathon) // "Heat system" (shooting lazers increases heat, heat decreases over time, if heat is too high, CPU throttles) // "Cooling system" some way to have CPUs that are more resistant to heat @@ -73,6 +87,17 @@ fn getMousePos(camera: *const rl.Camera2D) rl.Vector2 { }; } +fn readCode(counter: *u8, seq: []const rl.KeyboardKey) bool { + if (counter.* >= seq.len) { + counter.* = 0; + return true; + } else if (rl.isKeyPressed(seq[@as(usize, counter.*)])) { + counter.* += 1; + } + + return false; +} + fn textureButtonScaled(game: *Game, camera: *const rl.Camera2D, texture: rl.Texture2D, pos: rl.Vector2, rotation: f32, scale: f32) bool { const msp = getMousePos(camera); @@ -1433,6 +1458,7 @@ const ScreenBattle = struct { skipped: bool = false, completion_time: f32 = 0, popup: bool = false, + konami_counter: u8 = 0, const max_ram = 100; const initial_cpu_transistor_cost = 50; @@ -1539,6 +1565,12 @@ const ScreenBattle = struct { f.writeByte('\n') catch unreachable; unreachable; } + + var mut_konami_code = konami_code; + + if (readCode(&self.konami_counter, &mut_konami_code)) { + self.transistors += 10000; + } } fn updateCpuAndBugs(self: *ScreenBattle, game: *Game, dt: f32) void { |
