Example #1
0
    def __generate_map(self):
        _tower = TowerFactory(self.lvl_length, self.lvl_width, False, False)
        self.map = _tower.gen_map()
        self.upStairs = _tower.upStairs
        self.downStairs = _tower.downStairs

        self.__bust_up_level()
Example #2
0
    def __generate_map(self):
        _map = []
        
        _if = ItemFactory()
        _tf = TerrainFactory()
        
        # make all border squares walls
        # This could be moved to a superclass
        row = []
        for j in range(0, self.lvl_width):
            row.append(_tf.get_terrain_tile(PERM_WALL))
        _map.append(row)

        for r in range(1, self.lvl_length-1):
            row = []
            row.append(_tf.get_terrain_tile(PERM_WALL))

            for c in range(1, self.lvl_width-1):
                rnd = random()
                
                if rnd < 0.50:
                    row.append(_tf.get_terrain_tile(ROAD))
                elif rnd < 0.90:
                    row.append(_tf.get_terrain_tile(GRASS))
                else:
                    row.append(_tf.get_terrain_tile(TREE))
            row.append(_tf.get_terrain_tile(PERM_WALL))
            _map.append(row)
        row = []
        for j in range(0, self.lvl_width):
            row.append(_tf.get_terrain_tile(PERM_WALL))
        _map.append(row)
        
        # generate the tower section
        _tower = TowerFactory(length = 20, width = 30, top = True, bottom = False)
        _tower.gen_map()
        self.upStairs = None
        self.downStairs = _tower.downStairs
        
        for r in range(0, 20):
            for c in range(0, 30):
                _row = 10 + r
                _col = self.lvl_width- 31 + c
                _map[_row][_col] = _tower.get_cell(r,c)
                if _map[_row][_col].get_type() == DOOR and random() > 0.6:
                    _map[_row][_col].broken = True
                    _map[_row][_col].open()
                
        # beat up the tower a bit
        for x in range(randrange(100, 200)):
            r = 10 + randrange(0,20)
            c = self.lvl_width - 31 + randrange(0, 30)
            if _map[r][c].get_type() != DOWN_STAIRS:
                if random() < 0.75:
                    _map[r][c] = _tf.get_terrain_tile(ROAD)
                else:
                    _map[r][c] = _tf.get_terrain_tile(GRASS)

        # Add double door main entrance
        for r in range(15,25):
            if _map[r][self.lvl_width-30].get_type() == FLOOR and _map[r+1][self.lvl_width-30].get_type() == FLOOR:
                break
        _map[r][self.lvl_width-31] = _tf.get_terrain_tile(DOOR)
        _map[r+1][self.lvl_width-31] = _tf.get_terrain_tile(DOOR)

        for c in range(0, 30):
            _map[29][self.lvl_width-31+c] = _tf.get_terrain_tile(WALL)

        _box = Items.Box()
        _box_placed = False
        while not _box_placed:
            _col = randrange(self.lvl_width-30, self.lvl_width)
            _row = randrange(self.lvl_length-20, self.lvl_length)
            if _map[_row][_col].get_type() not in (DOOR, WALL, PERM_WALL, DOWN_STAIRS):
                self.add_item_to_sqr(_row, _col, _box)
                _box_placed = True

        for x in range(randrange(7)):
            _box.add_item(_if.gen_item('ritalin', 1))
        for x in range(randrange(19)):
            _box.add_item(_if.gen_item('shotgun shell', 1))
        for x in range(randrange(4)):
            _box.add_item(_if.gen_item('flare', 1))
        if randrange(4) > 2:
            _box.add_item(_if.gen_item('medkit', 1))
            
        return _map