From 78c3049172469899fb791f530dea0540933e93b6 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Sat, 2 Jul 2022 09:21:51 -0400 Subject: [PATCH] more progress on drawing big maps Signed-off-by: Xe Iaso --- maps/RPGmap.json | 6 ++-- maps/RPGmap.tmx | 4 +-- src/main.zig | 78 ++++++++++++++++++++---------------------- src/maps/overworld.zig | 4 +-- 4 files changed, 44 insertions(+), 48 deletions(-) diff --git a/maps/RPGmap.json b/maps/RPGmap.json index df5b6d8..fba32d9 100644 --- a/maps/RPGmap.json +++ b/maps/RPGmap.json @@ -22,7 +22,7 @@ 1, 2, 409, 410, 345, 346, 345, 346, 417, 121, 121, 121, 121, 418, 345, 346, 417, 418, 345, 346, 345, 346, 345, 346, 345, 346, 345, 346, 345, 346, 345, 346, 345, 346, 345, 346, 345, 346, 345, 346, 35, 36, 443, 444, 379, 380, 379, 380, 451, 452, 451, 452, 451, 452, 379, 380, 451, 452, 379, 380, 379, 380, 379, 380, 379, 380, 379, 380, 379, 380, 379, 380, 379, 380, 379, 380, 379, 380, 379, 380, 69, 57, 58, 206, 69, 70, 205, 206, 69, 307, 205, 206, 69, 70, 205, 206, 39, 40, 205, 206, 69, 70, 205, 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, 73, 74, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, + 90, 91, 92, 93, 57, 58, 57, 58, 103, 104, 239, 240, 103, 104, 239, 240, 73, 74, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 91, 92, 91, 92, 91, 92, 91, 92, 93, 21, 137, 138, 1, 2, 137, 138, 1, 2, 137, 138, 1, 2, 137, 138, 1, 2, 137, 138, 1, 2, 137, 138, 1, 2, 137, 138, 1, 2, 137, 138, 125, 126, 125, 126, 125, 126, 125, 126, 127, 94, 171, 172, 35, 36, 171, 172, 35, 36, 171, 172, 35, 36, 171, 172, 35, 36, 171, 172, 35, 36, 171, 172, 35, 36, 171, 172, 35, 36, 171, 172, 159, 160, 159, 160, 159, 160, 159, 160, 70, 26, 205, 206, 69, 70, 205, 206, 69, 70, 205, 206, 69, 70, 205, 206, 69, 70, 205, 206, 69, 70, 205, 206, 69, 70, 205, 206, 69, 70, 205, 206, @@ -358,8 +358,8 @@ "rotation":0, "visible":true, "width":16, - "x":72, - "y":64 + "x":32, + "y":31 }], "opacity":1, "type":"objectgroup", diff --git a/maps/RPGmap.tmx b/maps/RPGmap.tmx index 0bacfa0..b5414a6 100644 --- a/maps/RPGmap.tmx +++ b/maps/RPGmap.tmx @@ -25,7 +25,7 @@ 1,2,409,410,345,346,345,346,417,121,121,121,121,418,345,346,417,418,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346,345,346, 35,36,443,444,379,380,379,380,451,452,451,452,451,452,379,380,451,452,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380,379,380, 69,57,58,206,69,70,205,206,69,307,205,206,69,70,205,206,39,40,205,206,69,70,205,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,73,74,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240, +90,91,92,93,57,58,57,58,103,104,239,240,103,104,239,240,73,74,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240,103,104,239,240, 91,92,91,92,91,92,91,92,93,21,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138,1,2,137,138, 125,126,125,126,125,126,125,126,127,94,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172,35,36,171,172, 159,160,159,160,159,160,159,160,70,26,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206,69,70,205,206, @@ -94,6 +94,6 @@ - + diff --git a/src/main.zig b/src/main.zig index e636545..66e81e0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -73,30 +73,45 @@ fn bonk() void { } fn drawMap() !void { - w4.m.colors.* = .{ - ._0 = .p3, - ._1 = .p2, - ._2 = .p1, - ._3 = .p0, - }; - + switch (map.tileset) { + .Dungeon => { + w4.m.colors.* = .{ + ._0 = .p2, + ._1 = .p0, + ._2 = .p1, + ._3 = .p3, + }; + }, + .Rpg => { + w4.m.colors.* = .{ + ._0 = .p3, + ._1 = .p2, + ._2 = .p1, + ._3 = .p0, + }; + }, + } if (!done) { var buf = fmt.bufPrint(&textBuf, "camera: {},{}", .{ camera.x, camera.y }) catch unreachable; w4.trace(buf); } - var startCol: i32 = @divTrunc(camera.x, screen_width); + var startCol: i32 = @divTrunc(camera.x, tile_size); var endCol = startCol + screen_width; - var startRow: i32 = @divTrunc(camera.y, screen_height); + var startRow: i32 = @divTrunc(camera.y, tile_size); var endRow = startRow + screen_height; - var offsetX = -camera.x + startCol * tile_size; - var offsetY = -camera.y + startRow * tile_size; + var offsetX = startCol * tile_size; + var offsetY = startRow * tile_size; if (!done) { var buf = fmt.bufPrint(&textBuf, "{},{}: {},{}", .{ startCol, startRow, endCol, endRow }) catch unreachable; w4.trace(buf); } + if (!done) { + var buf = fmt.bufPrint(&textBuf, "offx: {}, offy: {}", .{ offsetX, offsetY }) catch unreachable; + w4.trace(buf); + } var col: i32 = startCol; while (col < endCol) { @@ -105,43 +120,24 @@ fn drawMap() !void { while (row < endRow) { defer row += 1; - var tile = map.data[@intCast(usize, col) * map.width + @intCast(usize, row)]; + var tile = map.data[@intCast(u32, col) * map.width + @intCast(u32, row)]; - var x = (row - startCol) * tile_size + offsetX; - var y = (col - startRow) * tile_size + offsetY; + var x = (row - startCol) * tile_size - offsetX; + var y = (col - startRow) * tile_size - offsetY; + + if (x < 0) { + x = x * -1; + } + if (y < 0) { + y = y * -1; + } if (!done) { var buf = fmt.bufPrint(&textBuf, "{},{}: {}: {},{}", .{ col, row, tile, x, y }) catch unreachable; w4.trace(buf); } - var tileX = (tile - 1) % map.ts_width; - var tileY = (tile - 1) / map.ts_width; - - switch (map.tileset) { - .Rpg => w4.blitSub( - &sprites.kenney_rpg, - @intCast(u32, x), - @intCast(u32, y), - 8, - 8, - @intCast(u32, tileX) * 8, - @intCast(u32, tileY) * 8, - sprites.kenney_rpg_width, - w4.BlitFlags{ .two_bits = true }, - ), - .Dungeon => w4.blitSub( - &sprites.dungeon, - @intCast(u32, x), - @intCast(u32, y), - 8, - 8, - @intCast(u32, tileX) * 8, - @intCast(u32, tileY) * 8, - sprites.dungeon_width, - w4.BlitFlags{ .two_bits = true }, - ), - } + draw_tile(tile, @intCast(u32, x), @intCast(u32, y)); } } } diff --git a/src/maps/overworld.zig b/src/maps/overworld.zig index ed4e26c..9cb8f51 100644 --- a/src/maps/overworld.zig +++ b/src/maps/overworld.zig @@ -91,7 +91,7 @@ pub const data = [1600]u9{ 206, 69, 70, 205, 206, 39, 40, 205, 206, 69, 70, 205, 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, + 91, 92, 93, 57, 58, 57, 58, 103, 104, 239, 240, 103, 104, 239, 240, 73, 74, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 103, 104, 239, 240, 91, @@ -202,5 +202,5 @@ pub const triggers = [_]Trigger{ Trigger{.aura = Rect{.base = Point{.x = 96, .y = 103}, .width = 7, .height = 16}, .direction = Direction.Up, .dialogue = "Moar ded."}, // gravestone 2 }; -pub const start_point = Point{ .x = 72, .y = 64 }; +pub const start_point = Point{ .x = 32, .y = 31 };