Ejemplo n.º 1
0
def create_house(game_map, room):
    # Draw corners
    game_map.tiles[room.x1][room.y1] = Tile(True,
                                            "Wall",
                                            libtcod.dark_sepia,
                                            libtcod.Color(0, 0, 100),
                                            char=201)
    game_map.tiles[room.x2][room.y1] = Tile(True,
                                            "Wall",
                                            libtcod.dark_sepia,
                                            libtcod.Color(0, 0, 100),
                                            char=187)
    game_map.tiles[room.x1][room.y2] = Tile(True,
                                            "Wall",
                                            libtcod.dark_sepia,
                                            libtcod.Color(0, 0, 100),
                                            char=200)
    game_map.tiles[room.x2][room.y2] = Tile(True,
                                            "Wall",
                                            libtcod.dark_sepia,
                                            libtcod.Color(0, 0, 100),
                                            char=188)

    # Draw horizontal walls
    for x in range(room.x1 + 1, room.x2):
        game_map.tiles[x][room.y1] = Tile(True,
                                          "Wall",
                                          libtcod.dark_sepia,
                                          libtcod.Color(0, 0, 100),
                                          char=205)
        game_map.tiles[x][room.y2] = Tile(True,
                                          "Wall",
                                          libtcod.dark_sepia,
                                          libtcod.Color(0, 0, 100),
                                          char=205)

    # Draw vertical walls
    for y in range(room.y1 + 1, room.y2):
        game_map.tiles[room.x1][y] = Tile(True,
                                          "Wall",
                                          libtcod.dark_sepia,
                                          libtcod.Color(0, 0, 100),
                                          char=186)
        game_map.tiles[room.x2][y] = Tile(True,
                                          "Wall",
                                          libtcod.dark_sepia,
                                          libtcod.Color(0, 0, 100),
                                          char=186)

    for x in range(room.x1 + 1, room.x2):
        for y in range(room.y1 + 1, room.y2):
            game_map.tiles[x][y] = Tile(False,
                                        "Floor",
                                        libtcod.Color(130, 110, 50),
                                        libtcod.Color(0, 0, 100),
                                        char='.')
Ejemplo n.º 2
0
    def __init__(self, width, height, order: str = 'F'):
        super().__init__(width, height, order)
        self.living_console: Console = None
        self.decor_console: Console = None
        self.terrain_console: Console = None
        self.tiles = []
        self.tiles_at = np.empty((self.width, self.height),
                                 dtype=object,
                                 order='F')

        for x, columns in enumerate(self.chars):
            for y, char in enumerate(columns):
                tile = Tile(x, y, char)
                self.tiles_at[x][y] = tile
                self.tiles.append(tile)

        self.walkable[:] = (self.chars[:] == ord(' '))

        for c in ('+', chr(197), '0', 't', '>', '=', '"', chr(25), chr(24),
                  chr(250)):
            self.walkable[:] = self.walkable[:] | (self.chars == ord(c))

        self.transparent[:] = self.walkable[:]
        for c in ('Ú', 'Ä', 'Â', '¿', '³', 'Ã', 'Å', '´', 'À', 'Á', 'Ù', '~',
                  chr(176), chr(3), chr(247)):
            self.transparent[:] = self.transparent[:] | (self.chars == ord(c))

        self.transparent[:] = self.transparent[:] & (self.chars != ord('+'))
        self.transparent[:] = self.transparent[:] & (self.chars != 197)
        self.generated = True
Ejemplo n.º 3
0
    def initialize_tiles(self):
        tiles = [[Tile(True) for y in range(self._height)] for x in range(self._width)]

        # Call random generation algorithm here
        self.make_map(tiles)

        return tiles
Ejemplo n.º 4
0
 def create_v_tunnel(self, y1, y2, x):
     for y in range(min(y1, y2), max(y1, y2) + 1):
         self.tiles[x][y] = Tile(False,
                                 "Floor",
                                 libtcod.Color(200, 180, 50),
                                 libtcod.Color(50, 50, 150),
                                 char='.')
Ejemplo n.º 5
0
 def create_h_tunnel(self, x1, x2, y):
     for x in range(min(x1, x2), max(x1, x2) + 1):
         self.tiles[x][y] = Tile(False,
                                 "Floor",
                                 libtcod.Color(200, 180, 50),
                                 libtcod.Color(50, 50, 150),
                                 char='.')
Ejemplo n.º 6
0
    def initialize_tiles(self):

        # Everything is blocked
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
Ejemplo n.º 7
0
def add_tile_type(terrain,
                  name,
                  blocked,
                  block_sight=None,
                  destructible=False):
    # on créé la tuile dans terrain
    tile = Tile(name, blocked, block_sight, destructible, explored=False)
    terrain[name] = tile
    # on créé sa variante "explored"
    new_name = name + '_explored'
    tile_explored = Tile(new_name,
                         blocked,
                         block_sight,
                         destructible,
                         explored=True)
    terrain[new_name] = tile_explored
Ejemplo n.º 8
0
    def initialize_tiles(self):

        # initialize a 2D aray of tiles, set to blocking by default
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
Ejemplo n.º 9
0
    def initialize_tiles(self):
        '''
        地图的房间从全部为墙开始删减
        '''
        tiles = [[Tile(True) for y in range(self.height)] for x in range(self.width)]

        return tiles
Ejemplo n.º 10
0
 def set_tile(self, x, y, char):
     tmp_tile = Tile(x, y, char)
     tile = self.tiles_at[x][y]
     tile.char = tmp_tile.char
     tile.bg = tmp_tile.bg
     tile.fg = tmp_tile.fg
     self.walkable[x][y] = True
     self.transparent[x][y] = True
Ejemplo n.º 11
0
    def initialize_tiles(self):
        """
        initialze map tiles
        """
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
Ejemplo n.º 12
0
    def initialize_tiles(self):
        '''
        Initialize a 2D array of tiles
        '''
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
Ejemplo n.º 13
0
    def place_glyphs(self):

        gate_coordinates = choice(self.gate_place)

        for glyph in range(GLYPHS_NUM):

            # find random place on map
            # place the right glyph.

            rand_map_place_x = randint(1, WORLD_WIDTH - 1)
            rand_map_place_y = randint(1, WORLD_HEIGHT - 1)
            rand_chunk_place_x = randint(0, MAP_WIDTH - 1)
            rand_chunk_place_y = randint(0, MAP_HEIGHT - 1)

            print(f"GLYPH_POS: {rand_map_place_x}, {rand_map_place_y}")
            print(
                f"GLYPH POS ON CHUNK: {rand_chunk_place_x}, {rand_chunk_place_y}"
            )

            difference_x, difference_y = (gate_coordinates[0] -
                                          rand_map_place_x,
                                          gate_coordinates[1] -
                                          rand_map_place_y)

            if difference_x < -2 and difference_y < 0:  # glyph is further on x and y axis than gate. It will point to the LEFT.
                self.chunks[rand_map_place_x][rand_map_place_y].tiles[
                    rand_chunk_place_x][rand_chunk_place_y] = Tile(
                        False, type_of=arrow_left)

            elif difference_x >= -1 and difference_y < 0:
                self.chunks[rand_map_place_x][rand_map_place_y].tiles[
                    rand_chunk_place_x][rand_chunk_place_y] = Tile(
                        False, type_of=arrow_up)

            elif difference_x > -2 and difference_y > 0:
                self.chunks[rand_map_place_x][rand_map_place_y].tiles[
                    rand_chunk_place_x][rand_chunk_place_y] = Tile(
                        False, type_of=arrow_right)

            elif difference_x >= -1 and difference_y > 0:  # GATE_CORD_Y - GLYPH_Y > 0 means that gate has greater y - is further down.
                self.chunks[rand_map_place_x][rand_map_place_y].tiles[
                    rand_chunk_place_x][rand_chunk_place_y] = Tile(
                        False, type_of=arrow_down)

            self.chunks[rand_map_place_x][
                rand_map_place_y].property = ChunkProperty.HAS_DIRECTION
    def initialize_tiles(self):
        tiles = [[Tile(False) for y in range(self.height)]
                 for x in range(self.width)]

        for i in (30, 31, 32):
            tiles[i][22].blocked = True
            tiles[i][22].block_sight = True

        return tiles
Ejemplo n.º 15
0
    def initialize_tiles(self):
        """ Creates 2D array of tiles

        """

        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
Ejemplo n.º 16
0
    def initialize_tiles(self):
        """
        Création de Tiles qui bloquent le passage et la vue sur toute la surface de la carte.
        Ces Tiles sont stockés dans une liste qu'on retourne.
        """
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
def test_default_values():
    t1 = Tile(True)
    expected_blocked = True
    expected_block_sight = True
    expected_explored = False

    assert t1.blocked == expected_blocked
    assert t1.block_sight == expected_block_sight
    assert t1.explored == expected_explored
def test_custom_values():
    t1 = Tile(True, False)
    expected_blocked = True
    expected_block_sight = False
    expected_explored = False

    assert t1.blocked == expected_blocked
    assert t1.block_sight == expected_block_sight
    assert t1.explored == expected_explored
Ejemplo n.º 19
0
    def initialise_tiles(self):
        """
        Creates a pseudo 2D array using list comprehensions. Fills this array with tiles.
        :return: A nested 2D list of tiles.
        """
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
Ejemplo n.º 20
0
 def create_room(self, room):
     # Go through the tiles in the rectangle and make them passable
     for x in range(room.x1 + 1, room.x2):
         for y in range(room.y1 + 1, room.y2):
             self.tiles[x][y] = Tile(False,
                                     "Floor",
                                     libtcod.Color(0, 128, 0),
                                     libtcod.Color(32, 32, 125),
                                     char='.')
Ejemplo n.º 21
0
    def initialize_tiles(self):
        tiles = [[Tile(False) for y in range(self.height)] for x in range(self.width)]

        tiles[30][22].blocked = True
        tiles[30][22].block_sight = True
        tiles[31][22].blocked = True
        tiles[31][22].block_sight = True
        tiles[32][22].blocked = True
        tiles[32][22].block_sight = True
Ejemplo n.º 22
0
    def randomize_sand(self, chunk_x, chunk_y, world):

        chunk_obj = world.chunks[chunk_x][chunk_y]

        for y in range(0, self.height):
            for x in range(0, self.width):
                if chunk_obj.tiles[x][y].type_of == sand:
                    chunk_obj.tiles[x][y] = Tile(False, type_of=sand)

        self.current_chunk = chunk_obj
Ejemplo n.º 23
0
    def get_map_import(self, map_width, map_height, entities):

        x = 0
        y = 0

        with open("maps.txt", "rt") as f:
            for line in f:
                tiles = []
                
                for character in line:
                    if character == '^':
                        tiles.append(Tile(blocked=(character == "^")))
                        self.tiles[x][y].blocked = True
                        self.tiles[x][y].block_sight = True
                        x +=1

                    elif character == '.':
                        tiles.append(Tile(blocked=(character == ".")))
                        self.tiles[x][y].blocked = False
                        self.tiles[x][y].block_sight = False
                        x += 1

                    elif character == 'T':
                        tiles.append(Tile(blocked=(character == "T")))
                        self.tiles[x][y].blocked = False
                        self.tiles[x][y].block_sight = False
                        self.tiles[x][y].building = True
                        x += 1

                    elif character == 'E':
                        tiles.append(Tile(blocked=(character == "T")))
                        self.tiles[x][y].blocked = False
                        self.tiles[x][y].block_sight = False
                        self.tiles[x][y].earth = True
                        x += 1

                    else:
                        y += 1

                # map.append(tiles)
                # self.tiles.append(map)
                x = 0
Ejemplo n.º 24
0
    def initialize_tiles(self) -> list:
        """Initialize the tile map
        
        Returns:
            list -- tile grid
        """
        # Initialize the WxH tile grid with non-blocking tiles
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
Ejemplo n.º 25
0
    def initialize_tiles(self, walls=True):
        # Make a big ol' pile of floor tiles
        tiles = [[
            Tile(walls,
                 "Wall" if walls else "Floor",
                 libtcod.Color(130, 110, 50),
                 libtcod.Color(0, 0, 100),
                 char='#' if walls else '.') for y in range(self.height)
        ] for x in range(self.width)]

        return tiles
Ejemplo n.º 26
0
 def fill_rect(self, rect, tile_name):
     self.graphics[rect.y1:rect.y2 + 1, rect.x1:rect.x2 + 1] = Tile(
         self.tile_gfx[tile_name]['char'],
         tuple(self.palette[self.tile_gfx[tile_name]['colour_lit']]),
         tuple(self.palette[self.tile_gfx[tile_name]['colour_dim']]))
     self.path_map.walkable[rect.y1:rect.y2 + 1, rect.x1:rect.x2 +
                            1] = self.tile_data[tile_name]['walkable']
     self.path_map.transparent[rect.y1:rect.y2 + 1, rect.x1:rect.x2 +
                               1] = self.tile_data[tile_name]['transparent']
     self.destructible[rect.y1:rect.y2 + 1, rect.x1:rect.x2 +
                       1] = self.tile_data[tile_name]['destructible']
Ejemplo n.º 27
0
def initialize_tiles(game_map,
                     tile=Tile(True,
                               "Wall",
                               libtcod.Color(130, 110, 50),
                               libtcod.Color(0, 0, 100),
                               char='#')):
    # Make a big ol' pile of floor tiles
    tiles = [[deepcopy(tile) for y in range(game_map.height)]
             for x in range(game_map.width)]

    return tiles
Ejemplo n.º 28
0
    def initialize_tiles(self):
        tiles = [[Tile(False) for y in range(self.height)]
                 for x in range(self.width)]

        # Demonstraition of blocked tiles
        tiles[30][22].blocked = True
        tiles[30][22].block_sight = True
        tiles[31][22].blocked = True
        tiles[31][22].block_sight = True
        tiles[32][22].blocked = True
        tiles[32][22].block_sight = True

        return tiles
Ejemplo n.º 29
0
    def __init__(self):
        self.world_map = [[
            Tile(False, type_of=sand)
            for y in range(0, WORLD_HEIGHT * MAP_HEIGHT)
        ] for x in range(0, WORLD_WIDTH * MAP_WIDTH)]
        self.chunks = self.initialize_chunks()
        self.gate_place = []
        self.create_village()
        self.place_glyphs()

        for x in range(0, WORLD_WIDTH):
            for y in range(0, WORLD_HEIGHT):
                if self.chunks[x][y].property == ChunkProperty.END:
                    print(f"END CHUNK: {x}, {y}")
Ejemplo n.º 30
0
    def initialize_tiles(self):
        # Tiles are set to non-blocking by default
        tiles = [[Tile(False) for y in range(self.height)]
                 for x in range(self.width)]

        # Set some tiles to blocking
        tiles[30][22].blocked = True
        tiles[30][22].block_sight = True
        tiles[31][22].blocked = True
        tiles[31][22].block_sight = True
        tiles[32][22].blocked = True
        tiles[32][22].block_sight = True

        return tiles