aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig43
1 files changed, 9 insertions, 34 deletions
diff --git a/src/main.zig b/src/main.zig
index 866b831..f51c3a3 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -28,34 +28,6 @@ const constants = @import("constants.zig");
const raycast = @import("raycast.zig");
const level = @import("level.zig");
-// TODO: is there anyway i can say fn renderSlice : RenderSliceFunction?
-fn renderSlice(
- window: sf.graphics.RenderWindow,
- sprite: sf.graphics.Sprite,
- col: i32, // which column
- top: f32, // top of wall
- total_height: f32, // how tall
- draw_frac: f32,
- texfrac: f32, // how far along the texture
- texture: u8, // which texture index
-) void {
-
- // we need ceil here so that we draw always to or past the edge of the screen
- const draw_height = @floatToInt(c_int, std.math.ceil(draw_frac * constants.TextureDim));
- const total_length = total_height * constants.VFact;
-
- const xpos = @intToFloat(f32, col) * constants.HFact;
- const ypos = constants.ScreenHeight / 2 + (constants.PlaneHeight / 2 - top) * constants.VFact;
-
- const tind = @as(c_int, texture) * @floatToInt(c_int, constants.TextureDim);
- const left = tind + @floatToInt(c_int, texfrac * constants.TextureDim);
-
- sprite.setPosition(.{ .x = xpos, .y = ypos });
- sprite.setScale(.{ .x = constants.HFact, .y = total_length / constants.TextureDim });
- sprite.setTextureRect(.{ .top = 0, .left = left, .width = 1, .height = draw_height });
- window.draw(sprite, null);
-}
-
pub fn main() !void {
const PI = std.math.pi;
@@ -193,12 +165,15 @@ pub fn main() !void {
});
window.draw(back_sprite, null);
- // Then render the walls
- try player.renderFloorsToTexture(floors_image, rendered_floors_texture, map);
- window.draw(rendered_floors_sprite, null);
-
- // Finally the world
- player.renderWorld(window, walls_sprite, objects_sprite, renderSlice, map);
+ try player.renderWorld(
+ window,
+ walls_sprite,
+ objects_sprite,
+ floors_image,
+ rendered_floors_texture,
+ rendered_floors_sprite,
+ map,
+ );
window.display();