diff --git a/raycaster.c b/raycaster.c index 0d1782b..3635663 100644 --- a/raycaster.c +++ b/raycaster.c @@ -593,6 +593,8 @@ void drawRays3D() // * Cast n rays for (r = 0; r < 60; r++) { + int verticalMapTexture = 0; + int horizontalMapTexture = 0; // * --- Check Horizontal Lines --- dof = 0; @@ -676,6 +678,8 @@ void drawRays3D() hy = rayY; distanceHor = distance(playerX, playerY, hx, hy, rayAngle); + verticalMapTexture = map[mapPoint] - 1; + dof = 8; // Break the loop - no need to calculate more. } else @@ -744,6 +748,8 @@ void drawRays3D() vy = rayY; distanceVert = distance(playerX, playerY, vx, vy, rayAngle); + verticalMapTexture = map[mapPoint] - 1; + dof = 8; // Break the loop - no need to calculate more. } else @@ -762,6 +768,7 @@ void drawRays3D() // Vertical wall hit if (distanceVert < distanceHor) { + horizontalMapTexture = verticalMapTexture; rayX = vx; rayY = vy; disT = distanceVert; @@ -777,6 +784,7 @@ void drawRays3D() // Horizontal wall hit if (distanceHor < distanceVert) { + horizontalMapTexture = mh - 1; rayX = hx; rayY = hy; disT = distanceHor; @@ -853,25 +861,25 @@ void drawRays3D() if (shade == 1) // North-south walls (PI -> (2 * PI)) { - textureX = (int)(rayX / 2.0) % mapSize; + textureX = (int)(rayX / 2.0) % 32; if (rayAngle < PI) // South walls { - textureX = mapSize - 1 - textureX; + textureX = 31 - textureX; } } else // East-west walls (PI2 -> PI3) { - textureX = (int)(rayY / 2.0) % mapSize; - if (rayAngle > PI2 && rayAngle < PI3) // West + textureX = (int)(rayY / 2.0) % 32; + if (rayAngle > PI2 || rayAngle < PI3) // West { - textureX = mapSize - 1 - textureX; + textureX = 31 - textureX; } } for (x = xStart; x < xEnd; x++) { - float textureY = textureYoffset * textureYstep; + float textureY = textureYoffset * textureYstep + (horizontalMapTexture * 32); for (y = 0; y < lineHeight; y++) { float c = All_Textures[((int)textureY * mapSize) + textureX] * shade;