const std = @import("std"); const lib = @import("zig_civ"); const rl = @import("raylib"); const screen_offset_x: f32 = 400.0; // center of 800px screen const screen_offset_y: f32 = 225.0; // center of 450px screen fn draw_hex(hex: lib.hex.HexCell) !void { var corners: [6]lib.hex.Point = undefined; for (0..6) |i| { const corner = lib.hex.calculate_hex_corners(hex.center, hex.outer_radius, i); corners[i] = corner; } for (0..6) |i| { const start = corners[i]; const end = corners[@mod(i + 1, 6)]; const start_x: i32 = @intFromFloat(@round(start.x + screen_offset_x)); const start_y: i32 = @intFromFloat(@round(start.y + screen_offset_y)); const end_x: i32 = @intFromFloat(@round(end.x + screen_offset_x)); const end_y: i32 = @intFromFloat(@round(end.y + screen_offset_y)); rl.drawLine(start_x, start_y, end_x, end_y, .black); } const center_x: i32 = @intFromFloat(@round(hex.center.x + screen_offset_x - 10)); const center_y: i32 = @intFromFloat(@round(hex.center.y + screen_offset_y - 6)); var buf: [64]u8 = undefined; const text = try std.fmt.bufPrintZ(&buf, "{d} {d}", .{ hex.cubic.q, hex.cubic.r }); rl.drawText(text, center_x, center_y, 12, .black); } pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); // Axial template: 7x7 grid, center at [3][3], indexed [r+3][q+3] // Hexagon shape for radius 3 //const template = [7][7]u1{ //// q: -3 -2 -1 0 1 2 3 //.{ 0, 0, 0, 1, 1, 1, 1 }, // r = -3 //.{ 0, 0, 1, 1, 1, 1, 1 }, // r = -2 //.{ 0, 1, 1, 1, 1, 1, 1 }, // r = -1 //.{ 1, 1, 1, 1, 1, 1, 1 }, // r = 0 //.{ 1, 1, 1, 1, 1, 1, 0 }, // r = 1 //.{ 1, 1, 1, 1, 1, 0, 0 }, // r = 2 //.{ 1, 1, 1, 1, 0, 0, 0 }, // r = 3 //}; //const template_rombus = [7][7]u1{ //.{ 1, 1, 1, 1, 1, 1, 1 }, //.{ 1, 1, 1, 1, 1, 1, 1 }, //.{ 1, 1, 1, 1, 1, 1, 1 }, //.{ 1, 1, 1, 1, 1, 1, 1 }, //.{ 1, 1, 1, 1, 1, 1, 1 }, //.{ 1, 1, 1, 1, 1, 1, 1 }, //.{ 1, 1, 1, 1, 1, 1, 1 }, //}; const template_left_triangle = [7][7]u1{ .{ 1, 1, 1, 1, 1, 1, 1 }, .{ 1, 1, 1, 1, 1, 1, 0 }, .{ 1, 1, 1, 1, 1, 0, 0 }, .{ 1, 1, 1, 1, 0, 0, 0 }, .{ 1, 1, 1, 0, 0, 0, 0 }, .{ 1, 1, 0, 0, 0, 0, 0 }, .{ 1, 0, 0, 0, 0, 0, 0 }, }; const template = template_left_triangle; var grid = try lib.world.generateFromTemplate(3, &template, 40.0, allocator); defer grid.deinit(allocator); // Initialization const screenWidth = 800; const screenHeight = 450; const fps = 60; rl.initWindow(screenWidth, screenHeight, "raylib.hex-zig [core] example - basic window"); defer rl.closeWindow(); rl.setTargetFPS(fps); // Main game loop while (!rl.windowShouldClose()) { rl.beginDrawing(); defer rl.endDrawing(); rl.clearBackground(.white); for (grid.items) |cell| { try draw_hex(cell); } } }