コード例 #1
0
def handle_key(key):
    """Handles key events in the game"""
    direction = DIRECTIONS.get(key)
    if direction:
        move(maze, direction)
    img = draw_grid(maze, tile_img, tiles)
    display.blit(img, Rect((0, 0, 384, 224)), Rect((0, 0, 384, 224)))
    pygame.display.update()
コード例 #2
0
ファイル: test_graphics.py プロジェクト: krother/maze_run
def draw(surface):
    # prepare the maze and draw the graphics
    img = draw_grid(maze, tile_img, tiles)
    surface.blit(img, Rect((0, 0, 384, 224)), Rect((0, 0, 384, 224)))
    pygame.display.update()
コード例 #3
0
ファイル: moves.py プロジェクト: krikavap/python-mazeRun

def move(level, direction):
    """Handle move on the level."""
    oldx, oldy = get_player_pos(level)
    newx = oldx + direction[0]
    newy = oldy + direction[1]
    if level[newy][newx] == 'x':
        sys.exit(0)
    if level[newy][newx] == 'o':
        cratex = newx + direction[0]
        cratey = newy + direction[1]
        if level[cratey][cratex] in '. ':
            level[cratey][cratex] = 'o'
            level[newy][newx] = ' '
    if level[newy][newx] in '. ':
        level[oldy][oldx] = ' '
        level[newy][newx] = '*'


if __name__ == '__main__':
    tile_img, tiles = load_tiles()
    maze = create_maze(12, 7)
    maze = parse_grid(maze)
    maze[1][1] = '*'
    for i in range(100):
        direction = random.choice([LEFT, RIGHT, UP, DOWN])
        move(maze, direction)
    img = draw_grid(maze, tile_img, tiles)
    image.save(img, 'moved.png')
コード例 #4
0
def draw(surface):
    # prepare the maze and draw the graphics
    img = draw_grid(maze, tile_img, tiles)
    surface.blit(img, Rect((0, 0, 384, 224)), Rect((0, 0, 384, 224)))
    pygame.display.update()
コード例 #5
0
ファイル: moves.py プロジェクト: krother/maze_run

def move(level, direction):
    """Handles moves on the level"""
    oldx, oldy = get_player_pos(level)
    newx = oldx + direction[0]
    newy = oldy + direction[1]
    if level[newy][newx] == 'x':
        sys.exit(0)
    if level[newy][newx] == 'o':
        cratex = newx + direction[0]
        cratey = newy + direction[1]
        if level[cratey][cratex] in '. ':
            level[cratey][cratex] = 'o'
            level[newy][newx] = ' '
    if level[newy][newx] in '. ':
        level[oldy][oldx] = ' '
        level[newy][newx] = '*'


if __name__ == '__main__':
    tile_img, tiles = load_tiles()
    maze = create_maze(12, 7)
    maze = parse_grid(maze)
    maze[1][1] = '*'
    for i in range(100):
        direction = random.choice([LEFT, RIGHT, UP, DOWN])
        move(maze, direction)
    img = draw_grid(maze, tile_img, tiles)
    image.save(img, 'moved.png')