Casting single ray to nearest wall
This commit is contained in:
parent
ada9598e25
commit
904d817203
14
raycaster.py
14
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))
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user