diff --git a/build.zig b/build.zig index 876bee8..949d1dd 100644 --- a/build.zig +++ b/build.zig @@ -13,6 +13,8 @@ fn mapgen(b: *std.build.Step) !void { var deno = std.ChildProcess.init(&.{"deno", "run", "-A", "./src/tools/genmap.js", map[0], map[1]}, alloc); try deno.spawn(); _ = try deno.wait(); + + std.log.info("generated map {s}", .{map[1]}); } } @@ -22,7 +24,9 @@ fn release(b: *std.build.Step) !void { var rel = std.ChildProcess.init(&.{"bash", "./release.sh"}, alloc); try rel.spawn(); - _ = try rel.wait(); + _ = try rel.wait(); + + std.log.info("generated release assets in dist/{s}", .{""}); } pub fn build(b: *std.build.Builder) !void { @@ -31,6 +35,7 @@ pub fn build(b: *std.build.Builder) !void { const release_step = b.step("release", "generate release binaries"); release_step.makeFn = release; + release_step.dependOn(map_step); const mode = b.standardReleaseOptions(); const lib = b.addSharedLibrary("cart", "src/main.zig", .unversioned); diff --git a/maps/RPGmap.json b/maps/RPGmap.json index 795f450..9f94cb9 100644 --- a/maps/RPGmap.json +++ b/maps/RPGmap.json @@ -1,25 +1,35 @@ { "compressionlevel":-1, - "height":10, + "height":20, "infinite":false, "layers":[ { - "data":[1, 1, 1, 18, 1, 19, 20, 21, 1, 18, - 69, 1, 35, 52, 1, 36, 53, 38, 35, 52, - 1, 18, 1, 18, 86, 88, 104, 1, 18, 17, - 35, 52, 35, 52, 105, 1, 18, 35, 92, 1, - 18, 69, 1, 1, 105, 35, 52, 1, 81, 1, - 52, 35, 1, 18, 105, 67, 66, 97, 98, 99, - 1, 68, 35, 52, 105, 66, 67, 114, 115, 116, - 18, 103, 88, 88, 106, 1, 1, 100, 118, 101, - 52, 1, 1, 1, 103, 88, 88, 88, 107, 88, - 11, 13, 1, 12, 1, 69, 1, 18, 35, 52], - "height":10, + "data":[1, 2, 137, 138, 1, 2, 137, 138, 1, 2, 71, 72, 73, 74, 75, 76, 1, 2, 137, 138, + 35, 36, 171, 172, 35, 36, 171, 172, 35, 36, 105, 106, 107, 108, 109, 110, 35, 36, 171, 172, + 69, 70, 205, 206, 69, 70, 205, 206, 69, 70, 139, 140, 207, 208, 143, 144, 69, 70, 205, 206, + 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 173, 174, 241, 242, 177, 178, 103, 104, 239, 240, + 137, 138, 137, 138, 1, 2, 137, 138, 1, 2, 137, 138, 1, 2, 137, 138, 1, 2, 33, 34, + 171, 172, 171, 172, 35, 36, 171, 172, 35, 36, 171, 172, 35, 36, 171, 172, 35, 36, 67, 68, + 205, 206, 205, 206, 69, 70, 205, 206, 69, 70, 205, 206, 69, 70, 205, 206, 69, 70, 205, 206, + 239, 240, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, + 1, 2, 137, 138, 1, 2, 137, 138, 1, 2, 137, 138, 1, 2, 137, 138, 1, 2, 137, 138, + 35, 36, 171, 172, 35, 36, 171, 172, 35, 36, 171, 172, 35, 36, 171, 172, 331, 332, 171, 172, + 69, 70, 205, 206, 69, 70, 205, 206, 69, 70, 235, 236, 233, 234, 205, 364, 365, 366, 367, 206, + 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 269, 270, 267, 268, 397, 398, 399, 400, 401, 402, + 1, 2, 237, 238, 1, 2, 137, 138, 1, 2, 233, 234, 235, 236, 431, 432, 433, 434, 435, 436, + 35, 36, 271, 272, 35, 353, 354, 172, 35, 36, 267, 268, 269, 270, 465, 466, 467, 468, 469, 470, + 69, 70, 351, 352, 69, 387, 388, 206, 347, 348, 349, 350, 343, 344, 499, 500, 439, 440, 503, 504, + 103, 104, 385, 386, 103, 104, 239, 240, 381, 382, 383, 384, 377, 378, 403, 404, 473, 474, 405, 406, + 1, 2, 409, 410, 345, 346, 345, 346, 417, 418, 417, 418, 417, 418, 345, 346, 417, 418, 345, 346, + 35, 36, 443, 444, 379, 380, 379, 380, 451, 452, 451, 452, 451, 452, 379, 380, 451, 452, 379, 380, + 69, 57, 58, 206, 69, 70, 205, 206, 69, 70, 205, 206, 69, 70, 205, 206, 69, 70, 205, 206, + 90, 91, 92, 93, 103, 104, 57, 58, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240], + "height":20, "id":1, "name":"map", "opacity":1, "type":"tilelayer", "visible":true, - "width":10, + "width":20, "x":0, "y":0 }, @@ -137,8 +147,7 @@ "width":30.3636, "x":120.727, "y":86.9091 - }, - + }, { "class":"", "height":7.09091, @@ -315,14 +324,14 @@ "orientation":"orthogonal", "renderorder":"right-down", "tiledversion":"1.9.0", - "tileheight":16, + "tileheight":8, "tilesets":[ { "firstgid":1, "source":"..\/sprites\/kenney_rpg.tsx" }], - "tilewidth":16, + "tilewidth":8, "type":"map", "version":"1.9", - "width":10 + "width":20 } \ No newline at end of file diff --git a/maps/RPGmap.tmx b/maps/RPGmap.tmx index 25c8529..df84b8e 100644 --- a/maps/RPGmap.tmx +++ b/maps/RPGmap.tmx @@ -1,21 +1,31 @@ - + - + -1,1,1,18,1,19,20,21,1,18, -69,1,35,52,1,36,53,38,35,52, -1,18,1,18,86,88,104,1,18,17, -35,52,35,52,105,1,18,35,92,1, -18,69,1,1,105,35,52,1,81,1, -52,35,1,18,105,67,66,97,98,99, -1,68,35,52,105,66,67,114,115,116, -18,103,88,88,106,1,1,100,118,101, -52,1,1,1,103,88,88,88,107,88, -11,13,1,12,1,69,1,18,35,52 +1,2,137,138,1,2,137,138,1,2,71,72,73,74,75,76,1,2,137,138, +35,36,171,172,35,36,171,172,35,36,105,106,107,108,109,110,35,36,171,172, +69,70,205,206,69,70,205,206,69,70,139,140,207,208,143,144,69,70,205,206, +103,104,239,240,103,104,239,240,103,104,173,174,241,242,177,178,103,104,239,240, +137,138,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,33,34, +171,172,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,67,68, +205,206,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206, +239,240,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240, +1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138, +35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,331,332,171,172, +69,70,205,206,69,70,205,206,69,70,235,236,233,234,205,364,365,366,367,206, +103,104,239,240,103,104,239,240,103,104,269,270,267,268,397,398,399,400,401,402, +1,2,237,238,1,2,137,138,1,2,233,234,235,236,431,432,433,434,435,436, +35,36,271,272,35,353,354,172,35,36,267,268,269,270,465,466,467,468,469,470, +69,70,351,352,69,387,388,206,347,348,349,350,343,344,499,500,439,440,503,504, +103,104,385,386,103,104,239,240,381,382,383,384,377,378,403,404,473,474,405,406, +1,2,409,410,345,346,345,346,417,418,417,418,417,418,345,346,417,418,345,346, +35,36,443,444,379,380,379,380,451,452,451,452,451,452,379,380,451,452,379,380, +69,57,58,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206, +90,91,92,93,103,104,57,58,103,104,239,240,103,104,239,240,103,104,239,240 diff --git a/maps/TestMap.json b/maps/TestMap.json deleted file mode 100644 index e1c1478..0000000 --- a/maps/TestMap.json +++ /dev/null @@ -1,73 +0,0 @@ -{ "compressionlevel":-1, - "editorsettings": - { - "export": - { - "format":"json", - "target":"TestMap.json" - } - }, - "height":10, - "infinite":false, - "layers":[ - { - "data":[29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 18, 29, 29, 29, 29, 29, 29, 29, 29, 29, 38, 29, 29, 29, 29, 1, 2, 3, 4, 2, 48, 4, 2, 3, 4, 6, 50, 50, 50, 50, 50, 50, 22, 50, 23, 16, 22, 50, 23, 50, 43, 50, 50, 50, 50, 26, 41, 50, 50, 50, 50, 50, 22, 50, 50, 6, 50, 50, 50, 22, 50, 50, 50, 42, 50], - "height":10, - "id":1, - "name":"Tile Layer 1", - "opacity":1, - "type":"tilelayer", - "visible":true, - "width":10, - "x":0, - "y":0 - }, - { - "draworder":"topdown", - "id":2, - "name":"coll", - "objects":[ - { - "height":80, - "id":3, - "name":"", - "rotation":0, - "type":"", - "visible":true, - "width":160, - "x":0, - "y":80 - }, - { - "height":32, - "id":4, - "name":"", - "rotation":0, - "type":"", - "visible":true, - "width":16, - "x":80, - "y":48 - }], - "opacity":1, - "type":"objectgroup", - "visible":true, - "x":0, - "y":0 - }], - "nextlayerid":3, - "nextobjectid":5, - "orientation":"orthogonal", - "renderorder":"right-down", - "tiledversion":"1.4.3", - "tileheight":16, - "tilesets":[ - { - "firstgid":1, - "source":"..\/sprites\/Cave.tsx" - }], - "tilewidth":16, - "type":"map", - "version":1.4, - "width":10 -} \ No newline at end of file diff --git a/maps/TestMap.tmx b/maps/TestMap.tmx deleted file mode 100644 index eb9fea3..0000000 --- a/maps/TestMap.tmx +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - -29,29,29,29,29,29,29,29,29,29, -29,29,29,29,29,29,29,29,29,29, -29,29,29,29,29,29,29,29,29,29, -29,29,29,29,29,18,29,29,29,29, -29,29,29,29,29,38,29,29,29,29, -1,2,3,4,2,48,4,2,3,4, -6,50,50,50,50,50,50,22,50,23, -16,22,50,23,50,43,50,50,50,50, -26,41,50,50,50,50,50,22,50,50, -6,50,50,50,22,50,50,50,42,50 - - - - - - - diff --git a/release.sh b/release.sh index ca7c293..ca2731c 100755 --- a/release.sh +++ b/release.sh @@ -4,10 +4,9 @@ set -ex mkdir -p dist rm -rf dist/* -zig build mapgen zig build -Drelease-small=true +wasm-strip ./zig-out/lib/cart.wasm wasm-opt -Oz --strip-producers --dce ./zig-out/lib/cart.wasm -o ./dist/tamamo.wasm -wasm-strip ./dist/tamamo.wasm w4 bundle \ --windows ./dist/tamamo.exe \ --mac ./dist/tamamo.macOS \ diff --git a/sprites/kenney_rpg.tsx b/sprites/kenney_rpg.tsx index 214cba9..91b1c24 100644 --- a/sprites/kenney_rpg.tsx +++ b/sprites/kenney_rpg.tsx @@ -1,4 +1,4 @@ - - - - + + + + diff --git a/src/main.zig b/src/main.zig index cce4fcc..d27cc21 100644 --- a/src/main.zig +++ b/src/main.zig @@ -20,27 +20,16 @@ var mara_box: Rect = Rect{.base = map.start_point, .width = 16, .height = 16}; var mara_speed: u16 = 0; var screen = Rect{.base = Point{.x = 0, .y = 0}, .width = 160, .height = 160}; -const screen_width = 10; -const screen_height = 10; -var camera: [screen_height * screen_width]u8 = [_]u8{0} ** (screen_height * screen_width); +const screen_width = 20; +const screen_height = 20; var sound_timer: u8 = 0; var textBuf: [160]u8 = undefined; -var done: bool = true; +var done: bool = false; export fn start() void { palette.mist(); - - var col: u32 = 0; - while(col < screen_width) { - defer col += 1; - var row: u32 = 0; - while(row < screen_height) { - defer row += 1; - camera[row * screen_width + col] = map.data[row * screen_width + col]; - } - } } fn bonk() void { @@ -85,23 +74,23 @@ fn drawMap() !void { while (row < screen_height) { defer row += 1; - var tile = camera[col * map.width + row]; + var tile = map.data[col * map.width + row]; var tileX = tile % map.ts_width; var tileY = tile / map.ts_width; - // if (!done) { - // var buf = fmt.bufPrint(&textBuf, "{},{}: {}: {},{}", .{col, row, tile, tileX, tileY}) catch unreachable; - // w4.trace(buf); - // } + if (!done) { + var buf = fmt.bufPrint(&textBuf, "{},{}: {}: {},{}", .{col, row, tile, tileX, tileY}) catch unreachable; + w4.trace(buf); + } w4.blitSub( &sprites.kenney_rpg, - row * 16, - col * 16, - 16, - 16, - @intCast(u32, tileX) * 16, - @intCast(u32, tileY) * 16, + row * 8, + col * 8, + 8, + 8, + @intCast(u32, tileX) * 8, + @intCast(u32, tileY) * 8, sprites.kenney_rpg_width, w4.BlitFlags{.two_bits = true}, ); diff --git a/src/maps/rpg.zig b/src/maps/rpg.zig index 25b324c..c03d8ca 100644 --- a/src/maps/rpg.zig +++ b/src/maps/rpg.zig @@ -3,26 +3,58 @@ const sh0rk = @import("../sh0rk.zig"); const Direction = sh0rk.Direction; const Point = sh0rk.Point; +const Tileset = sh0rk.Tileset; const Trigger = sh0rk.Trigger; const Rect = sh0rk.Rect; -pub const width = 10; -pub const height = 10; +pub const width = 20; +pub const height = 20; -pub const ts_width = 17; -pub const ts_height = 8; +pub const tileset: Tileset = .Rpg; +pub const ts_width = 34; +pub const ts_height = 16; -pub const data = [100]u8{ - 0, 0, 0, 17, 0, 18, 19, 20, 0, 17, 68, - 0, 34, 51, 0, 35, 52, 37, 34, 51, 0, - 17, 0, 17, 85, 87, 103, 0, 17, 16, 34, - 51, 34, 51, 104, 0, 17, 34, 91, 0, 17, - 68, 0, 0, 104, 34, 51, 0, 80, 0, 51, - 34, 0, 17, 104, 66, 65, 96, 97, 98, 0, - 67, 34, 51, 104, 65, 66, 113, 114, 115, 17, - 102, 87, 87, 105, 0, 0, 99, 117, 100, 51, - 0, 0, 0, 102, 87, 87, 87, 106, 87, 10, - 12, 0, 11, 0, 68, 0, 17, 34, 51, +pub const data = [400]u9{ + 0, 1, 136, 137, 0, 1, 136, 137, 0, 1, 70, + 71, 72, 73, 74, 75, 0, 1, 136, 137, 34, + 35, 170, 171, 34, 35, 170, 171, 34, 35, 104, + 105, 106, 107, 108, 109, 34, 35, 170, 171, 68, + 69, 204, 205, 68, 69, 204, 205, 68, 69, 138, + 139, 206, 207, 142, 143, 68, 69, 204, 205, 102, + 103, 238, 239, 102, 103, 238, 239, 102, 103, 172, + 173, 240, 241, 176, 177, 102, 103, 238, 239, 136, + 137, 136, 137, 0, 1, 136, 137, 0, 1, 136, + 137, 0, 1, 136, 137, 0, 1, 32, 33, 170, + 171, 170, 171, 34, 35, 170, 171, 34, 35, 170, + 171, 34, 35, 170, 171, 34, 35, 66, 67, 204, + 205, 204, 205, 68, 69, 204, 205, 68, 69, 204, + 205, 68, 69, 204, 205, 68, 69, 204, 205, 238, + 239, 238, 239, 102, 103, 238, 239, 102, 103, 238, + 239, 102, 103, 238, 239, 102, 103, 238, 239, 0, + 1, 136, 137, 0, 1, 136, 137, 0, 1, 136, + 137, 0, 1, 136, 137, 0, 1, 136, 137, 34, + 35, 170, 171, 34, 35, 170, 171, 34, 35, 170, + 171, 34, 35, 170, 171, 330, 331, 170, 171, 68, + 69, 204, 205, 68, 69, 204, 205, 68, 69, 234, + 235, 232, 233, 204, 363, 364, 365, 366, 205, 102, + 103, 238, 239, 102, 103, 238, 239, 102, 103, 268, + 269, 266, 267, 396, 397, 398, 399, 400, 401, 0, + 1, 236, 237, 0, 1, 136, 137, 0, 1, 232, + 233, 234, 235, 430, 431, 432, 433, 434, 435, 34, + 35, 270, 271, 34, 352, 353, 171, 34, 35, 266, + 267, 268, 269, 464, 465, 466, 467, 468, 469, 68, + 69, 350, 351, 68, 386, 387, 205, 346, 347, 348, + 349, 342, 343, 498, 499, 438, 439, 502, 503, 102, + 103, 384, 385, 102, 103, 238, 239, 380, 381, 382, + 383, 376, 377, 402, 403, 472, 473, 404, 405, 0, + 1, 408, 409, 344, 345, 344, 345, 416, 417, 416, + 417, 416, 417, 344, 345, 416, 417, 344, 345, 34, + 35, 442, 443, 378, 379, 378, 379, 450, 451, 450, + 451, 450, 451, 378, 379, 450, 451, 378, 379, 68, + 56, 57, 205, 68, 69, 204, 205, 68, 69, 204, + 205, 68, 69, 204, 205, 68, 69, 204, 205, 89, + 90, 91, 92, 102, 103, 56, 57, 102, 103, 238, + 239, 102, 103, 238, 239, 102, 103, 238, 239, }; pub const coll = [_]Rect{ diff --git a/src/maps/rpgbig.zig b/src/maps/rpgbig.zig index 8a598bd..e251720 100644 --- a/src/maps/rpgbig.zig +++ b/src/maps/rpgbig.zig @@ -3,16 +3,18 @@ const sh0rk = @import("../sh0rk.zig"); const Direction = sh0rk.Direction; const Point = sh0rk.Point; +const Tileset = sh0rk.Tileset; const Trigger = sh0rk.Trigger; const Rect = sh0rk.Rect; pub const width = 20; pub const height = 20; -pub const ts_width = 17; -pub const ts_height = 8; +pub const tileset: Tileset = .Rpg; +pub const ts_width = 34; +pub const ts_height = 16; -pub const data = [400]u8{ +pub const data = [400]u9{ 0, 0, 0, 17, 0, 18, 19, 20, 0, 17, 0, 17, 18, 67, 20, 17, 0, 17, 19, 17, 68, 0, 34, 51, 0, 35, 52, 37, 34, 51, 34, diff --git a/src/maps/test.zig b/src/maps/test.zig deleted file mode 100644 index 0891616..0000000 --- a/src/maps/test.zig +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by ./src/tools/genmap.js ./maps/TestMap.json, DO NOT EDIT - -const sh0rk = @import("../sh0rk.zig"); -const Direction = sh0rk.Direction; -const Point = sh0rk.Point; -const Trigger = sh0rk.Trigger; -const Rect = sh0rk.Rect; - -pub const width = 10; -pub const height = 10; - -pub const ts_width = 10; -pub const ts_height = 5; - -pub const coll = [_]Rect{ - Rect{.base = Point{.x = 0, .y = 80}, .width = 160, .height = 80}, - Rect{.base = Point{.x = 80, .y = 48}, .width = 16, .height = 32}, -}; - diff --git a/src/sh0rk.zig b/src/sh0rk.zig index 715de15..964765f 100644 --- a/src/sh0rk.zig +++ b/src/sh0rk.zig @@ -47,7 +47,8 @@ pub const Trigger = struct { dialogue: []const u8, }; -pub const Tile = packed struct { - x: u4, - y: u4, +pub const Tileset = enum(u2) { + Cave, + Rpg, + Dungeon, }; \ No newline at end of file diff --git a/src/tools/genmap.js b/src/tools/genmap.js index 5ae236d..5b8ae03 100644 --- a/src/tools/genmap.js +++ b/src/tools/genmap.js @@ -17,6 +17,7 @@ out += `const sh0rk = @import("../sh0rk.zig");\n`; out += `const Direction = sh0rk.Direction;\n`; out += `const Point = sh0rk.Point;\n`; +out += `const Tileset = sh0rk.Tileset;\n`; out += `const Trigger = sh0rk.Trigger;\n`; out += `const Rect = sh0rk.Rect;\n\n`; @@ -33,24 +34,27 @@ let tilesheet = { map.tilesets.forEach(tset => { if (tset.source.includes("kenney")) { tilesheet = { - width: 17, - height: 8, + width: 34, + height: 16, + name: "Rpg", }; } if (tset.source.includes("Cave")) { tilesheet = { - width: 10, + width: 14, height: 5, + name: "Cave", } } }); +out += `pub const tileset: Tileset = .${tilesheet.name};\n`; out += `pub const ts_width = ${tilesheet.width};\n`; out += `pub const ts_height = ${tilesheet.height};\n\n`; const genMap = (tiles) => { - out += `pub const data = [${tiles.data.length}]u8{\n `; + out += `pub const data = [${tiles.data.length}]u9{\n `; tiles.data.forEach((tile, index) => { tile -= 1;