diff options
Diffstat (limited to 'src/level.zig')
| -rw-r--r-- | src/level.zig | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/src/level.zig b/src/level.zig index 87c3e80..81a0e67 100644 --- a/src/level.zig +++ b/src/level.zig @@ -17,37 +17,48 @@ const std = @import("std"); -pub const Object = struct { - height: f32, - width: f32, - texture: u8, - pos_x: f32, - pos_y: f32, - pos_z: f32 = 0, +pub const Layer = struct { + pub const MAX_VERTS = 16; + + height : f32 = 0, + vertical_texture : u8 = 0, + horizontal_texture : u8 = 0, + // What happened to this error? Is it comptime? + vertices: std.BoundedArray([2]f32, MAX_VERTS), }; pub const Cell = struct { - floor_height: f32 = 0, - ceiling_height: f32 = DEFAULT_HEIGHT, - draw_down: bool = false, - lower_texture: u8 = 0, - upper_texture: u8 = 0, - floor_texture: u8 = 0, - ceiling_texture: u8 = 2, + pub const MAX_LAYERS = 16; + // floor_height: f32 = 0, + // ceiling_height: f32 = DEFAULT_HEIGHT, + // draw_down: bool = false, + // lower_texture: u8 = 0, + // upper_texture: u8 = 0, + // floor_texture: u8 = 0, + // ceiling_texture: u8 = 2, - vertices: []const [2]f32 = &[_][2]f32{ - .{ 0.25, 0.25 }, - .{ 0.75, 0.25 }, - .{ 0.75, 0.75 }, - .{ 0.25, 0.75 }, - .{ 0.25, 0.25 }, - }, + lower_layers : std.BoundedArray(Layer, MAX_LAYERS), - pub const floor = Cell{}; + // I'm not sure how i feel about reaching into the implementation of + // BoundedArray like this. Surely there should be an ``.empty'' or something + // default? + fn empty() !Cell { + const lower_layers = try std.BoundedArray(Layer, MAX_LAYERS).init(0); + return Cell{ . lower_layers = lower_layers }; + } pub const DEFAULT_HEIGHT: f32 = 4; }; +pub const Object = struct { + height: f32, + width: f32, + texture: u8, + pos_x: f32, + pos_y: f32, + pos_z: f32 = 0, +}; + pub const Map = struct { width: u32, height: u32, @@ -63,7 +74,7 @@ pub const Map = struct { pub fn new(width: u32, height: u32, alloc: *std.mem.Allocator) !Map { var cells = std.ArrayList(Cell).init(alloc); try cells.ensureTotalCapacity(width * height); - try cells.appendNTimes(Cell.floor, width * height); + try cells.appendNTimes(try Cell.empty(), width * height); var objects = std.ArrayList(Object).init(alloc); |
