Skip to content

Commit

Permalink
updated procs to use Zig 0.12.0 library
Browse files Browse the repository at this point in the history
  • Loading branch information
10aded committed May 2, 2024
1 parent 89172a4 commit fc5f7c8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
1 change: 0 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion buttons.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
25 changes: 13 additions & 12 deletions grid-logic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions itch-description.txt
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions qoi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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],
};
Expand Down

0 comments on commit fc5f7c8

Please sign in to comment.