Пример #1
0
    def render(self, terminal):
        m = matrix(room)
        w, h = dimensions(m)
        x = terminal.width // 2  - w // 2
        y = terminal.height // 2 - h // 2
        for j, s in enumerate(string(m).split('\n')):
            terminal.add_string(x, y+j, s)

        for e, p in self.engine.positions:
            terminal.add_char(x + p.x, y + p.y, str(e))
Пример #2
0
    def build_map(self, map_type, map_string) -> (object, object):
        """
            Width x Height is determined by map_string dimensions if it exists.
            Otherwise, a random map is generated and used instead.

            Currently, predetermined levels are town maps only.
            Empty map strings leads to the construction of cave maps.
        """
        # if given a specific map string use it instead of a random map
        if map_string:
            dungeon = [ [ c for c in row ] for row in map_string.split('\n') ]
            width, height = dimensions(dungeon)
            tilemap = TileMap(width, height, map_type)
            # add environmental details (grass, flowers) if town
            if map_type == "town":
                matrix = array_to_matrix(
                    generate_poisson_array(width, height),
                    width, height,
                    filter=lambda x: x < 3 or x >= 8,
                    chars=("'", ".")
                )
                for y in range(len(dungeon)):
                    for x in range(len(dungeon[0])):
                        if dungeon[y][x] == '.':
                            dungeon[y][x] = matrix[y][x]
        else:
            w, h = 58, 17
            tilemap = TileMap(w, h, map_type)
            random_array = generate_poisson_array(w, h)
            no_stairs = array_to_matrix(
                random_array,
                w, h,
                filter=lambda x: x < 3 or x >= 8
            )
            no_stairs = add_boundry_to_matrix(no_stairs, bounds=1)
            for i in range(4):
                no_stairs = cell_auto(no_stairs, deadlimit=5+(i-5))
            no_stairs = flood_fill(no_stairs)
            dungeon = replace_cell_with_stairs(no_stairs)
            print(string(dungeon))
        return tilemap, dungeon
Пример #3
0
# maps.py
"""Holds premade levels used for testing"""

import enum

from source.generate import (burrow_passage, cell_auto, empty_room, rotate,
                             string)


class MapType:
    TOWN = 'town'
    CAVE = 'cave'


# generated levels
ASTAR = string(empty_room(190, 44))
CHOKE = string(cell_auto(rotate(burrow_passage(24, 50))))
EMPTY = string(empty_room(58, 17))
HALL = string(empty_room(200, 80))
STRESS = string(empty_room(500, 100))

m, n = 100, 80
LARGE = '\n'.join([
    ''.join('#' for x in range(m)) if j == 0 or j == n - 1 else '#' +
    ''.join('.' for x in range(m - 2)) + '#' for j in range(n)
])

# handmade levels
DUNGEON = (MapType.CAVE, """
###########################################################
#....#....#....#....#..........##....#....#....#....#.....#
Пример #4
0
# demos\cave.py
"""Demo for the build_cave function in generate.py"""

import shutil

from source.generate import build_cave, string

if __name__ == "__main__":
    w, h = shutil.get_terminal_size()
    print(string(build_cave(w - 1, h - 2)))
Пример #5
0
# demos\blob.py
"""Demo for the build_blob function in generate.py"""

import shutil

from source.generate import build_blob, string

if __name__ == "__main__":
    h, w = shutil.get_terminal_size()
    print(w, h)
    x = build_blob(w - 1, w - 2)
    print(x)
    print(string(x))
Пример #6
0
            17 + off_y, 
            raycaster=raycaster
        )
        s = time.time()

        # save the timing result
        recorder.append(s - t)

    # edit the map buffer with seen positions and player position
    for p, v in join_drop_key(engine.positions, engine.visibilities):
        m[p.y][p.x] = ' ' if v.level == 0 else n[p.y][p.x]
    p = engine.positions.find(engine.player)
    m[p.y][p.x] = '@'

    # render
    print(string(m))

    try:
        c = input().strip()
    except KeyboardInterrupt:
        break

    p = engine.positions.find(engine.player)
    if c == 'w' and n[p.y-1][p.x] == '.':
        m[p.y][p.x] = '.'
        p.y += -1
    if c == 'a' and n[p.y][p.x-1] == '.':
        m[p.y][p.x] = '.'
        p.x += -1
    if c == 's' and n[p.y+1][p.x] == '.':
        m[p.y][p.x] = '.'