diff --git a/assets/assets.zig b/assets/assets.zig index 8e6d3d7..fb6f308 100644 --- a/assets/assets.zig +++ b/assets/assets.zig @@ -1,2 +1,3 @@ -// pub const tiles = @import("tiles.zig"); +pub usingnamespace @import("tiles.zig"); pub usingnamespace @import("sprites.zig"); +pub usingnamespace @import("maps/map.zig"); diff --git a/assets/maps/map.zig b/assets/maps/map.zig new file mode 100644 index 0000000..2d46bfb --- /dev/null +++ b/assets/maps/map.zig @@ -0,0 +1,22 @@ +pub const map: [400]u32 = .{ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 1, 1, + 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, + 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, + 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, + 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, + 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, + 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 50, 19, 19, 18, 1, 1, 1, 37, 1, + 1, 39, 1, 1, 1, 1, 1, 50, 19, 52, 1, 1, 1, 1, 20, 1, 1, 1, 37, 1, + 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 1, 37, 1, + 1, 39, 1, 50, 19, 52, 1, 1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 1, 37, 1, + 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 1, 37, 1, + 1, 39, 1, 1, 1, 1, 1, 50, 19, 52, 1, 1, 1, 1, 51, 1, 1, 1, 37, 1, + 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 1, 37, 1, + 1, 39, 1, 50, 19, 52, 1, 1, 1, 1, 1, 1, 1, 1, 51, 1, 2, 1, 37, 1, + 54, 55, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 33, 19, 19, 19, 66, 54, + 1, 1, 1, 1, 1, 1, 1, 50, 19, 52, 1, 1, 1, 1, 1, 1, 1, 1, 20, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 51, 1, + 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; diff --git a/map.zig b/map.zig deleted file mode 100644 index 2c442cb..0000000 --- a/map.zig +++ /dev/null @@ -1 +0,0 @@ -pub const map: [400]u8 = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 1, 1, 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37, 1, 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 50, 19, 19, 18, 1, 1, 1, 37, 1, 1, 39, 1, 1, 1, 1, 1, 50, 19, 52, 1, 1, 1, 1, 20, 1, 1, 1, 37, 1, 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 1, 37, 1, 1, 39, 1, 50, 19, 52, 1, 1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 1, 37, 1, 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 1, 37, 1, 1, 39, 1, 1, 1, 1, 1, 50, 19, 52, 1, 1, 1, 1, 51, 1, 1, 1, 37, 1, 1, 39, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 1, 37, 1, 1, 39, 1, 50, 19, 52, 1, 1, 1, 1, 1, 1, 1, 1, 51, 1, 2, 1, 37, 1, 54, 55, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 33, 19, 19, 19, 66, 54, 1, 1, 1, 1, 1, 1, 1, 50, 19, 52, 1, 1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 51, 1, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; diff --git a/map2src.zig b/map2src.zig index be80b71..4d84d6d 100644 --- a/map2src.zig +++ b/map2src.zig @@ -59,7 +59,7 @@ pub fn main() anyerror!void { defer std.json.parseFree(MapType, map, options); var outbuffer: [64 * KB]u8 = undefined; - var outcontent = try std.fmt.bufPrint(&outbuffer, "pub const map: [{}]u8 = {any};\n", .{ map.layers[0].data.len, map.layers[0].data }); + var outcontent = try std.fmt.bufPrint(&outbuffer, "pub const map: [{}]u8 = .{any};\n", .{ map.layers[0].data.len, map.layers[0].data }); _ = try output.writeAll(outcontent); } } diff --git a/src/main.zig b/src/main.zig index a07abea..1477d85 100644 --- a/src/main.zig +++ b/src/main.zig @@ -102,24 +102,25 @@ export fn start() void { } export fn update() void { + w4.DRAW_COLORS.* = 0x0004; + w4.rect(.{ 0, 0 }, .{ 160, 160 }); + world.process(1, &.{ .pos, .control }, controlProcess); world.process(1, &.{ .sprite, .staticAnim }, staticAnimProcess); world.process(1, &.{ .sprite, .controlAnim, .control }, controlAnimProcess); world.process(1, &.{ .pos, .sprite }, drawProcess); - w4.DRAW_COLORS.* = 2; - w4.text("Hello from Zig!", .{ 10, 10 }); - - if (w4.GAMEPAD1.button_1) { - w4.DRAW_COLORS.* = 4; + w4.DRAW_COLORS.* = 0x0010; + for (assets.map) |tilePlus, i| { + const tile = tilePlus - 1; + const t = w4.Vec2{ @intCast(i32, (tile % 16) * 8), @intCast(i32, (tile / 16) * 8) }; + const pos = w4.Vec2{ @intCast(i32, (i % 20) * 8), @intCast(i32, (i / 20) * 8) }; + w4.blitSub(&assets.tiles, pos, .{ 8, 8 }, t, 128, .{ .bpp = .b2 }); } - - // w4.blit(&smiley, .{ 76, 76 }, .{ 8, 8 }, .{ .bpp = .b1 }); - w4.text("Press X to blink", .{ 16, 90 }); } fn drawProcess(_: f32, pos: *Pos, sprite: *Sprite) void { - w4.DRAW_COLORS.* = 0x0030; + w4.DRAW_COLORS.* = 0x0010; const ipos = w4.Vec2{ @floatToInt(i32, pos.*[0]), @floatToInt(i32, pos.*[1]) }; const t = w4.Vec2{ @intCast(i32, (sprite.index * 8) % 128), @intCast(i32, (sprite.index * 8) / 128) }; w4.blitSub(&assets.sprites, ipos, .{ 8, 8 }, t, 128, sprite.flags);