From d4f2376bb0ea219b79dac3f4f37b77342ca6ef4a Mon Sep 17 00:00:00 2001 From: tslil clingman <> Date: Thu, 7 Oct 2021 11:25:09 -0400 Subject: Variable height ceilings! Plus bonus graphical artefacts around the edges of such! In the end the majority of this code was rather easy: take the upwards floor drawing code and reflect it. However, there were many edge-cases and plenty of off-by-one pixels and rounding issues that didn't quite work the same way going down as they do going up. Also the object drawing code used to take advantage of the fact that the z-buffer was painted bottom-up only, so that required change too. --- src/main.zig | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index 5754793..d76e424 100644 --- a/src/main.zig +++ b/src/main.zig @@ -48,18 +48,34 @@ pub fn main() !void { var y: u32 = 0; while (y < 16) : (y += 1) { - map.cells.items[y * 16 + 00] = level.Cell{ .height = constants.MAX_HEIGHT }; - map.cells.items[y * 16 + 15] = level.Cell{ .height = constants.MAX_HEIGHT, .wall_texture = 2 }; - map.cells.items[15 * 16 + y] = level.Cell{ .height = constants.MAX_HEIGHT }; - map.cells.items[00 * 16 + y] = level.Cell{ .height = constants.MAX_HEIGHT }; + map.cells.items[y * 16 + 00] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT }; + map.cells.items[y * 16 + 15] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT, .lower_texture = 2 }; + map.cells.items[15 * 16 + y] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT }; + map.cells.items[00 * 16 + y] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT }; + + if (y < 15) { + map.cells.items[y * 16 + 01] = level.Cell{ + .ceiling_height = 3, + .upper_texture = 3, + .draw_down = true, + }; + } } - map.cells.items[16 * 7 + 7] = level.Cell{ .height = constants.MAX_HEIGHT, .wall_texture = 1 }; - map.cells.items[16 * 7 + 6] = level.Cell{ .height = constants.MAX_HEIGHT / 4, .wall_texture = 1, .floor_texture = 1 }; - - try map.objects.append(level.Object{ .pos_x = 5.5, .pos_y = 7.5, .pos_z = 1, .texture = 2, .height = 1, .width = 1 }); - try map.objects.append(level.Object{ .pos_x = 4, .pos_y = 8.5, .texture = 1, .height = 1, .width = 1 }); - try map.objects.append(level.Object{ .pos_x = 6.5, .pos_y = 8.5, .texture = 0, .height = 1, .width = 1 }); + map.cells.items[16 * 7 + 7] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT, .lower_texture = 1 }; + map.cells.items[16 * 7 + 6] = level.Cell{ + .floor_height = 0.5, + .ceiling_height = 2, + .lower_texture = 1, + .upper_texture = 1, + .floor_texture = 1, + .ceiling_texture = 1, + .draw_down = true, + }; + + try map.objects.append(level.Object{ .pos_x = 1.5, .pos_y = 7.5, .pos_z = 2, .texture = 2, .height = 1, .width = 1 }); + try map.objects.append(level.Object{ .pos_x = 4, .pos_y = 8.5, .texture = 0, .height = 1, .width = 1 }); + try map.objects.append(level.Object{ .pos_x = 6, .pos_y = 8.5, .texture = 1, .height = 1, .width = 1 }); // Initialise SFML //-------------------------------------------------------------------------- -- cgit v1.3.1