aboutsummaryrefslogtreecommitdiff
path: root/src/map.zig
diff options
context:
space:
mode:
authortslil clingman <>2021-09-05 11:43:38 -0400
committertslil clingman <>2021-09-05 11:43:38 -0400
commitb1086c978996e522f133b4c6bdc59c95016eec0a (patch)
tree887eea5fb8f49beb8aeee408cc283f91cf70dd53 /src/map.zig
parentf45ce44d41930391354c5086a833d63e8791c0bd (diff)
Sprite rendering skeleton!
Except that i'm not satisfied. It would appear that we're computing various distances more-or-less exactly in the sprite rendering process, but this is at odds with the walls and floors which -- by virtue of the linear interpolation garbage -- don't agree about where things are. The net result is that there are at least two fudge factors: - to account to for the incorrect height of the floors i shift the sprites up by 0.2 - to account for the incorrect wall distances i add 1 to the z_buffer comparison These fudges are ugly and empirical. Still to do: for more than one object we have to sort by distance first!
Diffstat (limited to 'src/map.zig')
-rw-r--r--src/map.zig14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/map.zig b/src/map.zig
index 8093e21..92ca5be 100644
--- a/src/map.zig
+++ b/src/map.zig
@@ -20,6 +20,14 @@ const std = @import("std");
// Let's pretend that our units are meters
pub const MAX_HEIGHT: f32 = 2.5;
+pub const Object = struct {
+ height : f32,
+ width : f32,
+ texture : u8,
+ pos_x : f32,
+ pos_y : f32,
+};
+
pub const Cell = struct {
height: f32,
wall_texture: u8 = 0,
@@ -34,9 +42,11 @@ pub const Map = struct {
height: u32,
size: f32 = 64,
cells: std.ArrayList(Cell),
+ objects: std.ArrayList(Object),
pub fn deinit(self: Map) void {
self.cells.deinit();
+ self.objects.deinit();
}
pub fn new(width: u32, height: u32, alloc: *std.mem.Allocator) !Map {
@@ -44,7 +54,9 @@ pub const Map = struct {
try cells.ensureTotalCapacity(width * height);
try cells.appendNTimes(Cell.floor, width * height);
- return Map{ .width = width, .height = height, .cells = cells };
+ var objects = std.ArrayList(Object).init(alloc);
+
+ return Map{ .width = width, .height = height, .cells = cells, .objects = objects };
}
pub fn inBounds(self: Map, x: i32, y: i32) bool {