Exemple #1
0
    def __init__(self):

        self.map = Map.Map(10, 10)
        self.monsters = Units.Squad(10)
        self.tileset = None

        self.random = libtcod.random_get_instance()
Exemple #2
0
    def __init__(self, mode):

        self._hmGenerator = Generators.getGenerator(mode)

        self._tempGenerator = Generators.tempGenerator
        self._salinityGenerator = Generators.salinityGenerator
        self._rainGenerator = Generators.rainGenerator
        self._rand = tcod.random_get_instance()
 def __init__(self, mode):
     
     self._hmGenerator = Generators.getGenerator(mode)
     
     self._tempGenerator = Generators.tempGenerator
     self._salinityGenerator = Generators.salinityGenerator
     self._rainGenerator = Generators.rainGenerator
     self._rand = tcod.random_get_instance()
Exemple #4
0
def generateTempmap(_map):
    print("Temperature Generation...")
    
    _rand = tcod.random_get_instance()
    _tm = tcod.heightmap_new(_map.width, _map.height)
    
    _altMap = tcod.heightmap_new(_map.width, _map.height)
    _latMap = tcod.heightmap_new(_map.width, _map.height)
    
    for y in range(0, _map.height):
        for x in range(0, _map.width):
            
            latitude = -int(180*y/_map.height - 90)
            latTemp = int(-(latitude*latitude)/51 + 128)
            
            tcod.heightmap_set_value(_latMap, x, y, latTemp)
            
            alt = _map.heightmap(x, y)
            
            if (alt > 0):
                # expect alt to peak out around 255-320
                altTemp = -alt/4
            else:
                altTemp = tcod.random_get_int(_rand,-10, 10)
                
            tcod.heightmap_set_value(_altMap, x, y, altTemp)
    
    tcod.heightmap_add_hm(_altMap, _latMap, _tm)
    
    
    tcod.heightmap_rain_erosion(
            _tm, 
            _map.width*_map.height/2,     #number of raindrops
            0.2,                        #erosion cooef (f)
            0.2)                        #sediment cooef (f)
    
    tcod.heightmap_normalize(_tm, -32, 128)
    
    dx = [-1,1,0]
    dy = [0,0,0]
    weight = [0.33,0.33,0.33]
    tcod.heightmap_kernel_transform(_tm,3,dx,dy,weight,-32,128);
    
    for y in range(0, _map.height):
        for x in range(0, _map.width):
            _map.coords[x][y].setTemp(tcod.heightmap_get_value(_tm, x, y))
    return True
Exemple #5
0
def test_random():
    rand = libtcodpy.random_get_instance()
    rand = libtcodpy.random_new()
    libtcodpy.random_delete(rand)
    rand = libtcodpy.random_new_from_seed(42)
    libtcodpy.random_set_distribution(rand, libtcodpy.DISTRIBUTION_LINEAR)
    libtcodpy.random_get_int(rand, 0, 1)
    libtcodpy.random_get_int_mean(rand, 0, 1, 0)
    libtcodpy.random_get_float(rand, 0, 1)
    libtcodpy.random_get_double(rand, 0, 1)
    libtcodpy.random_get_float_mean(rand, 0, 1, 0)
    libtcodpy.random_get_double_mean(rand, 0, 1, 0)

    backup = libtcodpy.random_save(rand)
    libtcodpy.random_restore(rand, backup)

    libtcodpy.random_delete(rand)
    libtcodpy.random_delete(backup)
Exemple #6
0
                ret = ret + str(self.population[xx][yy])
            ret = ret + '|\n'
        return (ret)


#create world
nwidth = 100
nheight = 60
alivechar = '+'
deadchar = ' '
char_option = 'ascii'
speed = .1
inc = 0.01

# default generator
default = libtcod.random_get_instance()
# another random generator
my_random = libtcod.random_new()
# a random generator with a specific seed
my_determinist_random = libtcod.random_new_from_seed(0xdeadbeef)

world = World(nwidth, nheight, alivechar, deadchar, char_option,
              my_determinist_random)

libtcod.console_set_custom_font(
    'oryx_tiles3.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD,
    32, 12)
libtcod.console_init_root(nwidth, nheight, 'johnstein\'s Game of RogueLife!',
                          False, libtcod.RENDERER_SDL)
libtcod.sys_set_fps(30)
Exemple #7
0
def area_cell_create(width, height, p_blocked, p_unblocked, nudge, steps, border=True, exits=0, connect=True, seed=lt.random_get_instance()):
    """
    :param width:
    :param height:
    :param p_blocked: - At least what percent of a valid area must be unblocked spaces.
    :param p_unblocked: - At least what percent of a valid area must be blocked spaces.
    :param nudge: - Higher number means more blocked space.
    :param steps: - How many steps to run the automata.
    :param border: - Requires a solid border?
    :param exits: - If there's a solid border, how many exits should there be?
    :return:
    """
    print "---"
    area = [[True for row in xrange(width)] for col in xrange(height)]
    # Create noise
    print "Generating noise..."
    area_noise = lt.noise_new(2, random=seed)
    for col in xrange(height):
        for row in xrange(width):
            if border:
                if row < 3 or row > width - 3:
                    area[col][row] = 1
                elif col < 3 or col > height - 3:
                    area[col][row] = 1
                else:
                    coords = (col, row)
                    n = lt.noise_get(area_noise, coords)
                    area[col][row] = int(round(abs(n) + nudge, 0))
            else:
                coords = (col, row)
                n = lt.noise_get(area_noise, coords)
                area[col][row] = int(round(abs(n) + nudge, 0))
    visualize(area)

    # Add in exits.
    print "Adding exits..."
    if exits > 0:
        exitcoords = []
        for direction in xrange(exits):
            row_size = random.randint(4, 10)
            col_size = random.randint(4, 10)
            if direction == 0:
                row_loc = random.randint(width/2 - width/4, width/2 + width/4)
                col_loc = height - col_size
                for col in xrange(col_size):
                    for row in xrange(row_size):
                        area[col_loc+col][row_loc+row] = 0
                for row in xrange(row_size):
                    coords = (height - 2, row_loc + row)
                    area[coords[0] + 1][coords[1]] = -1
                    exitcoords.append(coords)


    visualize(area)

    # Begin cellular automata
    print "Running automata..."
    for i in xrange(steps):
        next_step = area
        for col in xrange(height):
            for row in xrange(width):
                neighbors = count_neighbors(col, row, area)

                # Check births and survivals.
                # Current rules are: B5678 / S45678. May want to add the ability to affect that too.
                if area[col][row] == 1 and neighbors < 4:
                    next_step[col][row] = 0
                elif area[col][row] == 0 and neighbors > 4:
                    next_step[col][row] = 1
        area = next_step
        visualize(area)

    # Mark as ground only those ground tiles which can be reached from an arbitrary point near the center OR an exit.
    print "Counting reach..."
    while True:
        if exits == 0:
            row = random.randint(width/2 - 10, width/2 + 10)
            col = random.randint(height/2 - 10, height/2 + 10)
        elif exits > 0:
             col, row = exitcoords.pop()
        if area[col][row] == 0:
            reachable(col, row, area, 1)
            break
    # Replace 0's (unreachable sections) with 1 (blocked). and 2's (reachable sections)
    # with 0 (unblocked), while counting how many there are.
    unblocked_n = 0.
    blocked_n = 0.
    for col in xrange(height):
        for row in xrange(width):
            if area[col][row] == 1 or (area[col][row] == 0 and connect):
                area[col][row] = 1
                blocked_n += 1
            elif area[col][row] > 1 or (area[col][row] == 0 and not connect):
                if col == 0 or col == height - 1 or row == 0 or row == width - 1:
                    area[col][row] = -1
                unblocked_n += 1

    # Ensure the map fits our parameters.
    print "Testing parameters..."
    visualize(area)
    if unblocked_n <= width * height * p_unblocked:
        print "Not enough unblocked: ", unblocked_n, "<", width * height * p_unblocked
        if blocked_n <= width * height * p_blocked:
            print "Not enough blocked.", blocked_n, "<", width * height * p_blocked
        return False
    print "Area generated."
    return area
Exemple #8
0
	def generate_map(self):
		y = 0
		for row in MAPTEXT:
			self.map.append([])
			for char in row:
				if (char == '#'):
					tile = Tile(False, False, '#')
				elif (char == ' '):
					tile = Tile(True, True, ' ')
				elif (char == '='):
					tile = Tile(False, True, '=')
				self.map[-1].append(tile)
		self.height = len(self.map)
		self.width = len(self.map[0])

RNG = libtcod.random_get_instance()

class Character:
	def __init__(self):
		self.hp = None
		self.mp = None
		self.symbol = '@'
		self.x = 0
		self.y = 0
	
	def move(self, x, y):
		self.x += x
		self.y += y

gameMap = Map()
gameMap.generate_map()
def generateHeightmap(_map):
    print("Particle Deposition Generation...")

    _rand = tcod.random_get_instance()
    _hm = tcod.heightmap_new(_map.width, _map.height)

    #half-width and -height
    _hw = _map.width / 2
    _hh = _map.height / 2

    #quarter-width and -height
    _qw = _map.width / 4
    _qh = _map.height / 4

    #define our four "continental centers"
    _continents = [
        (_qw, _qh),  #top-left
        (_map.width - _qw, _qh),  #top-right
        (_qw, _map.height - _qh),  #btm-left
        (_map.width - _qw, _map.height - _qh)
    ]  #btm-right

    print("Continents:", _continents)

    _avg = min(_map.width, _map.height)

    _maxHillHeight = _avg / 4
    _maxHillRad = _avg / 8
    _iterations = _avg * 32

    for i in range(0, _iterations):

        _quadrant = tcod.random_get_int(_rand, 0, 3)

        _qx = _continents[_quadrant][0]
        _qy = _continents[_quadrant][1]

        _minX = _qx - ((_qw * CONT_SIZE) / 10)
        _maxX = _qx + ((_qw * CONT_SIZE) / 10)

        _minY = _qy - _qh
        _maxY = _qy + _qh

        x = tcod.random_get_int(_rand, _minX, _maxX)
        y = tcod.random_get_int(_rand, _minY, _maxY)

        height = tcod.random_get_int(_rand, -1 * _maxHillHeight,
                                     _maxHillHeight)
        rad = tcod.random_get_int(_rand, 0, _maxHillRad)

        tcod.heightmap_add_hill(_hm, x, y, rad, height)

    #"dig out" the space  around the edge of the map
    x = _hw
    for y in range(0, _map.height, max(1, _maxHillRad / 8)):

        height = tcod.random_get_int(_rand, _maxHillHeight / -2,
                                     -1 * _maxHillHeight)
        rad = tcod.random_get_int(_rand, 0, _maxHillRad * 2)

        tcod.heightmap_add_hill(_hm, 0, y, rad, height)
        tcod.heightmap_add_hill(_hm, _map.width - 1, y, rad, height)

    for x in range(0, _map.width, max(1, _maxHillRad / 4)):

        height = tcod.random_get_int(_rand, _maxHillHeight / -2,
                                     -1 * _maxHillHeight)
        rad = tcod.random_get_int(_rand, 0, _maxHillRad * 2)

        tcod.heightmap_add_hill(_hm, x, 0, rad, height)
        tcod.heightmap_add_hill(_hm, x, _map.height - 1, rad, height)

    tcod.heightmap_rain_erosion(
        _hm,
        _map.width * _map.height,  #number of raindrops
        0.2,  #erosion cooef (f)
        0.2)  #sediment cooef (f)

    _dx = [-2, -1, 0, 1, 2]
    _dy = [-2, -1, 0, 1, 2]
    _weight = [0.1, 0.1, 0.2, 0.3, 0.3]

    tcod.heightmap_kernel_transform(_hm, 5, _dx, _dy, _weight, -64, 255)

    tcod.heightmap_normalize(_hm, -255, 392)
    for y in range(0, _map.height):
        for x in range(0, _map.width):
            _map.coords[x][y].setAltitude(tcod.heightmap_get_value(_hm, x, y))

    return True
Exemple #10
0
                ret= ret + str(self.population[xx][yy])
            ret= ret + '|\n'
        return(ret)


#create world
nwidth = 100
nheight = 60
alivechar = '+'
deadchar = ' '
char_option = 'ascii'
speed = .1
inc = 0.01

# default generator
default = libtcod.random_get_instance()
# another random generator
my_random = libtcod.random_new()
# a random generator with a specific seed
my_determinist_random = libtcod.random_new_from_seed(0xdeadbeef)

world = World(nwidth,nheight, alivechar, deadchar, char_option, my_determinist_random)

libtcod.console_set_custom_font('oryx_tiles3.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 12)
libtcod.console_init_root(nwidth, nheight, 'johnstein\'s Game of RogueLife!', False, libtcod.RENDERER_SDL)
libtcod.sys_set_fps(30)

libtcod.console_map_ascii_codes_to_font(256   , 32, 0, 5)  #map all characters in 1st row
libtcod.console_map_ascii_codes_to_font(256+32, 32, 0, 6)  #map all characters in 2nd row

mouse = libtcod.Mouse()