aboutsummaryrefslogtreecommitdiff
path: root/src/level.zig
diff options
context:
space:
mode:
authortslil clingman <>2021-10-15 17:11:06 -0400
committertslil clingman <>2021-10-15 17:11:06 -0400
commit61856ed5407a227aab35d7b800daad883c265dd9 (patch)
treea864bf8f06835fa6b1723f9d1271864d5ec4721b /src/level.zig
parentb45b9388cfd96fa5e89ea11db99ee11a1c95386a (diff)
Well, there's no reason not to do this ... Multiple polygon layers!
Diffstat (limited to 'src/level.zig')
-rw-r--r--src/level.zig57
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);