update to new version
This commit is contained in:
12
build.zig
12
build.zig
@@ -18,7 +18,6 @@ pub fn build(b: *std.Build) void {
|
|||||||
const raylib_dep = b.dependency("raylib_zig", .{
|
const raylib_dep = b.dependency("raylib_zig", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.shared = true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const raylib = raylib_dep.module("raylib");
|
const raylib = raylib_dep.module("raylib");
|
||||||
@@ -43,13 +42,8 @@ pub fn build(b: *std.Build) void {
|
|||||||
const run_step = b.step("run", "Run the app");
|
const run_step = b.step("run", "Run the app");
|
||||||
run_step.dependOn(&run_cmd.step);
|
run_step.dependOn(&run_cmd.step);
|
||||||
|
|
||||||
const main_tests = b.addTest(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize });
|
const tests = b.addTest(.{ .root_module = exe_mod });
|
||||||
const game_tests = b.addTest(.{ .root_source_file = b.path("src/game.zig"), .target = target, .optimize = optimize });
|
const run_tests = b.addRunArtifact(tests);
|
||||||
|
|
||||||
const run_exe_main_tests = b.addRunArtifact(main_tests);
|
|
||||||
const run_exe_game_tests = b.addRunArtifact(game_tests);
|
|
||||||
|
|
||||||
const test_step = b.step("test", "Run unit tests");
|
const test_step = b.step("test", "Run unit tests");
|
||||||
test_step.dependOn(&run_exe_main_tests.step);
|
test_step.dependOn(&run_tests.step);
|
||||||
test_step.dependOn(&run_exe_game_tests.step);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
|
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.raylib_zig = .{
|
.raylib_zig = .{
|
||||||
.url = "git+https://github.com/Not-Nik/raylib-zig?ref=devel#5013830647196ba938a3a25a36b8245606e9a9cd",
|
.url = "git+https://github.com/raylib-zig/raylib-zig?ref=devel#cd71c85d571027ac8033357f83b124ee051825b3",
|
||||||
.hash = "raylib_zig-5.6.0-dev-KE8REM0tBQAHVn9Xjqlgu9l1qgfTmP8aJa1kLhD584bV",
|
.hash = "raylib_zig-5.6.0-dev-KE8REENOBQC-m5nK7M2b5aKSIubJPbPLUYcRhT7aT3RN",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ pub const Game = struct {
|
|||||||
playFieldSize: Vec2,
|
playFieldSize: Vec2,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
body: std.ArrayList(Vec2),
|
body: std.ArrayList(Vec2),
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
state: State,
|
state: State,
|
||||||
rng: std.Random.DefaultPrng,
|
rng: std.Random.DefaultPrng,
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ pub const Game = struct {
|
|||||||
const startPos: u8 = 10;
|
const startPos: u8 = 10;
|
||||||
for (0..bodySize) |i| {
|
for (0..bodySize) |i| {
|
||||||
const index = std.math.cast(i32, i) orelse unreachable;
|
const index = std.math.cast(i32, i) orelse unreachable;
|
||||||
try body.append(Vec2{ startPos - index, 10 });
|
try body.append(allocator, Vec2{ startPos - index, 10 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const seed: u64 = @intCast(std.time.nanoTimestamp());
|
const seed: u64 = @intCast(std.time.nanoTimestamp());
|
||||||
@@ -55,6 +56,7 @@ pub const Game = struct {
|
|||||||
.food = Vec2{ 11, 13 },
|
.food = Vec2{ 11, 13 },
|
||||||
.direction = Direction.right,
|
.direction = Direction.right,
|
||||||
.body = body,
|
.body = body,
|
||||||
|
.allocator = allocator,
|
||||||
.state = State.running,
|
.state = State.running,
|
||||||
.rng = prng,
|
.rng = prng,
|
||||||
.grow = false,
|
.grow = false,
|
||||||
@@ -66,7 +68,7 @@ pub const Game = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Game) void {
|
pub fn deinit(self: *Game) void {
|
||||||
self.body.deinit();
|
self.body.deinit(self.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setDirection(self: *Game, newDirection: Direction) void {
|
pub fn setDirection(self: *Game, newDirection: Direction) void {
|
||||||
@@ -104,7 +106,7 @@ pub const Game = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try self.body.insert(0, newHead);
|
try self.body.insert(self.allocator, 0, newHead);
|
||||||
if (self.grow) {
|
if (self.grow) {
|
||||||
self.grow = false;
|
self.grow = false;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ const std = @import("std");
|
|||||||
const rl = @import("raylib");
|
const rl = @import("raylib");
|
||||||
const g = @import("game.zig");
|
const g = @import("game.zig");
|
||||||
|
|
||||||
|
test {
|
||||||
|
_ = g;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
const allocator = std.heap.page_allocator;
|
const allocator = std.heap.page_allocator;
|
||||||
const scaleFactor = 20;
|
const scaleFactor = 20;
|
||||||
|
|||||||
Reference in New Issue
Block a user