Casting single ray to nearest wall

This commit is contained in:
Daniele Verducci 2023-01-02 19:19:47 +01:00
parent ada9598e25
commit 904d817203

View File

@ -123,7 +123,6 @@ class Main:
# Casts rays for raycasting # Casts rays for raycasting
rayAngle = self.player_position["r"] rayAngle = self.player_position["r"]
for r in range(1): for r in range(1):
# Check horizontal lines # Check horizontal lines
dof = 0 # Depth of field dof = 0 # Depth of field
if rayAngle == 0 or rayAngle == math.pi: if rayAngle == 0 or rayAngle == math.pi:
@ -159,8 +158,9 @@ class Main:
rayY = rayY + yOffset rayY = rayY + yOffset
dof = dof + 1 dof = dof + 1
# Draw ray # Save horyzontal probe rays for later comparison with vertical
sdl2.ext.draw.line(self.mapSurface, sdl2.ext.Color(0,255,0,255), (self.player_position["x"], self.player_position["y"], rayX, rayY)) horizRayX = rayX
horizRayY = rayY
# Check vertical lines # Check vertical lines
dof = 0 # Depth of field dof = 0 # Depth of field
@ -199,10 +199,14 @@ class Main:
rayY = rayY + yOffset rayY = rayY + yOffset
dof = dof + 1 dof = dof + 1
# Draw ray if self.dist(self.player_position["x"], self.player_position["y"], rayX, rayY) > self.dist(self.player_position["x"], self.player_position["y"], horizRayX, horizRayY):
#sdl2.ext.draw.line(self.mapSurface, sdl2.ext.Color(0,0,255,255), (self.player_position["x"], self.player_position["y"], rayX, rayY)) rayX = horizRayX
rayY = horizRayY
sdl2.ext.draw.line(self.mapSurface, sdl2.ext.Color(0,0,255,255), (self.player_position["x"], self.player_position["y"], rayX, rayY))
def dist(self, ax, ay, bx, by):
return math.sqrt((bx-ax)*(bx-ax) + (by-ay)*(by-ay))