Exemple #1
0
def make_map():
    global map, objects
 
    #the list of objects with just the player
    objects = [player]
    player.x = MAP_WIDTH / 2
    player.y = MAP_HEIGHT / 2
 
    myrng = libtcod.random_new(123)
    noise2d = libtcod.noise_new(2,libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY, myrng)
    libtcod.noise_set_type(noise2d, libtcod.NOISE_PERLIN)

    #fill map with "normal" tiles
    map = [[Tile(False, libtcod.light_gray)
        for y in range(MAP_HEIGHT)]
            for x in range(MAP_WIDTH)]

    #add color
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            value = int((libtcod.noise_get_fbm(noise2d,[x/float(MAP_WIDTH),y/float(MAP_HEIGHT)],32) + 1) * 96 )
            map[x][y] = Tile(False, libtcod.Color(value,value,value))

    r = [libtcod.random_get_int(0, CRATER_MIN_SIZE, (CRATER_MIN_SIZE + (CRATER_MAX_SIZE - CRATER_MIN_SIZE) * (MAX_CRATERS - i)**2/(MAX_CRATERS**2)) ) for i in range(MAX_CRATERS)]
    r.sort(reverse=True)
    for i in range(MAX_CRATERS):
        x = libtcod.random_get_int(0, 0, MAP_WIDTH - 1)
        y = libtcod.random_get_int(0, 0, MAP_HEIGHT - 1)
        # r = libtcod.random_get_int(0, CRATER_MIN_SIZE, (CRATER_MIN_SIZE + (CRATER_MAX_SIZE - CRATER_MIN_SIZE) * (MAX_CRATERS - i)/MAX_CRATERS) )
        make_crater(x, y, r[i])

    spawn_silicon(noise2d)
Exemple #2
0
    def __init__(self):
        
        logg.info('Main loop initialization.')

        logg.debug('Font size set to 8')
        libtcod.console_set_custom_font('main/terminal8x8_gs_ro.png',
            libtcod.FONT_LAYOUT_ASCII_INROW | libtcod.FONT_TYPE_GRAYSCALE)

        logg.debug('Main console initialization.')
        libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT,
            WINDOW_TITLE + ' v.' + VERSION, False,
                renderer = libtcod.RENDERER_SDL)
        logg.debug('Setting the FPS limit.')
        libtcod.sys_set_fps(LIMIT_FPS)
        logg.debug('Drawing console initialization.')
        self.con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)
        #bottom panel console
        logg.debug('Panels console initialization.')
        self.top_panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT)
        self.bottom_panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT)

        logg.debug('Gamestate variables initialization')
        self.entities=[]
        self.player = None
        self.gamestate = ""
        self.player_action = None
        self.map = None
        self.random = libtcod.random_new()
        self.score = 0
        self.gamemode = ''
Exemple #3
0
def create():
	display.create_surface('background')
	display.create_surface('text')
	display.blit_background('background')
	
	roll()
	
	NOISE = tcod.noise_new(2, h=tcod.NOISE_DEFAULT_HURST, random=tcod.random_new())
	
	for y in range(0, constants.WINDOW_HEIGHT):
		for x in range(0, constants.WINDOW_WIDTH):
			_noise_values = [(ZOOM * x / (constants.WINDOW_WIDTH)),
			                 (ZOOM * y / (constants.WINDOW_HEIGHT))]
			_height = 1 - tcod.noise_get_turbulence(NOISE, _noise_values, tcod.NOISE_SIMPLEX)
			_dist_to_crosshair = 30
			_crosshair_mod = abs((_dist_to_crosshair - 1))
			
			if _height > .4:
				_height = (_height - .4) / .4
				_r, _g, _b = numbers.clip(30 * _height, 20, 255), 50 * _height, numbers.clip(30 * _height, 30, 255)
			
			else:
				_r, _g, _b = 20, 0, 30
			
			_r += 30# * _crosshair_mod
			
			if x < SIDEBAR_WIDTH:
				if y < 7:
					_r = numbers.interp(_r, .0, .4)
					_g = numbers.interp(_g, .0, .4)
					_b = numbers.interp(_b, .0, .4)
					
				elif y < 43:
					_r = numbers.interp(_r, .0, .6)
					_g = numbers.interp(_g, .0, .6)
					_b = numbers.interp(_b, .0, .6)
					
				elif y < constants.WINDOW_HEIGHT:
					_r = numbers.interp(_r, 1, .7)
					_g = numbers.interp(_g, 1, .7)
					_b = numbers.interp(_b, 1, .7)

				else:
					_r = (int(round(_r * 1.0)))
					_g = (int(round(_g * .2)))
					_b = (int(round(_b * .2)))
			
			if x > SIDEBAR_WIDTH + 3 and x < constants.WINDOW_WIDTH - 6:
				if y > 18 and y < 36:
					_r = numbers.interp(_r, 255, .1)
					_g = numbers.interp(_g, 255, .1)
					_b = numbers.interp(_b, 255, .1)
			
			if x > SIDEBAR_WIDTH + 3 and x < constants.WINDOW_WIDTH - 6:
				if y > 10 and y < 16:
					_r = numbers.interp(_r, .0, .4)
					_g = numbers.interp(_g, .0, .4)
					_b = numbers.interp(_b, .0, .4)
			
			display._set_char('background', x, y, ' ', (0, 0, 0), (_r, _g, _b))
Exemple #4
0
def create():
    global NOISE

    display.create_surface("background")

    NOISE = tcod.noise_new(2, h=tcod.NOISE_DEFAULT_HURST, random=tcod.random_new())

    paint_map(initial=True)
Exemple #5
0
def make_rivers(heightmap, size, seed, river_count=None):
    rivers = []
    sealevel = -15
    random = lt.random_new()
    if seed:
        random = lt.random_new_from_seed(seed)
    if river_count is None:
        river_count = lt.random_get_int(random, 10, 15)

    mouths = [(0, 0)]
    for river in xrange(river_count):
        while True:
            setting = True
            col = lt.random_get_int(random, 0, size - 1)
            row = lt.random_get_int(random, 0, size - 1)
            if sealevel > lt.heightmap_get_value(heightmap, row, col) >= sealevel - 4:
                for mouth in mouths:
                    if abs(col - mouth[0]) < 5 and abs(row - mouth[1]) < 5:
                        setting = False
                if setting:
                    mouths.append((col, row))
                    rivers.append(River(col, row, heightmap, size, random))
                    break
    visualize(rivers, False)

    # Clean up inappropriate rivers.
    to_remove = set()
    i = -1
    for river in rivers:
        i += 1
        if len(river.tiles) < 15:
            to_remove.add(i)
        if lt.heightmap_get_value(heightmap, river.head_row, river.head_col) < 30:
            to_remove.add(i)
        for other in rivers:
            if river != other:
                x = True
                for n in list(to_remove):
                    if other == rivers[n] or river == rivers[n]:
                        x = False
                if x:
                    for (this_x, this_y) in river.tiles:
                        for (other_x, other_y) in other.tiles:
                            distance = ((this_x - other_x) ** 2 + (this_y - other_y) ** 2) ** 0.5
                            if distance < 2:
                                to_remove.add(i)
                                break
    remove = sorted(list(to_remove), reverse=True)
    for n in remove:
        rivers.pop(n)

    if len(rivers) > 0:
        visualize(heightmap, False)
        visualize(rivers)
    else:
        visualize(heightmap)

    return rivers
Exemple #6
0
def create():
    global NOISE

    display.create_surface('background')

    NOISE = tcod.noise_new(2,
                           h=tcod.NOISE_DEFAULT_HURST,
                           random=tcod.random_new())

    paint_map(initial=True)
Exemple #7
0
 def attackCreature(self, target):
   rand = libtcod.random_new()
   damage = libtcod.random_get_int(rand, 0, self.attack)
   defense = libtcod.random_get_int(rand, 0, target.defense)
   
   delta = damage - defense
   if delta > 0:
     target.attrDelta('health', - delta)
     print self.species + " hit " + target.species + " for " + str(delta) + " damage! " +\
       str(target.health) + " health left"
     if target.health <= 0:
       target.die()
Exemple #8
0
	def __init__(self):
		self.rnd = libtcod.random_new()
		self.noise = 0
		self.hm_list = [0] * (game.WORLDMAP_WIDTH * game.WORLDMAP_HEIGHT)
		self.sandheight = game.terrain['Coast']['elevation']
		self.map_image_big = None
		self.map_image_small = None
		self.player_positionx = 0
		self.player_positiony = 0
		self.originx = 0
		self.originy = 0
		self.max_distance = 0
		self.dungeons = []
		self.generate()
Exemple #9
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 #10
0
def make_heightmap(size, seed):

    # Gradient generated by distance to the northeast corner (creates northeast ocean).
    gradient1 = lt.heightmap_new(size, size)
    for col in xrange(size):
        for row in xrange(size):
            distance = ((row - size) ** 2 + col ** 2) ** 0.5
            lt.heightmap_set_value(gradient1, row, col, distance)
    lt.heightmap_clamp(gradient1, mi=0, ma=WORLD_SIZE)
    lt.heightmap_scale(gradient1, 2)
    # Similar gradient, but cube root (creates mountains around edge).
    gradient2 = lt.heightmap_new(size, size)
    for col in xrange(size):
        for row in xrange(size):
            distance = ((row - size) ** 2 + col ** 2) ** 0.33
            lt.heightmap_set_value(gradient2, row, col, distance)
    lt.heightmap_clamp(gradient2, mi=0, ma=WORLD_SIZE / 6)
    lt.heightmap_scale(gradient2, 5)

    # Height map based on Perlin noise.
    heightmap = lt.heightmap_new(size, size)
    random = lt.random_new()
    if seed:
        random = lt.random_new_from_seed(seed)
    perlin = lt.noise_new(2, h=2, l=2, random=random)

    lt.heightmap_add_fbm(heightmap, perlin, mulx=3, muly=3, addx=0, addy=0, octaves=8, delta=50, scale=100)

    # Add in gradients.
    lt.heightmap_add_hm(heightmap, gradient1, heightmap)
    lt.heightmap_add_hm(heightmap, gradient2, heightmap)

    lt.heightmap_normalize(heightmap, mi=-100, ma=105)
    lt.heightmap_clamp(heightmap, mi=-50, ma=100)
    lt.heightmap_normalize(heightmap, mi=-100, ma=100)
    visualize(heightmap)

    return heightmap
Exemple #11
0
	def new_game(self, chargeneration=True):
		global rnd, message, player, char, game_state, gametime, worldmap, current_map, savefiles
		cardinal = [-(WORLDMAP_WIDTH - 1), -(WORLDMAP_WIDTH), -(WORLDMAP_WIDTH + 1), -1, 1, WORLDMAP_WIDTH - 1, WORLDMAP_WIDTH, WORLDMAP_WIDTH + 1]
		rnd = libtcod.random_new()
		message = messages.Message()
		player = Player()
		char = mapgen.Object(libtcod.random_get_int(rnd, 40, 80), libtcod.random_get_int(rnd, 26, 46), player.icon, 'player', player.icon_color, blocks=True)
		if chargeneration:
			game_state = chargen.create_character()
		else:
			game_state = chargen.quick_start()
		if game_state == 'playing':
			contents = ['Generating world map...']
			messages.box(None, None, 'center_screenx', 'center_screeny', len(max(contents, key=len)) + 16, len(contents) + 4, contents, input=False, align=libtcod.CENTER, nokeypress=True)
			gametime = Time()
			worldmap = worldgen.World()
			current_map = mapgen.Map('Wilderness', 'WD', 0, (worldmap.player_positiony * WORLDMAP_WIDTH) + worldmap.player_positionx, type=util.find_terrain_type((worldmap.player_positiony * WORLDMAP_WIDTH) + worldmap.player_positionx))
			for i in range(len(border_maps)):
				border_maps[i] = mapgen.Map('Wilderness', 'WD', 0, (worldmap.player_positiony * WORLDMAP_WIDTH) + worldmap.player_positionx + cardinal[i], type=util.find_terrain_type((worldmap.player_positiony * WORLDMAP_WIDTH) + worldmap.player_positionx + cardinal[i]))
			IO.save_game(True)
			savefiles = [f for f in os.listdir('saves') if os.path.isfile(os.path.join('saves', f))]
			util.combine_maps()
			message.new('Welcome to Immortal, ' + player.name + '!', turns, libtcod.Color(96, 212, 238))
			self.play_game()
Exemple #12
0
#!/usr/bin/python
import math
import libtcodpy as libtcod
# size of the heightmap
HM_WIDTH=80
HM_HEIGHT=80
rnd=libtcod.random_new()
noise=libtcod.noise_new(2,libtcod.NOISE_DEFAULT_HURST,libtcod.NOISE_DEFAULT_LACUNARITY,rnd)
def addHill(hm,nbHill,baseRadius,radiusVar,height) :
    for i in range(nbHill) :
        hillMinRadius=baseRadius*(1.0-radiusVar)
        hillMaxRadius=baseRadius*(1.0+radiusVar)
        radius = libtcod.random_get_float(rnd,hillMinRadius, hillMaxRadius)
        theta = libtcod.random_get_float(rnd,0.0, 6.283185) # between 0 and 2Pi
        dist = libtcod.random_get_float(rnd,0.0, float(min(HM_WIDTH,HM_HEIGHT))/2 - radius)
        xh = int(HM_WIDTH/2 + math.cos(theta) * dist)
        yh = int(HM_HEIGHT/2 + math.sin(theta) * dist)
        libtcod.heightmap_add_hill(hm,float(xh),float(yh),radius,height)
# 3x3 kernel for smoothing operations
smoothKernelSize=9
smoothKernelDx=[-1,0,1,-1,0,1,-1,0,1]
smoothKernelDy=[-1,-1,-1,0,0,0,1,1,1]
smoothKernelWeight=[1.0,2.0,1.0,2.0,20.0,2.0,1.0,2.0,1.0]
# function building the heightmap
def buildMap(hm) :
    libtcod.heightmap_add_fbm(hm,noise,3.83,3.83,400,0,4.93,1,0.35)
    libtcod.heightmap_normalize(hm)

def head(l):
    if len(l) == 0:
        return None
Exemple #13
0
        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
Exemple #14
0
def create():
    display.create_surface('background')
    display.create_surface('text')
    display.blit_background('background')

    roll()

    NOISE = tcod.noise_new(2,
                           h=tcod.NOISE_DEFAULT_HURST,
                           random=tcod.random_new())

    for y in range(0, constants.WINDOW_HEIGHT):
        for x in range(0, constants.WINDOW_WIDTH):
            _noise_values = [(ZOOM * x / (constants.WINDOW_WIDTH)),
                             (ZOOM * y / (constants.WINDOW_HEIGHT))]
            _height = 1 - tcod.noise_get_turbulence(NOISE, _noise_values,
                                                    tcod.NOISE_SIMPLEX)
            _dist_to_crosshair = 30
            _crosshair_mod = abs((_dist_to_crosshair - 1))

            if _height > .4:
                _height = (_height - .4) / .4
                _r, _g, _b = numbers.clip(30 * _height, 20,
                                          255), 50 * _height, numbers.clip(
                                              30 * _height, 30, 255)

            else:
                _r, _g, _b = 20, 0, 30

            _r += 30  # * _crosshair_mod

            if x < SIDEBAR_WIDTH:
                if y < 7:
                    _r = numbers.interp(_r, .0, .4)
                    _g = numbers.interp(_g, .0, .4)
                    _b = numbers.interp(_b, .0, .4)

                elif y < 43:
                    _r = numbers.interp(_r, .0, .6)
                    _g = numbers.interp(_g, .0, .6)
                    _b = numbers.interp(_b, .0, .6)

                elif y < constants.WINDOW_HEIGHT:
                    _r = numbers.interp(_r, 1, .7)
                    _g = numbers.interp(_g, 1, .7)
                    _b = numbers.interp(_b, 1, .7)

                else:
                    _r = (int(round(_r * 1.0)))
                    _g = (int(round(_g * .2)))
                    _b = (int(round(_b * .2)))

            if x > SIDEBAR_WIDTH + 3 and x < constants.WINDOW_WIDTH - 6:
                if y > 18 and y < 36:
                    _r = numbers.interp(_r, 255, .1)
                    _g = numbers.interp(_g, 255, .1)
                    _b = numbers.interp(_b, 255, .1)

            if x > SIDEBAR_WIDTH + 3 and x < constants.WINDOW_WIDTH - 6:
                if y > 10 and y < 16:
                    _r = numbers.interp(_r, .0, .4)
                    _g = numbers.interp(_g, .0, .4)
                    _b = numbers.interp(_b, .0, .4)

            display._set_char('background', x, y, ' ', (0, 0, 0), (_r, _g, _b))
Exemple #15
0
import Constants
import libtcodpy as libtcod

noise_field = None
height_map = None

# rnd = libtcod.random_new_from_seed(654321)
rnd = libtcod.random_new()


def initialze(scale=50, weather=False):
    global noise_field, height_map
    noise_field = libtcod.noise_new(2, 0.5, 2.0, rnd)  # 0.5f  and 2.0f
    libtcod.noise_set_type(noise_field, libtcod.NOISE_SIMPLEX)

    height_map = libtcod.heightmap_new(Constants.MAP_WIDTH,
                                       Constants.MAP_HEIGHT)

    for y in range(Constants.MAP_HEIGHT):
        for x in range(Constants.MAP_WIDTH):
            libtcod.heightmap_set_value(height_map, x, y,
                                        get_noise_value(x, y, scale=scale))

    libtcod.heightmap_normalize(height_map, 0.0, 1.0)
    # libtcod.heightmap_add_hill(height_map, 40, 40, 6, 0.8)
    if weather:
        libtcod.heightmap_rain_erosion(height_map, 5000, 0.75, .75)


def get_height_value(x, y):
    return libtcod.heightmap_get_value(height_map, x, y)
Exemple #16
0
        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()
key = libtcod.Key()