From fc5f7c87f95a103051b0fff42b42bd650b9d16f1 Mon Sep 17 00:00:00 2001 From: 10aded <10aded-Streaming@protonmail.com> Date: Thu, 2 May 2024 12:58:30 -0400 Subject: [PATCH] updated procs to use Zig 0.12.0 library --- build.zig | 1 - buttons.zig | 2 +- grid-logic.zig | 25 +++++++++++++------------ itch-description.txt | 16 ++++++++++++++++ main.zig | 6 +++--- qoi.zig | 4 ++-- 6 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 itch-description.txt diff --git a/build.zig b/build.zig index 5c99f59..7e07e6d 100644 --- a/build.zig +++ b/build.zig @@ -59,7 +59,6 @@ pub fn addRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. } // Raylib C files to add. - // TODO: Update to remove 0.12.0 compiler warning. const rcore_path = std.Build.path(b, "./Raylib5/src/rcore.c"); const utils_path = std.Build.path(b, "./Raylib5/src/utils.c"); const rshapes_path = std.Build.path(b, "./Raylib5/src/rshapes.c"); diff --git a/buttons.zig b/buttons.zig index 84a061b..67b50b6 100644 --- a/buttons.zig +++ b/buttons.zig @@ -93,6 +93,6 @@ pub fn set_hover_status(pos : Vec2, button : *Button) void { const button_center = button.pos; const xpos = pos[0]; const ypos = pos[1]; - const in_rect = @fabs(xpos - button_center[0]) < 0.5 * button.width and @fabs(ypos - button_center[1]) < 0.5 * button.height; + const in_rect = @abs(xpos - button_center[0]) < 0.5 * button.width and @abs(ypos - button_center[1]) < 0.5 * button.height; button.hovering = in_rect; } diff --git a/grid-logic.zig b/grid-logic.zig index 97553c6..16e4ed7 100644 --- a/grid-logic.zig +++ b/grid-logic.zig @@ -35,28 +35,29 @@ pub fn is_grid_solved(grid : Grid) bool { var quads_unique = true; // Rows first. for (0..4) |i| { - const t1 = std.math.absCast(grid[4*i + 0]); - const t2 = std.math.absCast(grid[4*i + 1]); - const t3 = std.math.absCast(grid[4*i + 2]); - const t4 = std.math.absCast(grid[4*i + 3]); +// const texture_index = @as(usize, @intCast(@abs(tile))) - 1; + const t1 = @abs(grid[4*i + 0]); + const t2 = @abs(grid[4*i + 1]); + const t3 = @abs(grid[4*i + 2]); + const t4 = @abs(grid[4*i + 3]); const unique = t1 != t2 and t1 != t3 and t1 != t4 and t2 != t3 and t2 != t4 and t3 != t4; rows_unique = rows_unique and unique; } // Cols next. for (0..4) |j| { - const t1 = std.math.absCast(grid[0 + j]); - const t2 = std.math.absCast(grid[4 + j]); - const t3 = std.math.absCast(grid[8 + j]); - const t4 = std.math.absCast(grid[12 + j]); + const t1 = @abs(grid[0 + j]); + const t2 = @abs(grid[4 + j]); + const t3 = @abs(grid[8 + j]); + const t4 = @abs(grid[12 + j]); const unique = t1 != t2 and t1 != t3 and t1 != t4 and t2 != t3 and t2 != t4 and t3 != t4; cols_unique = cols_unique and unique; } // Quads. for ([4]usize{0,2,8,10}) |k| { - const t1 = std.math.absCast(grid[k]); - const t2 = std.math.absCast(grid[k + 1]); - const t3 = std.math.absCast(grid[k + 4]); - const t4 = std.math.absCast(grid[k + 5]); + const t1 = @abs(grid[k]); + const t2 = @abs(grid[k + 1]); + const t3 = @abs(grid[k + 4]); + const t4 = @abs(grid[k + 5]); const unique = t1 != t2 and t1 != t3 and t1 != t4 and t2 != t3 and t2 != t4 and t3 != t4; quads_unique = quads_unique and unique; } diff --git a/itch-description.txt b/itch-description.txt new file mode 100644 index 0000000..3de53be --- /dev/null +++ b/itch-description.txt @@ -0,0 +1,16 @@ +This is a simple game of some 4x4 Sudoku puzzles, played with a mouse. + +The game is very short; solving the game's 11 puzzles should take less than 10 minutes. + +The source code of this app is available on GitHub at: https://github.com/10aded/4x4-Sudoku-Game + +The app's entire development (basically) was streamed on Twitch and uploaded to YouTube at: + +https://www.twitch.tv/10aded + +https://www.youtube.com/@10aded + + +The game should not require any dependencies outside of OpenGL (for which drivers exist on most builds of Windows). If for whatever reason it does not launch, the source code is available on GitHub at: https://github.com/10aded/4x4-Sudoku-Game and can be built from scratch using the Zig 0.11.0 compiler. + +The game was created from scratch in Zig / raylib from the GitHub repo linked above. As such, only the Zig 0.11.0 compiler, and the GitHub project are needed to build the project. diff --git a/main.zig b/main.zig index 3b757d8..96dce89 100644 --- a/main.zig +++ b/main.zig @@ -672,7 +672,7 @@ fn render() void { // Set the background color to win_color if the grid has been solved AND // the game mode is puzzles. const solved = levels_solved_status[current_level_index] and gamemode == .puzzles; - var background_color = if (solved) win_color else default_background_color; + const background_color = if (solved) win_color else default_background_color; rl.ClearBackground(rlc(background_color)); @@ -781,7 +781,7 @@ fn draw_tile(tile : Tile, pos : Vec2) void { const border_width = @max(0.05 * length, 5); const background_color = if (tile > 0) tile_fixed_background_color else tile_movable_background_color; - const texture_index : usize = std.math.absCast(tile) - 1; // @abs() not available in Zig 0.11.0 + const texture_index = @as(usize, @intCast(@abs(tile))) - 1; const texture_ptr = &numeral_textures[texture_index]; shapes.draw_centered_rect(pos, length + border_width, length + border_width, grid_bar_color); @@ -835,5 +835,5 @@ fn vec2_to_rl(vec : Vec2) rl.Vector2 { // Check if some position is over a tile. fn is_tile_hovered(cursor_pos : Vec2, tile_pos : Vec2) bool { const tl = grid_geometry.tile_length; - return @fabs(cursor_pos[0] - tile_pos[0]) < 0.5 * tl and @fabs(cursor_pos[1] - tile_pos[1]) < 0.5 * tl; + return @abs(cursor_pos[0] - tile_pos[0]) < 0.5 * tl and @abs(cursor_pos[1] - tile_pos[1]) < 0.5 * tl; } diff --git a/qoi.zig b/qoi.zig index 2720927..879978d 100644 --- a/qoi.zig +++ b/qoi.zig @@ -40,8 +40,8 @@ pub fn comptime_header_parser( raw_image : [] const u8) Qoi_Header { // Parse the image header into the qoi_header struct. const qoi_header = Qoi_Header{ .magic_bytes = [4]u8{raw_image[0], raw_image[1], raw_image[2], raw_image[3]}, - .image_width = std.mem.readIntSlice(u32, raw_image[4..8], .Big), // (Thanks tw0st3p!) - .image_height = std.mem.readIntSlice(u32, raw_image[8..12], .Big), + .image_width = std.mem.readInt(u32, raw_image[4..8], .big), // (Thanks tw0st3p)! + .image_height = std.mem.readInt(u32, raw_image[8..12], .big), .channel = raw_image[12], .colorspace = raw_image[13], };