Doors
This commit is contained in:
parent
2e650bae26
commit
ef80c7d091
@ -31,9 +31,9 @@ TEXTURES = [
|
||||
TEXTURE_SIZE = 64
|
||||
|
||||
# Raycast cfg
|
||||
RAYCAST_WIN_WIDTH = 1000
|
||||
RAYCAST_WIN_HEIGHT = 1000
|
||||
RAYCAST_RESOLUTION_SCALING = 1
|
||||
RAYCAST_WIN_WIDTH = 600
|
||||
RAYCAST_WIN_HEIGHT = 600
|
||||
RAYCAST_RESOLUTION_SCALING = 4
|
||||
RAYCAST_RENDER_WIDTH = int(RAYCAST_WIN_WIDTH / RAYCAST_RESOLUTION_SCALING)
|
||||
RAYCAST_RENDER_HEIGHT = int(RAYCAST_WIN_HEIGHT / RAYCAST_RESOLUTION_SCALING)
|
||||
DOF = 2*MAP_SIZE # Depth Of Field
|
||||
@ -84,6 +84,9 @@ MAP = [
|
||||
class Main:
|
||||
|
||||
def __init__(self):
|
||||
# Print instructions
|
||||
print('RAYCASTER by penguin86\n\nMovement: up, down, left, right\nOpen door: space\n\nFPS:')
|
||||
|
||||
# Check valid map
|
||||
if len(MAP) != MAP_SIZE * MAP_SIZE:
|
||||
raise ValueError("Map size is {}, but should be a power of {}".format(len(MAP), MAP_SIZE))
|
||||
@ -153,6 +156,10 @@ class Main:
|
||||
if self.player_position["r"] < 0:
|
||||
self.player_position["r"] = 2*math.pi
|
||||
|
||||
# Open doors
|
||||
if keystate[sdl2.SDL_SCANCODE_SPACE]:
|
||||
self.openDoor()
|
||||
|
||||
self.draw()
|
||||
if not MAP_HIDDEN:
|
||||
self.mapWindow.refresh()
|
||||
@ -419,6 +426,37 @@ class Main:
|
||||
converted.append(pixels[i+2] + (pixels[i+1] << 8) + (pixels[i] << 16)) # BGR
|
||||
return converted
|
||||
|
||||
def openDoor(self):
|
||||
# Opens a door near the user
|
||||
# Works by modifying the map (removing the door)
|
||||
|
||||
# Find where is the user
|
||||
mapX = int(self.player_position["x"] / MAP_SCALE)
|
||||
mapY = int(self.player_position["y"] / MAP_SCALE)
|
||||
mapArrayPosition = mapY * MAP_SIZE + mapX
|
||||
|
||||
# Find in which direction the user is looking
|
||||
playerAngle = self.player_position["r"]
|
||||
lookingAtMapArrayPosition = 0
|
||||
if playerAngle > math.pi / 4 and playerAngle <= 3 * math.pi / 4:
|
||||
# Looking up
|
||||
lookingAtMapArrayPosition = mapArrayPosition - MAP_SIZE
|
||||
elif playerAngle > 3 * math.pi / 4 and playerAngle <= 5 * math.pi / 4:
|
||||
# Looking left
|
||||
lookingAtMapArrayPosition = mapArrayPosition - 1
|
||||
elif playerAngle > 5 * math.pi / 4 and playerAngle <= 7 * math.pi / 4:
|
||||
# Looking down
|
||||
lookingAtMapArrayPosition = mapArrayPosition + MAP_SIZE
|
||||
else:
|
||||
# Looking right
|
||||
lookingAtMapArrayPosition = mapArrayPosition + 1
|
||||
|
||||
if MAP[lookingAtMapArrayPosition] == MAP_DOOR_CELL_TYPE:
|
||||
# Player looking at a door: open it ("remove" it, leaving an empty space)
|
||||
MAP[lookingAtMapArrayPosition] = 0
|
||||
else:
|
||||
print("Player looking at cell #{} of type {}: nothing to do".format(lookingAtMapArrayPosition, MAP[lookingAtMapArrayPosition]))
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user