aboutsummaryrefslogtreecommitdiff
path: root/src/main.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/main.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/main.zig')
-rw-r--r--src/main.zig24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig
index 2d12975..8129ae2 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -28,8 +28,8 @@ usingnamespace @import("raycast.zig");
usingnamespace @import("renderConstants.zig");
usingnamespace @import("map.zig");
-// TODO: is there anyway i can say fn renderWall : RenderWallFunction?
-fn renderWall(
+// TODO: is there anyway i can say fn renderSlice : RenderSliceFunction?
+fn renderSlice(
window: sf.graphics.RenderWindow,
sprite: sf.graphics.Sprite,
col: i32, // which column
@@ -77,13 +77,15 @@ pub fn main() !void {
var y: u32 = 0;
while (y < 32) : (y += 1) {
map.cells.items[y * 32 + 00] = Cell{ .height = MAX_HEIGHT };
- map.cells.items[y * 32 + 31] = Cell{ .height = MAX_HEIGHT };
+ map.cells.items[y * 32 + 31] = Cell{ .height = MAX_HEIGHT, .wall_texture = 2 };
map.cells.items[31 * 32 + y] = Cell{ .height = MAX_HEIGHT };
map.cells.items[00 * 32 + y] = Cell{ .height = MAX_HEIGHT };
}
- map.cells.items[y * 15 + 15] = Cell{ .height = MAX_HEIGHT, .wall_texture = 1 };
- map.cells.items[y * 15 + 14] = Cell{ .height = MAX_HEIGHT / 3, .wall_texture = 1, .floor_texture = 1 };
+ map.cells.items[32 * 15 + 15] = Cell{ .height = MAX_HEIGHT, .wall_texture = 1 };
+ map.cells.items[32 * 15 + 14] = Cell{ .height = MAX_HEIGHT / 3, .wall_texture = 1, .floor_texture = 1 };
+
+ try map.objects.append(Object{.pos_x = 14.5, .pos_y = 16.5, .texture = 0, .height = 1.5, .width = 1});
// Initialise SFML
//--------------------------------------------------------------------------
@@ -117,7 +119,15 @@ pub fn main() !void {
var walls_sprite = try sf.Sprite.createFromTexture(wall_textures);
defer walls_sprite.destroy();
- // Load floor textures
+ // Load sprite textures
+ var object_textures = try sf.Texture.createFromFile("objects.png");
+ defer object_textures.destroy();
+ object_textures.setSmooth(false);
+
+ var objects_sprite = try sf.Sprite.createFromTexture(object_textures);
+ defer objects_sprite.destroy();
+
+ // Load floor image
var floors_image = try sf.Image.createFromFile("floors.png");
defer floors_image.destroy();
@@ -187,7 +197,7 @@ pub fn main() !void {
window.draw(rendered_floors_sprite, null);
// Finally the world
- player.renderWorld(window, walls_sprite, map, renderWall);
+ player.renderWorld(window, walls_sprite, objects_sprite, renderSlice, map);
window.display();