more progress on drawing big maps

Signed-off-by: Xe Iaso <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-07-02 09:21:51 -04:00
parent ea5e635635
commit 78c3049172
4 changed files with 44 additions and 48 deletions

View File

@ -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",

View File

@ -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 @@
</object>
</objectgroup>
<objectgroup id="4" name="spc">
<object id="33" name="mara_start" x="72" y="64" width="16" height="16"/>
<object id="33" name="mara_start" x="32" y="31" width="16" height="16"/>
</objectgroup>
</map>

View File

@ -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));
}
}
}

View File

@ -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 };