Fixed raycast window rendering

This commit is contained in:
Daniele Verducci (Slimpenguin) 2023-01-05 01:29:29 +01:00
parent c75f8555ab
commit 3c810497bf

View File

@ -134,9 +134,9 @@ class Main:
# Casts rays for raycasting
playerAngle = self.player_position["r"]
# Cast 100 rays from -0,5 rads to +0,5 rads (about 60° viewing angle)
for i in range(100):
rayAngle = playerAngle + (i/100) - 0.5
# Cast one ray for every window pixel, from -0,5 rads to +0,5 rads (about 60° viewing angle)
for i in range(RAYCAST_WIN_WIDTH):
rayAngle = playerAngle + (i/RAYCAST_WIN_WIDTH) - 0.5
if rayAngle < 0:
rayAngle = math.pi * 2 + rayAngle
if rayAngle > math.pi * 2:
@ -245,8 +245,7 @@ class Main:
color = sdl2.ext.Color(200,200,200,255)
# Draw line
for x in range(i*15, i*15+15):
sdl2.ext.draw.line(self.raycastSurface, color, (x, int(lineOffset), x, int(lineOffset + lineHeight)))
sdl2.ext.draw.line(self.raycastSurface, color, (i, int(lineOffset), i, int(lineOffset + lineHeight)))
def dist(self, ax, ay, bx, by):
return math.sqrt((bx-ax)*(bx-ax) + (by-ay)*(by-ay))