Esempio n. 1
0
	def create_map_images(self, mode=0):
		if mode == 0:
			print 'Creating images....'
			t0 = libtcod.sys_elapsed_seconds()
		con = libtcod.console_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
		self.map_image_small = libtcod.image_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
		self.create_map_legend(con, mode)
		libtcod.image_scale(self.map_image_small, (game.SCREEN_WIDTH - 2) * 2, (game.SCREEN_HEIGHT - 2) * 2)

		if mode == 0:
			while self.player_positionx == 0:
				start = self.randomize('int', 0, (game.WORLDMAP_WIDTH * game.WORLDMAP_HEIGHT) - 1, 3)
				if int(self.hm_list[start] * 1000) in range(int(game.terrain['Forest']['elevation'] * 1000), int(game.terrain['Forest']['maxelev'] * 1000)):
					self.player_positionx = start % game.WORLDMAP_WIDTH
					self.player_positiony = start / game.WORLDMAP_WIDTH
					self.originx = self.player_positionx
					self.originy = self.player_positiony

					path = self.set_dijkstra_map()
					for y in range(game.WORLDMAP_HEIGHT):
						for x in range(game.WORLDMAP_WIDTH):
							dist = libtcod.dijkstra_get_distance(path, x, y)
							if dist > self.max_distance:
								self.max_distance = int(round(dist))
					#libtcod.image_put_pixel(self.map_image_small, self.player_positionx, self.player_positiony, libtcod.white)

		if mode == 2:
			self.map_image_big = libtcod.image_from_console(con)
			libtcod.image_save(self.map_image_big, 'maps/worldmap-' + game.player.name + '.png')
			self.map_image_big = None
		libtcod.console_delete(con)
		if mode == 0:
			t1 = libtcod.sys_elapsed_seconds()
			print '    done! (%.3f seconds)' % (t1 - t0)
Esempio n. 2
0
def test_image(console, tmpdir):
    img = libtcodpy.image_new(16, 16)
    libtcodpy.image_clear(img, libtcodpy.Color(0, 0, 0))
    libtcodpy.image_invert(img)
    libtcodpy.image_hflip(img)
    libtcodpy.image_rotate90(img)
    libtcodpy.image_vflip(img)
    libtcodpy.image_scale(img, 24, 24)
    libtcodpy.image_set_key_color(img, libtcodpy.Color(255, 255, 255))
    libtcodpy.image_get_alpha(img, 0, 0)
    libtcodpy.image_is_pixel_transparent(img, 0, 0)
    libtcodpy.image_get_size(img)
    libtcodpy.image_get_pixel(img, 0, 0)
    libtcodpy.image_get_mipmap_pixel(img, 0, 0, 1, 1)
    libtcodpy.image_put_pixel(img, 0, 0, libtcodpy.Color(255, 255, 255))
    libtcodpy.image_blit(img, console, 0, 0, libtcodpy.BKGND_SET, 1, 1, 0)
    libtcodpy.image_blit_rect(img, console, 0, 0, 16, 16, libtcodpy.BKGND_SET)
    libtcodpy.image_blit_2x(img, console, 0, 0)
    libtcodpy.image_save(img, tmpdir.join('test.png').strpath)
    libtcodpy.image_delete(img)

    # Not portable.
    #img = libtcodpy.image_from_console(console)
    #libtcodpy.image_refresh_console(img, console)
    #libtcodpy.image_delete(img)

    libtcodpy.image_delete(libtcodpy.image_load('../data/img/circle.png'))
Esempio n. 3
0
 def __init__(self, size, intensity=1.0, light_colour=Mappable.LIGHT_H_CLAMP):
     self._size              = size
     self.intensity          = intensity
     self.raw_light_colour   = light_colour
     self.light_enabled      = True
     self.__tcod_light_map   = libtcod.map_new(size.x + 2, size.y + 2)
     self.__tcod_light_image = libtcod.image_new(size.x + 2, size.y + 2)
Esempio n. 4
0
 def __init__(self, radius=0, intensity=1.0, light_colour=Mappable.LIGHT_H_CLAMP):
     self._radius            = radius == 0 and 100 or radius # TODO: more sensible behaviour for infinite r
     self.intensity          = intensity
     self.raw_light_colour   = light_colour
     self.light_enabled      = True
     self.__tcod_light_map   = libtcod.map_new(radius * 2 + 1, radius * 2 + 1)
     self.__tcod_light_image = libtcod.image_new(radius * 2 + 1, radius * 2 + 1)
Esempio n. 5
0
 def __init__(self,
              size,
              intensity=1.0,
              light_colour=Mappable.LIGHT_H_CLAMP):
     self._size = size
     self.intensity = intensity
     self.raw_light_colour = light_colour
     self.light_enabled = True
     self.__tcod_light_map = libtcod.map_new(size.x + 2, size.y + 2)
     self.__tcod_light_image = libtcod.image_new(size.x + 2, size.y + 2)
Esempio n. 6
0
 def set_graphics(self, flag=None):
     # if the graphics layer hasn't been initialized, start it
     # if called with no arguments, switches the state of graphics mode
     # otherwise, switches to the designated state (True for on, False for off)
     if flag is None:
         flag = not self.graphics_mode
     self.graphics_mode = flag
     if self.graphics_mode:
         self.img = libtcod.image_new(self.width * 2, self.height * 2)
         libtcod.image_clear(self.img, self.background)
Esempio n. 7
0
 def radius(self, r):
     """Change light radius"""
     if r == self._radius:
         return # because this is slow!
     e = self.light_enabled
     self.close()
     self.light_enabled      = e
     self._radius            = r
     self.__tcod_light_map   = libtcod.map_new(r * 2 + 1, r * 2 + 1)
     self.__tcod_light_image = libtcod.image_new(r * 2 + 1, r * 2 + 1)
     self.reset_map()
Esempio n. 8
0
 def radius(self, r):
     """Change light radius"""
     if r == self._radius:
         return  # because this is slow!
     e = self.light_enabled
     self.close()
     self.light_enabled = e
     self._radius = r
     self.__tcod_light_map = libtcod.map_new(r * 2 + 1, r * 2 + 1)
     self.__tcod_light_image = libtcod.image_new(r * 2 + 1, r * 2 + 1)
     self.reset_map()
Esempio n. 9
0
 def __init__(self,
              radius=0,
              intensity=1.0,
              light_colour=Mappable.LIGHT_H_CLAMP):
     self._radius = radius == 0 and 100 or radius  # TODO: more sensible behaviour for infinite r
     self.intensity = intensity
     self.raw_light_colour = light_colour
     self.light_enabled = True
     self.__tcod_light_map = libtcod.map_new(radius * 2 + 1, radius * 2 + 1)
     self.__tcod_light_image = libtcod.image_new(radius * 2 + 1,
                                                 radius * 2 + 1)
Esempio n. 10
0
def generate_screen():
    # create 'computer screen' backdrop and store in screen_img
    screen_img = libtcod.image_new(160, 100)
    for x in range(124):
        for y in range(68):
            libtcod.image_put_pixel(screen_img, x + 16, y + 16, libtcod.grey)
    for x in range(120):
        for y in range(60):
            libtcod.image_put_pixel(screen_img, x + 18, y + 18, libtcod.darkest_green)
    for x in range(3):
        libtcod.image_put_pixel(screen_img, x + 132, 80, libtcod.red)
    return screen_img
Esempio n. 11
0
	def __init__(self, owner, width = MAP_WIDTH, height = MAP_HEIGHT, gen = True):
		self.size = self.width, self.height = width, height
		self.owner = owner
		self.generated = False

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

		self.image = libtcod.image_new(self.width * 2, self.height * 2)
		
		if gen:
			self.generate()
Esempio n. 12
0
def generate_starpic():
    # Generates a random starfield pattern and stores it in img
    img = libtcod.image_new(160, 100)
    libtcod.image_clear(img, libtcod.black)
    colors = [libtcod.lightest_yellow, libtcod.lightest_grey, libtcod.white, libtcod.white, libtcod.light_orange,
              libtcod.darker_red]

    for x in range(100):
        x = libtcod.random_get_int(0, 0, 159)
        y = libtcod.random_get_int(0, 0, 99)
        c = libtcod.random_get_int(0, 0, len(colors) - 1)
        libtcod.image_put_pixel(img, x, y, colors[c])

    return img
Esempio n. 13
0
    def __init__(self, win_name='BlueBox', boot_msg=True, graphics_mode=False, img=None,
                 width=40, height=24, fps=24, foreground=color_on, background=color_off):
        # declare initial graphics colors and resolution (40 or 80 column modes)
        self.win_name = win_name
        self.boot_msg = boot_msg
        self.graphics_mode = graphics_mode
        self.img = img
        self.width = width
        self.height = height
        self.fps = fps
        self.foreground = foreground
        self.background = background

        # initialize libtcod console and store to self.con
        if width >= 80:
            libtcod.console_set_custom_font('bluebox80.png',
                                            libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)
        else:
            libtcod.console_set_custom_font('bluebox.png',
                                            libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)
        libtcod.console_init_root(self.width, self.height, self.win_name, False)
        libtcod.sys_set_fps(self.fps)
        self.con = libtcod.console_new(self.width, self.height)

        # set console colors and alignment
        libtcod.console_set_default_foreground(self.con, self.foreground)
        libtcod.console_set_default_background(self.con, self.background)
        libtcod.console_set_alignment(self.con, libtcod.LEFT)

        # create the cursor
        self.cursor = Cursor()

        # create an array containing the screen contents
        self.screen = [[' ' for y in range(self.height)] for x in range(self.width)]

        # if graphics layer is enabled, initialize it.
        if graphics_mode:
            self.img = libtcod.image_new(self.width * 2, self.height * 2)
            libtcod.image_clear(self.img, self.background)

        # Display the default boot message, disable with boot_msg=False
        if boot_msg:
            self.text_out('BUTTECH CAI-1 (C) 1987')
            self.text_out('PRODUCED UNDER CONTRACT FOR THE BUTTE')
            self.text_out('COUNTY BOARD OF EDUCATION')
            self.text_out('')
Esempio n. 14
0
def show_text_log(text, img=None, delay=True, center_first_line=False):
    # takes list of text and displays it line by line against a black screen
    # optional parameters: img = an image based in libtcod.image format, defaults to None (black screen)
    # delay = whether to use the text delay, defaults to True (for cinematic style sequences)
    if img is None:
        img = libtcod.image_new(160, 100)
    libtcod.image_blit_2x(img, 0, 0, 0)

    libtcod.console_set_default_foreground(0, libtcod.green)

    for y in range(len(text)):
        key = libtcod.console_check_for_keypress()

        if key.vk == libtcod.KEY_ESCAPE:
            return
        else:
            if center_first_line and y == 0:
                libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 5 + y * 2, libtcod.BKGND_NONE,
                                         libtcod.CENTER, text[y])
            else:
                libtcod.console_print_ex(0, SCREEN_WIDTH / 8, SCREEN_HEIGHT / 5 + y * 2, libtcod.BKGND_NONE,
                                         libtcod.LEFT, text[y])

            if delay:
                libtcod.console_flush()
                time.sleep(1.3)
                key = libtcod.console_check_for_keypress()
                if key.vk == libtcod.KEY_SPACE:
                    delay = False

    libtcod.console_set_default_foreground(0, libtcod.white)
    libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER,
                             'Press any key to continue')
    libtcod.console_flush()
    input_valid = False
    while not input_valid:
        key = libtcod.console_wait_for_keypress(True)
        if key.pressed:
            key = libtcod.console_wait_for_keypress(False)
            if not key.pressed:
                input_valid = True
Esempio n. 15
0
    def __init__(self, width, height):
        self.size = width 
        self.width = width
        self.height = height
        self.units = []
        self.selected_unit = None

        self.world_img = libtcod.image_new(self.width, self.height)
        self.ground_map = libtcod.map_new(width, height)
        self.deepsea_map = libtcod.map_new(width, height)
        
        self.noise_zoom = 5.0
        self.noise_octaves = 8.0

        self.center = [self.width/2, self.height/2]

        self.map_list = [[Tile(True, libtcod.black) for y in range(height)] for x in range(width)]

        self.world_noise = libtcod.noise_new(2)
        self.ocean_noise = libtcod.noise_new(2)
        libtcod.noise_set_type(self.world_noise, libtcod.NOISE_PERLIN)
        self.generate_land()
con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)
libtcod.console_set_default_background(con, libtcod.Color(0,0,0))

noise_func = 0
noise_dx = 0.0
noise_dy = 0.0
noise_dz = 0.0
noise_octaves = 4.0
noise_zoom = 3.0
noise_hurst = libtcod.NOISE_DEFAULT_HURST
noise_lacunarity = libtcod.NOISE_DEFAULT_LACUNARITY

# noise = libtcod.noise_new(2)
noise = libtcod.noise_new(3)

noise_img=libtcod.image_new(SCREEN_WIDTH, SCREEN_HEIGHT)

noise_dx += 0.01
noise_dy += 0.01
noise_dz += 0.01

pi_times_two = 2 * math.pi
pi_div_two = math.pi / 2.0

theta = 0.0
phi = pi_div_two * -1.0
x = 0
y = 0

while phi <= pi_div_two:
    while theta <= pi_times_two:
Esempio n. 17
0
##===============================================================================

    def getMap(self):
        ##===============================================================================
        return self.map_arr


#Just for testing ;)
if __name__ == "__main__":
    Main_Console = libtcod.console_init_root(Game_Screen_Width,
                                             Game_Screen_Height,
                                             "Lost Horizon 0.0.1a", False)
    libtcod.sys_set_fps(25)
    map = GenDungeon(50, 50, var=50)
    map_arr = map.getMap()
    pix = libtcod.image_new(len(map_arr), len(map_arr))
    for x in range(len(map_arr)):
        for y in range(len(map_arr)):
            if map_arr[x][y] == "#":
                libtcod.image_put_pixel(pix, x, y, libtcod.dark_grey)
            if map_arr[x][y] == " ":
                libtcod.image_put_pixel(pix, x, y, libtcod.white)
    while not libtcod.console_is_window_closed():
        #libtcod.image_blit(pix,0,50,50,libtcod.BKGND_SET,1.0,1.0,0.0)
        libtcod.image_blit_2x(pix, 0, 0, 0)
        libtcod.console_flush()
        key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED)
        if key.vk == libtcod.KEY_ESCAPE:
            break
Esempio n. 18
0
                for xx in range (x+1,x+xsize+1):
                    self.map_arr[xx][yy] = " "
                    self.map_arr[xx+self.room_size][yy+self.room_size] = " "

##===============================================================================
    def getMap(self):
##===============================================================================
        return self.map_arr

#Just for testing ;)
if __name__ == "__main__":
    Main_Console = libtcod.console_init_root(Game_Screen_Width,Game_Screen_Height,"Lost Horizon 0.0.1a",False)
    libtcod.sys_set_fps(25)
    map = GenDungeon(50,50,var=50)
    map_arr = map.getMap()
    pix = libtcod.image_new(len(map_arr),len(map_arr))
    for x in range(len(map_arr)):
        for y in range(len(map_arr)):
            if map_arr[x][y] == "#":
                libtcod.image_put_pixel(pix,x,y,libtcod.dark_grey)
            if map_arr[x][y] == " ":
                libtcod.image_put_pixel(pix,x,y,libtcod.white)
    while not libtcod.console_is_window_closed():
        #libtcod.image_blit(pix,0,50,50,libtcod.BKGND_SET,1.0,1.0,0.0)
        libtcod.image_blit_2x(pix,0,0,0)
        libtcod.console_flush()
        key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED)
        if key.vk == libtcod.KEY_ESCAPE:
            break
    
    
Esempio n. 19
0
 def __init__(self, width, height):
     self.width = width
     self.height = height
     self.console = libtcod.console_new(width, height)
     self.unit_image = libtcod.image_new(self.width - 4, self.width - 4)
Esempio n. 20
0
 def __init__(self, width, height):
     self.width = width
     self.height = height
     self.image_id = libtcod.image_new(width, height)
Esempio n. 21
0
 def image_new(self,x,y):
     img = libtcod.image_new(x,y)
     self.mImages.append(img)
     return len(self.mImages)