aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortslil clingman <>2021-09-10 00:02:18 -0400
committertslil clingman <>2021-09-10 00:02:18 -0400
commitf59d8c3b31781c4093aa526d7f66544d132765e9 (patch)
tree732a1fa0cb1a9d5b543c69074f17fedbc0eebfa6
parent9e15cb6352c9afc771c41451dea86b93e35349e5 (diff)
Textures repeat rather than scale?
-rw-r--r--src/constants.zig3
-rw-r--r--src/main.zig3
-rw-r--r--src/raycast.zig4
3 files changed, 6 insertions, 4 deletions
diff --git a/src/constants.zig b/src/constants.zig
index 5c89b94..1ca0c4f 100644
--- a/src/constants.zig
+++ b/src/constants.zig
@@ -14,6 +14,7 @@
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
pub const ScreenWidth: f32 = 1024;
pub const ScreenHeight: f32 = 768;
@@ -28,4 +29,4 @@ pub const BackTextureHeight: f32 = 240;
pub const TextureDim: f32 = 32.0;
-pub const MAX_HEIGHT: f32 = 1;
+pub const MAX_HEIGHT: f32 = 2;
diff --git a/src/main.zig b/src/main.zig
index 2dec9be..866b831 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -85,7 +85,7 @@ pub fn main() !void {
map.cells.items[16 * 7 + 7] = level.Cell{ .height = constants.MAX_HEIGHT, .wall_texture = 1 };
map.cells.items[16 * 7 + 6] = level.Cell{ .height = constants.MAX_HEIGHT / 3, .wall_texture = 1, .floor_texture = 1 };
- try map.objects.append(level.Object{ .pos_x = 5.5, .pos_y = 7.5, .pos_z = 0, .texture = 2, .height = 1, .width = 1 });
+ try map.objects.append(level.Object{ .pos_x = 5.5, .pos_y = 7.5, .pos_z = 1, .texture = 2, .height = 1, .width = 1 });
try map.objects.append(level.Object{ .pos_x = 4, .pos_y = 8.5, .texture = 1, .height = 1, .width = 1 });
try map.objects.append(level.Object{ .pos_x = 6.5, .pos_y = 8.5, .texture = 0, .height = 1, .width = 1 });
@@ -116,6 +116,7 @@ pub fn main() !void {
// Load wall textures
var wall_textures = try sf.Texture.createFromFile("walls.png");
defer wall_textures.destroy();
+ wall_textures.setRepeated(true);
wall_textures.setSmooth(false); // looks worse => better!
var walls_sprite = try sf.Sprite.createFromTexture(wall_textures);
diff --git a/src/raycast.zig b/src/raycast.zig
index 6711cb2..41fea5d 100644
--- a/src/raycast.zig
+++ b/src/raycast.zig
@@ -287,7 +287,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type {
// as well as the fraction we'll be drawing
const draw_length = top - highest_point;
- const draw_frac = std.math.clamp(draw_length / total_length, 0, 1);
+ const draw_frac = cell.height * std.math.clamp(draw_length / total_length, 0, 1);
// we need the distance to calculate the fractional
// part of the relevant coordinate for texture
@@ -300,7 +300,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type {
if ((horizontal_hit and sinra < 0) or (!horizontal_hit and cosra > 0)) texfrac = 1 - texfrac;
// draw the wall
- renderSlice(window, walls_sprite, col, top, total_length, draw_frac, texfrac, cell.wall_texture);
+ renderSlice(window, walls_sprite, col, top, total_length / cell.height, draw_frac, texfrac, cell.wall_texture);
// record that there's a wall here in the z_buffer
var y = @floatToInt(i32, std.math.min(top, PlaneHeight - 1));