diff --git a/raycaster.py b/raycaster.py index c083413..88bee89 100755 --- a/raycaster.py +++ b/raycaster.py @@ -123,7 +123,6 @@ class Main: # Casts rays for raycasting rayAngle = self.player_position["r"] for r in range(1): - # Check horizontal lines dof = 0 # Depth of field if rayAngle == 0 or rayAngle == math.pi: @@ -159,8 +158,9 @@ class Main: rayY = rayY + yOffset dof = dof + 1 - # Draw ray - sdl2.ext.draw.line(self.mapSurface, sdl2.ext.Color(0,255,0,255), (self.player_position["x"], self.player_position["y"], rayX, rayY)) + # Save horyzontal probe rays for later comparison with vertical + horizRayX = rayX + horizRayY = rayY # Check vertical lines dof = 0 # Depth of field @@ -199,10 +199,14 @@ class Main: rayY = rayY + yOffset dof = dof + 1 - # Draw ray - #sdl2.ext.draw.line(self.mapSurface, sdl2.ext.Color(0,0,255,255), (self.player_position["x"], self.player_position["y"], rayX, rayY)) + 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): + 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))