Lighting
This commit is contained in:
parent
cb89bd8fa4
commit
1736931554
26
raycaster.py
26
raycaster.py
@ -12,8 +12,8 @@ from time import time
|
|||||||
|
|
||||||
MAP_WIN_WIDTH = 640
|
MAP_WIN_WIDTH = 640
|
||||||
MAP_WIN_HEIGHT = 640
|
MAP_WIN_HEIGHT = 640
|
||||||
RAYCAST_WIN_WIDTH = MAP_WIN_WIDTH
|
RAYCAST_WIN_WIDTH = 900
|
||||||
RAYCAST_WIN_HEIGHT = MAP_WIN_HEIGHT
|
RAYCAST_WIN_HEIGHT = 600
|
||||||
DUNGEON_WIDTH = MAP_WIN_WIDTH
|
DUNGEON_WIDTH = MAP_WIN_WIDTH
|
||||||
DUNGEON_HEIGHT = MAP_WIN_HEIGHT
|
DUNGEON_HEIGHT = MAP_WIN_HEIGHT
|
||||||
PLAYER_SPEED = 10
|
PLAYER_SPEED = 10
|
||||||
@ -26,10 +26,10 @@ DEGREE_IN_RADIANTS = 0.01745329
|
|||||||
MAP = [
|
MAP = [
|
||||||
1, 1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
1, 0, 0, 0, 1, 0, 0, 1,
|
1, 0, 0, 0, 1, 0, 0, 1,
|
||||||
1, 0, 0, 0, 1, 1, 0, 1,
|
1, 0, 1, 0, 1, 0, 0, 1,
|
||||||
1, 0, 0, 0, 0, 0, 0, 1,
|
1, 0, 0, 0, 1, 0, 0, 1,
|
||||||
1, 0, 0, 0, 0, 0, 0, 1,
|
1, 0, 0, 0, 1, 0, 0, 1,
|
||||||
1, 0, 1, 0, 0, 0, 0, 1,
|
1, 0, 1, 1, 1, 0, 0, 1,
|
||||||
1, 0, 0, 0, 0, 0, 0, 1,
|
1, 0, 0, 0, 0, 0, 0, 1,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
]
|
]
|
||||||
@ -68,9 +68,9 @@ class Main:
|
|||||||
if event.type == sdl2.SDL_KEYDOWN:
|
if event.type == sdl2.SDL_KEYDOWN:
|
||||||
# Rotate player
|
# Rotate player
|
||||||
if event.key.keysym.sym == sdl2.SDLK_LEFT:
|
if event.key.keysym.sym == sdl2.SDLK_LEFT:
|
||||||
self.player_position["r"] = self.player_position["r"] - 5*DEGREE_IN_RADIANTS
|
self.player_position["r"] = self.player_position["r"] + 10*DEGREE_IN_RADIANTS
|
||||||
elif event.key.keysym.sym == sdl2.SDLK_RIGHT:
|
elif event.key.keysym.sym == sdl2.SDLK_RIGHT:
|
||||||
self.player_position["r"] = self.player_position["r"] + 5*DEGREE_IN_RADIANTS
|
self.player_position["r"] = self.player_position["r"] - 10*DEGREE_IN_RADIANTS
|
||||||
|
|
||||||
# Compute deltax and deltay based on player direction
|
# Compute deltax and deltay based on player direction
|
||||||
player_delta_x = math.cos(self.player_position["r"]) * PLAYER_SPEED
|
player_delta_x = math.cos(self.player_position["r"]) * PLAYER_SPEED
|
||||||
@ -235,9 +235,15 @@ class Main:
|
|||||||
lineHeight = RAYCAST_WIN_HEIGHT
|
lineHeight = RAYCAST_WIN_HEIGHT
|
||||||
# Center line vertically in window
|
# Center line vertically in window
|
||||||
lineOffset = RAYCAST_WIN_HEIGHT / 2 - lineHeight / 2
|
lineOffset = RAYCAST_WIN_HEIGHT / 2 - lineHeight / 2
|
||||||
|
|
||||||
|
# Simulate lighting based on wall incidence
|
||||||
|
color = sdl2.ext.Color(255,255,255,255)
|
||||||
|
if vertDist > horizDist:
|
||||||
|
color = sdl2.ext.Color(200,200,200,255)
|
||||||
|
|
||||||
# Draw line
|
# Draw line
|
||||||
for x in range(i*10, i*10+10):
|
for x in range(i*15, i*15+15):
|
||||||
sdl2.ext.draw.line(self.raycastSurface, sdl2.ext.Color(255,255,255,255), (x, int(lineOffset), x, 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))
|
||||||
|
Loading…
Reference in New Issue
Block a user