Curseyou is a Python Rogue style game that's intended to be small and simple. You can take this and turn it into your own game, but keep in mind it's built in stages based on the content of Learn Python the Hard Way 6th Edition.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

import utils
def add_neighbors(the_map, neighbors, closed, near_y, near_x):
points = utils.compass(near_x, near_y)
for x,y in points:
if the_map.inbounds(x,y) and closed[y, x] == utils.SPACE:
closed[y, x] = utils.WALL
neighbors.append([x,y])
def calculate_paths(the_map, paths, in_grid):
height, width = paths.shape
paths.fill(utils.PATH_LIMIT)
closed = the_map.map.copy()
starting_pixels = []
open_pixels = []
counter = 0
while counter < height * width:
x = counter % width
y = counter // width
if in_grid[y, x] == 0:
paths[y, x] = 0
closed[y, x] = utils.WALL
starting_pixels.append([x,y])
counter += 1
for x, y in starting_pixels:
add_neighbors(the_map, open_pixels, closed, y, x)
counter = 1
while counter < utils.PATH_LIMIT and open_pixels:
next_open = []
for x,y in open_pixels:
paths[y, x] = counter
add_neighbors(the_map, next_open, closed, y, x)
open_pixels = next_open
counter += 1
for x, y in open_pixels:
paths[y, x] = counter