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