Exemple #1
0
def dbox(x, y, w, h, text, wrap=True, border=0, margin=0, con=0, disp='poly'):
    con_box = libtcod.console_new(w, h)

    pad = 0 if border == None else 1
    offset = margin + pad
    fulltext = textwrap.fill(text, w - 2 * (margin + pad)) if wrap else text
    boxes = word.split_stanza(
        fulltext, h - 2 * (margin + pad)) if disp == 'poly' else [fulltext]
    length = len(boxes)
    i = 0
    for box in boxes:
        i += 1
        libtcod.console_clear(con_box)
        #   print
        if border is not None: rectangle(con_box, 0, 0, w, h, border)
        libtcod.console_print(con_box, offset, offset, box)
        put_text_special_colors(con_box, box, offset)
        libtcod.console_blit(
            con_box,
            0,
            0,
            w,
            h,  # Source
            con,
            x,
            y)  # Destination
        #   wait for user input to continue...
        if i < length:
            rog.blit_to_final(con, 0, 0)
            rog.refresh()
            while True:
                reply = rog.Input(x + w - 1, y + h - 1, mode="wait")
                if (reply == ' ' or reply == ''): break
    libtcod.console_delete(con_box)
Exemple #2
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)
Exemple #3
0
def render_effects():
    global activeeffects
    for effect in activeeffects:
        if effect.duration == 0:
            libtcod.console_delete(effect.console)
            activeeffects.remove(effect)
        else:
            effect.draw()
Exemple #4
0
def offscreen(console):
    """Return an off-screen console with the same size as the root console."""
    offscreen = libtcodpy.console_new(
        libtcodpy.console_get_width(console),
        libtcodpy.console_get_height(console),
        )
    yield offscreen
    libtcodpy.console_delete(offscreen)
Exemple #5
0
 def resize(self, w,h):
     """Changes the size of the canvas, copying over the contents of this canvas.
     Content outside of the new canvas bounds is clipped.
     """
     new = dlib.console_new(w,h)
     bw = min(w, self.width)
     bh = min(h, self.height)
     dlib.console_blit(self._intern, 0, 0, bw, bh, new, 0, 0)    #copy contents
     dlib.console_delete(self._intern)   #dispose old console
     self._intern = new
Exemple #6
0
def settings():
	width, height = 44, 10
	box = libtcod.console_new(width, height)
	game.messages.box_gui(box, 0, 0, width, height, libtcod.green)
	libtcod.console_set_default_foreground(box, libtcod.black)
	libtcod.console_set_default_background(box, libtcod.green)
	libtcod.console_print_ex(box, width / 2, 0, libtcod.BKGND_SET, libtcod.CENTER, ' Settings ')
	libtcod.console_set_default_foreground(box, libtcod.white)
	util.change_settings(box, width, height, blitmap=True)
	libtcod.console_delete(box)
	game.draw_gui = True
Exemple #7
0
def main():
    while True:
        render_all()

        player_action = player.ai.take_turn()
        if player_action == "exit":
            for console in [area.con, frame, panel, log]:
                lt.console_delete(console)
            lt.console_clear(0)
            lt.console_flush()
            return 'exit'
Exemple #8
0
	def settings(self):
		width, height = 44, 10
		box = libtcod.console_new(width, height)
		messages.box_gui(box, 0, 0, width, height, libtcod.green)
		libtcod.console_set_default_foreground(box, libtcod.black)
		libtcod.console_set_default_background(box, libtcod.green)
		libtcod.console_print_ex(box, 20, 0, libtcod.BKGND_SET, libtcod.CENTER, ' Settings ')
		libtcod.console_set_default_foreground(box, libtcod.white)
		util.change_settings(box, width, height, blitmap=False)
		libtcod.console_delete(box)
		IO.load_settings()
Exemple #9
0
def test_console_rexpaint_list_save_load(console, tmpdir):
    con1 = libtcodpy.console_new(8, 2)
    con2 = libtcodpy.console_new(8, 2)
    libtcodpy.console_print(con1, 0, 0, 'hello')
    libtcodpy.console_print(con2, 0, 0, 'world')
    xp_file = tmpdir.join('test.xp').strpath
    assert libtcodpy.console_list_save_xp([con1, con2], xp_file, 1)
    for a, b in zip([con1, con2], libtcodpy.console_list_load_xp(xp_file)):
        assertConsolesEqual(a, b)
        libtcodpy.console_delete(a)
        libtcodpy.console_delete(b)
Exemple #10
0
def show_worldmap():
	box = libtcod.console_new(game.SCREEN_WIDTH, game.SCREEN_HEIGHT)
	game.messages.box_gui(box, 0, 0, game.SCREEN_WIDTH, game.SCREEN_HEIGHT, libtcod.green)
	libtcod.console_set_default_foreground(box, libtcod.black)
	libtcod.console_set_default_background(box, libtcod.green)
	libtcod.console_print_ex(box, game.SCREEN_WIDTH / 2, 0, libtcod.BKGND_SET, libtcod.CENTER, ' World Map ')
	libtcod.console_set_default_foreground(box, libtcod.green)
	libtcod.console_set_default_background(box, libtcod.black)
	libtcod.console_print_ex(box, game.SCREEN_WIDTH / 2, game.SCREEN_HEIGHT - 1, libtcod.BKGND_SET, libtcod.CENTER, '[ Red dot - You, Black dots - Dungeons, S - Save map, Z - Zoom, TAB - Exit ]')
	libtcod.console_set_default_foreground(box, libtcod.white)
	util.showmap(box)
	libtcod.console_delete(box)
	game.draw_gui = True
    def start_new_round(self, winner_of_last_round=None):
        """starts a new round of pong
        says who won, shows a countdown, moves the ball to the center, resets the players
        at the end, wipes the conway sim and resumes play """

        # lets do stuff in an off-screen console, so we can use transparency
        # so the player can see the map
        con = tcod.console_new(self.width, self.height)
        time_elapsed = 0.0  # in seconds
        x = self.width / 2
        tcod.console_set_alignment(con, tcod.CENTER)
        while self.alive and not tcod.console_is_window_closed() and \
                time_elapsed < 3.0:
            y = self.height / 2
            if winner_of_last_round:
                tcod.console_set_default_foreground(con,
                                                    winner_of_last_round.color)
                player_num = self.players.index(winner_of_last_round) + 1
                string = "Player %d scores!" % player_num
                height = tcod.console_get_height_rect(con, x, y, self.width,
                                                      self.height, string)
                tcod.console_print_rect(con, x, y, self.width, height, string)
                y += height
            tcod.console_set_default_foreground(con, tcod.white)

            string = "New round starting in %d seconds..." % int(3 - time_elapsed)
            height = tcod.console_get_height_rect(con, x, y, self.width,
                                                  self.height,  string)
            tcod.console_print_rect(con, x, y, self.width, height, string)

            self.handle_input()
            self.update_conway()
            self.render_all()
            tcod.console_blit(con, 0, 0, 0, 0, 0, 0, 0, 1.0, 0.75)
            tcod.console_flush()
            time_elapsed += tcod.sys_get_last_frame_length()


        # delete tcod console we created
        tcod.console_delete(con)

        #reset the ball
        self.ball = Ball(1, 1)

        #reset the player positions
        for player in self.players:
            player.top = self.height / 2

        # wipe the conway simulation (by creating a new one)
        self.init_map(self.conway.size, self.conway.color)
Exemple #12
0
	def reset_game(self):
		global savefiles, current_map, border_maps, old_maps, turns, old_msg, hp_anim, times_saved, draw_gui, draw_map, fov_recompute, wm
		savefiles = [f for f in os.listdir('saves') if os.path.isfile(os.path.join('saves', f))]
		current_map = None
		border_maps = [0] * 8
		old_maps = []
		turns = 0
		old_msg = 0
		hp_anim = []
		times_saved = 0
		draw_gui = True
		draw_map = True
		fov_recompute = True
		if 'wm' in globals():
			libtcod.console_delete(wm)
		libtcod.console_clear(con)
Exemple #13
0
def display_help():
	help_menu_console = libtcod.console_new(80, 50)
	
	while True:
		for line, text in enumerate(HELP_TEXT):
			parsed_text, parse_data = parse_colors(text)
			libtcod.console_print_left(help_menu_console, 0, line, libtcod.BKGND_NONE, parsed_text%parse_data)
		
		libtcod.console_blit(help_menu_console, 0, 0, 80, 50, 0, 0, 0)
		libtcod.console_flush()
		
		key = libtcod.console_wait_for_keypress(True)
		if key.vk == libtcod.KEY_ESCAPE or key.c == ord('?'):
			break
	
	libtcod.console_delete(help_menu_console)
Exemple #14
0
    def export(self):

        print("Exporting world map with dimensions [" + str(self.width) + ',' +
              str(self.height) + ']')
        con = tcod.console_new(self.width, self.height)

        con = self.render(con, True)

        bmp = tcod.image_from_console(con)
        tcod.console_delete(con)

        date = datetime.datetime.now()
        timestamp = date.strftime("%Y%m%d-%H%M%S")

        tcod.image_save(bmp, 'export/WorldMap' + timestamp + '.png')
        print "Done."
 def export(self):
     
     print("Exporting world map with dimensions [" + 
             str(self.width) + ',' + str(self.height) + ']');
     con = tcod.console_new(self.width, self.height);
     
     con = self.render(con, True)
     
     bmp = tcod.image_from_console(con)
     tcod.console_delete(con)
     
     date = datetime.datetime.now()
     timestamp = date.strftime("%Y%m%d-%H%M%S")
     
     tcod.image_save(bmp, 'export/WorldMap'+ timestamp + '.png')
     print "Done."
Exemple #16
0
    def resize(self, width=None, height=None):
        """ Resize a console by destroying and recreating it """
        if self.console_id == self.ROOT_ID:
            raise AttributeError("The root console cannot be resized!")
        if width is None:
            width = self.width
        if height is None:
            height = self.height

        if self.height == height and self.width == width:
            return # No resize needed.

        libtcod.console_delete(self.console_id)
        self.console_id = libtcod.console_new(width, height)
        self.width = width
        self.height = height
Exemple #17
0
def session_console():
    libtcodpy.console_set_custom_font(FONT_FILE)
    console = libtcodpy.console_init_root(WIDTH, HEIGHT, TITLE, FULLSCREEN, RENDERER)

    assert libtcodpy.console_get_width(console) == WIDTH
    assert libtcodpy.console_get_height(console) == HEIGHT
    assert libtcodpy.console_is_fullscreen() == FULLSCREEN
    libtcodpy.console_set_window_title(TITLE)
    assert not libtcodpy.console_is_window_closed()

    libtcodpy.sys_get_current_resolution()
    libtcodpy.sys_get_char_size()
    libtcodpy.sys_set_renderer(RENDERER)
    libtcodpy.sys_get_renderer()

    yield console
    libtcodpy.console_delete(console)
Exemple #18
0
def rectangle(con, x, y, w, h, border):

    con_box = libtcod.console_new(w, h)

    b = border
    ch_hw = CH_HW[b]
    ch_vw = CH_VW[b]
    ch_tlc = CH_TLC[b]
    ch_trc = CH_TRC[b]
    ch_brc = CH_BRC[b]
    ch_blc = CH_BLC[b]

    # sides
    for i in range(w - 2):
        libtcod.console_put_char_ex(con_box, i + 1, 0, ch_hw, COL['white'],
                                    COL['black'])
    for i in range(w - 2):
        libtcod.console_put_char_ex(con_box, i + 1, h - 1, ch_hw, COL['white'],
                                    COL['black'])
    for i in range(h - 2):
        libtcod.console_put_char_ex(con_box, 0, i + 1, ch_vw, COL['white'],
                                    COL['black'])
    for i in range(h - 2):
        libtcod.console_put_char_ex(con_box, w - 1, i + 1, ch_vw, COL['white'],
                                    COL['black'])
    # corners
    libtcod.console_put_char_ex(con_box, 0, 0, ch_tlc, COL['white'],
                                COL['black'])
    libtcod.console_put_char_ex(con_box, w - 1, 0, ch_trc, COL['white'],
                                COL['black'])
    libtcod.console_put_char_ex(con_box, 0, h - 1, ch_blc, COL['white'],
                                COL['black'])
    libtcod.console_put_char_ex(con_box, w - 1, h - 1, ch_brc, COL['white'],
                                COL['black'])

    # blit
    libtcod.console_blit(
        con_box,
        0,
        0,
        w,
        h,  # Source
        con,
        x,
        y)  # Destination
    libtcod.console_delete(con_box)
Exemple #19
0
    def hover(self):
        width = len(max(self.text + self.header, key=len)) + (self.xoffset * 2)

        if self.header == []:   header_height = 0
        else:                   header_height = len(self.header) + 2

        height = len(self.text) + header_height + self.yoffset + self.hoffset


        wpanel = GuiPanel(width=width, height=height, xoff=0, yoff=0, interface=self.interface, is_root=0, append_to_panels=0)

        # Header
        libtcod.console_set_default_foreground(wpanel.con, self.textc)
        y = self.yoffset
        for line in self.header:
            libtcod.console_print(wpanel.con, self.xoffset, y, line)
            y += 1

        # Text
        y = header_height + self.hoffset
        for line in self.text:
            #color_current = self.textc
            libtcod.console_print(wpanel.con, self.xoffset, y, line)
            y += 1

        # Draw box around menu if parameter is selected
        if self.bcolor is not None:
            wpanel.draw_box(0, width - 1, 0, height - 1, self.textc)


        if not self.xy_corner:
            # center to coords. Fix for hanging over the left side of the screen and the top of the screen, not yet fixed for right/bottom side.
            x = max(0, int(self.cx - int(width/2) ))
            y = max(0, self.cy - height)
        else:
            x, y = self.cx, self.cy
        # Blit to root console + flush to present changes
        libtcod.console_blit(wpanel.con, 0, 0, width, height, 0, x, y, 1.0, self.transp)
        #libtcod.console_flush()
        libtcod.console_delete(wpanel.con)

        if not self.do_hover:
            self.interface.clear_hover_info()
Exemple #20
0
def box(header, footer, startx, starty, width, height, contents, default=0, input=True, color=libtcod.green, align=libtcod.LEFT, nokeypress=False, inv=False, step=1, mouse_exit=False, scrollbar=True):
	box = libtcod.console_new(width, height)
	if startx == 'center_screenx':
		startx = (game.SCREEN_WIDTH - (len(max(contents, key=len)) + 16)) / 2
	if startx == 'center_mapx':
		startx = game.PLAYER_STATS_WIDTH + ((game.MAP_WIDTH - (width - 4)) / 2)
	if starty == 'center_screeny':
		starty = (game.SCREEN_HEIGHT - (len(contents) + 4)) / 2
	if starty == 'center_mapy':
		starty = ((game.MAP_HEIGHT + 2) - height) / 2
	if color is not None:
		box_gui(box, 0, 0, width, height, color)
	if header is not None:
		libtcod.console_set_default_foreground(box, libtcod.black)
		libtcod.console_set_default_background(box, color)
		libtcod.console_print_ex(box, width / 2, 0, libtcod.BKGND_SET, libtcod.CENTER, ' ' + header + ' ')
	libtcod.console_set_default_foreground(box, color)
	libtcod.console_set_default_background(box, libtcod.black)
	if footer is not None:
		libtcod.console_print_ex(box, width / 2, height - 1, libtcod.BKGND_SET, libtcod.CENTER, '[ ' + footer + ' ]')
	if mouse_exit:
		libtcod.console_print_ex(box, width - 5, 0, libtcod.BKGND_SET, libtcod.LEFT, '[x]')
	libtcod.console_set_default_foreground(box, libtcod.white)

	if input:
		choice = box_options(box, startx, starty, width - 2, height - 2, contents, default, inv, step, mouse_exit, align, scrollbar)
	else:
		for i, line in enumerate(contents):
			if align == libtcod.LEFT:
				libtcod.console_print_ex(box, 2, 2 + i, libtcod.BKGND_SET, libtcod.LEFT, line)
			if align == libtcod.RIGHT:
				libtcod.console_print_ex(box, width - 2, 2 + i, libtcod.BKGND_SET, libtcod.RIGHT, line)
			if align == libtcod.CENTER:
				libtcod.console_print_ex(box, width / 2, 2 + i, libtcod.BKGND_SET, libtcod.CENTER, line)
		libtcod.console_blit(box, 0, 0, width, height, 0, startx, starty, 1.0, 0.9)
		libtcod.console_flush()
		if not nokeypress:
			libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, libtcod.Key(), libtcod.Mouse(), True)
		choice = default
	libtcod.console_delete(box)
	return choice
Exemple #21
0
	def menu(self, header, options, width, back_color=libtcod.black, fore_color=libtcod.white):

		if self.con is None: self.con = 0
		if len(options) > 26: raise ValueError('too many items')

		con = self.con

		header_height = libtcod.console_get_height_rect(con, 0,0, width, self.SCREEN_HEIGHT, header)
		height = len(options) + header_height
		window = libtcod.console_new(width, height)
		print 'window id is:', window
		print

		libtcod.console_set_default_foreground(window, fore_color)
		libtcod.console_print_rect(window, 0,0, width,height, header)

		y = header_height
		for option_text in zip('abcdefghijklmnopqrstuvwxyz', options):
			text = '(%s) %s' % option_text
			libtcod.console_print(window, 0, y, text)
			y += 1

		x = self.SCREEN_WIDTH/2 - width/2
		y = self.SCREEN_HEIGHT/2 - height/2
		libtcod.console_blit(window, 0,0, width,height, 0, x,y, 1.0, 0.9)

		key = libtcod.Key()
		mouse = libtcod.Mouse()
		libtcod.console_flush()
		libtcod.sys_wait_for_event(libtcod.KEY_PRESSED, key, mouse, True)

		libtcod.console_clear(window)
		libtcod.console_blit(window, 0,0, width,height, 0, x,y, 1.0, 0.9)
		libtcod.console_delete(window)
		libtcod.console_flush()

		index = key.c - ord('a')
		if index >= 0 and index < len(options): return index
		return None
Exemple #22
0
def see_message_history():
	box_width = game.MESSAGE_WIDTH + 2
	box_height = (game.SCREEN_HEIGHT / 2) + 4
	box = libtcod.console_new(box_width, box_height)
	game.messages.box_gui(box, 0, 0, box_width, box_height, libtcod.green)
	libtcod.console_set_default_foreground(box, libtcod.black)
	libtcod.console_set_default_background(box, libtcod.green)
	libtcod.console_print_ex(box, box_width / 2, 0, libtcod.BKGND_SET, libtcod.CENTER, ' Message History ')
	libtcod.console_set_default_foreground(box, libtcod.green)
	libtcod.console_set_default_background(box, libtcod.black)
	libtcod.console_print_ex(box, box_width / 2, box_height - 1, libtcod.BKGND_SET, libtcod.CENTER, ' Arrow keys - Scroll up/down, ESC - exit ')
	libtcod.console_set_default_foreground(box, libtcod.white)

	scroll = 0
	exit = False
	key = libtcod.Key()
	while exit is False:
		libtcod.console_rect(box, 1, 1, box_width - 2, box_height - 2, True, libtcod.BKGND_SET)
		for i in range(min(box_height - 4, len(game.message.history))):
			libtcod.console_set_default_foreground(box, game.message.history[i + scroll][1])
			libtcod.console_print(box, 2, i + 2, game.message.history[i + scroll][0])
		util.scrollbar(box, box_width - 2, 2, scroll, box_height - 4, len(game.message.history))
		libtcod.console_blit(box, 0, 0, box_width, box_height, 0, (game.SCREEN_WIDTH - box_width) / 2, (game.MAP_HEIGHT - box_height + 2) / 2, 1.0, 1.0)
		libtcod.console_flush()
		ev = libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse())
		if ev == libtcod.EVENT_KEY_PRESS:
			if key.vk == libtcod.KEY_ESCAPE:
				exit = True
			elif key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
				if scroll > 0:
					scroll -= 1
			elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
				if box_height - 4 + scroll < len(game.message.history):
					scroll += 1
	libtcod.console_delete(box)
	game.draw_gui = True
Exemple #23
0
def character_sheet(screen=0):
	width, height = 62, 21
	pick_skill, modify_skill = 0, 0
	exit = False
	key = libtcod.Key()
	stats = libtcod.console_new(width, height)
	pool = game.player.skill_points

	while exit is False:
		if screen == 0:
			character_sheet_attributes(stats, width, height)
		elif screen == 1:
			pool = character_sheet_skills(stats, width, height, pick_skill, modify_skill, pool)
		elif screen == 2:
			character_sheet_equipment(stats, width, height)
		elif screen == 3:
			character_sheet_inventory(stats, width, height)
		modify_skill = 0

		libtcod.console_set_default_foreground(stats, libtcod.black)
		libtcod.console_set_default_background(stats, libtcod.green)
		libtcod.console_print_ex(stats, width / 2, height - 1, libtcod.BKGND_SET, libtcod.CENTER, ' [ Arrow keys to change page, +/- to change skill pts ] ')
		libtcod.console_blit(stats, 0, 0, width, height, 0, ((game.MAP_WIDTH - width) / 2) + game.MAP_X, ((game.MAP_HEIGHT - height) / 2) + 1, 1.0, 1.0)
		libtcod.console_flush()
		libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, game.mouse, True)
		key_char = chr(key.c)
		if screen == 1:
			if key.vk == libtcod.KEY_UP:
				pick_skill -= 1
				if pick_skill < 1:
					pick_skill = 1
			elif key.vk == libtcod.KEY_DOWN:
				pick_skill += 1
				if pick_skill > len(game.player.skills):
					pick_skill = len(game.player.skills)
			elif key_char == '+':
				if pick_skill in range(1, len(game.player.skills)) and pool > 0:
					modify_skill = 1
			elif key_char == '-':
				if pick_skill in range(1, len(game.player.skills)) and (pool > 0 or (pool == 0 and game.player.skill_points > 0)):
					modify_skill = -1

		if key.vk == libtcod.KEY_LEFT:
			screen -= 1
			if screen < 0:
				screen = 3
		elif key.vk == libtcod.KEY_RIGHT:
			screen += 1
			if screen > 3:
				screen = 0
		elif key.vk == libtcod.KEY_ESCAPE:
			exit = True

	for i in range(len(game.player.skills)):
		if game.player.skills[i].temp > 0:
			game.player.skill_points -= game.player.skills[i].temp
			game.player.skills[i].base_level += game.player.skills[i].temp
			game.player.skills[i].level += game.player.skills[i].temp
			game.player.skills[i].temp = 0
	libtcod.console_delete(stats)
	game.draw_gui = True
Exemple #24
0
def exit_game() -> bool:
    # TODO save etc
    libtcod.console_delete(0)
    return True
Exemple #25
0
 def console_remove_console(self,con):
     if con > 1:  # so we dont try to delete root, or index oob error
         c = self.mConsole.pop(con-1)
         libtcod.console_delete(c)
Exemple #26
0
 def close(self):
     if self.console_id != self.ROOT_ID: # Root console cannot be console_delete()d
         libtcod.console_delete(self.console_id)
Exemple #27
0
 def redraw(self, w, h):
     libtcod.console_delete(self.console)
     self.w = w
     self.h = h
     self.create_console()
Exemple #28
0
                  xp_loader.transparent_cell_back_g,
                  xp_loader.transparent_cell_back_b))

####################
# libtcod piping to actually put the console layers on screen. This will probably change quite a bit for your actual usage of libtcod
####################

draw_layers = False

while not libtcod.console_is_window_closed():

    key = libtcod.console_check_for_keypress()
    if key.vk == libtcod.KEY_ESCAPE:
        break  #exit game

    if key.c == ord('a'):
        draw_layers = not draw_layers

    libtcod.console_clear(0)
    libtcod.console_blit(layer_0_console, 0, 0,
                         xp_data['layer_data'][0]['width'],
                         xp_data['layer_data'][0]['height'], 0, 0, 0)

    if draw_layers:
        libtcod.console_blit(layer_1_console, 0, 0,
                             xp_data['layer_data'][1]['width'],
                             xp_data['layer_data'][1]['height'], 0, 0, 0)
    libtcod.console_flush()

libtcod.console_delete(layer_0_console)
libtcod.console_delete(layer_1_console)
Exemple #29
0
 def delete_panel(self, panel):
     self.gui_panels.remove(panel)
     libtcod.console_delete(panel.con)
     self.panel_deletions.remove(panel)
     self.game.handle_fov_recompute()
Exemple #30
0
def create_character():
	cancel = False
	cs_width = 55
	cs_height = game.SCREEN_HEIGHT - 4
	cs = libtcod.console_new(cs_width, cs_height)
	stats = libtcod.console_new(34, cs_height)
	while not cancel:
		game.messages.box_gui(0, 0, 0, game.SCREEN_WIDTH, game.SCREEN_HEIGHT, color=libtcod.Color(245, 222, 179), lines=[{'dir': 'h', 'x': 0, 'y': 2}, {'dir': 'v', 'x': game.SCREEN_WIDTH - 36, 'y': 2}])
		libtcod.console_set_default_foreground(0, libtcod.white)
		libtcod.console_print_ex(0, game.SCREEN_WIDTH / 2, 1, libtcod.BKGND_NONE, libtcod.CENTER, 'CHARACTER GENERATION')
		show_stats_panel(stats)
		libtcod.console_print(0, 2, 4, 'Enter a name for your character: _')
		libtcod.console_flush()

		game.player.name = game.messages.input('chargen', 0, 35, 4, min=3, max=21)
		show_stats_panel(stats)
		libtcod.console_clear(cs)
		libtcod.console_print(cs, 1, 1, 'Select a gender:')
		libtcod.console_blit(cs, 0, 0, cs_width, cs_height, 0, 1, 3)
		game.player.gender = game.GENDER[chargen_options(2, 6, 10, game.GENDER, None)]

		show_stats_panel(stats)
		libtcod.console_clear(cs)
		libtcod.console_print(cs, 1, 1, 'Select a race:')
		libtcod.console_print(cs, 16, 2, 'Modifiers')
		libtcod.console_print(cs, 16, 3, 'None')
		libtcod.console_print(cs, 16, 4, '+2 Int, +1 Wis, -2 Str, -1 End')
		libtcod.console_print(cs, 16, 5, '+2 Str, +3 End, -2 Dex, -2 Int, -1 Wis')
		libtcod.console_print(cs, 16, 6, '+1 Dex, +1 Int, -1 Str, -1 Wis')
		libtcod.console_blit(cs, 0, 0, cs_width, cs_height, 0, 1, 3)
		game.player.race = game.RACES[chargen_options(2, 6, 12, game.RACES, 'race')]

		show_stats_panel(stats, 0)
		libtcod.console_clear(cs)
		libtcod.console_print(cs, 1, 1, 'Select a class:')
		libtcod.console_print(cs, 16, 2, 'Modifiers')
		libtcod.console_print(cs, 16, 3, '+3 Str, +2 End, -2 Int, -1 Wis')
		libtcod.console_print(cs, 16, 4, '+3 Dex, +1 Str, -1 Int, -1 End')
		libtcod.console_print(cs, 16, 5, '+3 Wis, +1 Str, -1 Dex, -1 End')
		libtcod.console_print(cs, 16, 6, '+4 Int, +1 Wis, -2 Str, -1 End')
		libtcod.console_print(cs, 16, 7, 'None')
		libtcod.console_blit(cs, 0, 0, cs_width, cs_height, 0, 1, 3)
		game.player.profession = game.CLASSES[chargen_options(2, 6, 12, game.CLASSES, 'class')]

		show_stats_panel(stats, 0, 0)
		libtcod.console_clear(cs)
		libtcod.console_print(cs, 1, 1, 'Options:')
		libtcod.console_blit(cs, 0, 0, cs_width, cs_height, 0, 1, 3)
		final_choice = False
		while not final_choice:
			choice = chargen_options(2, 6, 33, ['Reroll stats', 'Keep character and start game', 'Cancel and restart', 'Return to main menu'], None)
			if choice == 0:
				show_stats_panel(stats, 0, 0)
			if choice == 1:
				final_choice = True
				libtcod.console_delete(cs)
				libtcod.console_delete(stats)
				return 'playing'
			if choice == 2:
				game.player.name = ''
				game.player.gender = ''
				game.player.race = ''
				game.player.profession = ''
				final_choice = True
			if choice == 3:
				final_choice = True
				libtcod.console_delete(cs)
				libtcod.console_delete(stats)
				return 'quit'
Exemple #31
0

####################
# libtcod piping to actually put the console layers on screen. This will probably change quite a bit for your actual usage of libtcod
####################

draw_layers = False

while not libtcod.console_is_window_closed():

    key = libtcod.console_check_for_keypress()
    if key.vk == libtcod.KEY_ESCAPE:
        break  # exit game

    if key.c == ord("a"):
        draw_layers = not draw_layers

    libtcod.console_clear(0)
    libtcod.console_blit(
        layer_0_console, 0, 0, xp_data["layer_data"][0]["width"], xp_data["layer_data"][0]["height"], 0, 0, 0
    )

    if draw_layers:
        libtcod.console_blit(
            layer_1_console, 0, 0, xp_data["layer_data"][1]["width"], xp_data["layer_data"][1]["height"], 0, 0, 0
        )
    libtcod.console_flush()

libtcod.console_delete(layer_0_console)
libtcod.console_delete(layer_1_console)
Exemple #32
0
def display_message_log(player):
	message_log_console = libtcod.console_new(80, 40)
	
	start_on_line = 0
	focus = 0
	n_messages = len(player.message_log)
	
	while True:
		# draw the log
		libtcod.console_clear(message_log_console)
		
		libtcod.console_set_foreground_color(message_log_console, libtcod.white)
		libtcod.console_print_center(message_log_console, 40, 1, libtcod.BKGND_NONE, 'Message Log')
		
		offset = 3
		line_n = 0
		
		focus_age = player.message_log[focus].age
		focus_drawn = False
		
		try:
			for n, message in enumerate(player.message_log):
				for line, text in enumerate(wrap_text(message.text, 75, subsequent_indent = ' ')):
					if line_n < start_on_line:
						line_n += 1
						
						if n == focus:
							raise FocusAboveScreen()
						
						continue
					
					if message.age == focus_age:
						shade = 1
					
					else:
						shade = 0.5
					
					libtcod.console_set_foreground_color(message_log_console, libtcod.white * shade)
					
					if line == 0:
						
						if n == focus:
							libtcod.console_put_char_ex( message_log_console, 0, offset, libtcod.CHAR_ARROW_E, libtcod.white, libtcod.black)
						
						if message.symbol1:
							libtcod.console_put_char_ex( message_log_console, (message.symbol2 is None) and 2 or 1, offset, message.symbol1[0], message.symbol1[1] * shade, message.symbol1[2] * shade )
						
						if message.symbol2:
							libtcod.console_put_char_ex( message_log_console, 2, offset, message.symbol2[0], message.symbol2[1] * shade, message.symbol2[2] * shade )
					
					parsed_text, parse_data = parse_colors(text)
					libtcod.console_print_left(message_log_console, 4, offset, libtcod.BKGND_NONE, parsed_text%parse_data)
					offset += 1
					
					if offset >= 39:
						if focus_drawn:
							raise LogIsFull()
						
						else:
							raise FocusBelowScreen()
				
				if n == focus:
					focus_drawn = True
		
		except LogIsFull:
			pass
		
		except FocusAboveScreen:
			start_on_line = max(0, start_on_line - 35)
			continue
		
		except FocusBelowScreen:
			start_on_line += 35
			continue
		
		libtcod.console_blit(message_log_console, 0, 0, 80, 40, 0, 0, 0)
		
		draw_hud(player)
		
		libtcod.console_flush()
		
		# wait for input
		key = libtcod.console_wait_for_keypress(True)
		
		if key.vk == libtcod.KEY_ESCAPE or key.c == ord('m'):
			break
		
		elif key.vk in DIRECTION_KEYS and DIRECTION_KEYS[key.vk][0] == 0:
			focus += DIRECTION_KEYS[key.vk][1]
			focus %= n_messages
	
	libtcod.console_delete(message_log_console)
 def close(self):
     ##do not inherit
     libtcod.console_delete(self.console)
Exemple #34
0
def msg_clear():
    clr=libtcod.console_new(msgs_w(), msgs_h())
    libtcod.console_blit(clr, 0,0, msgs_w(),msgs_h(),  con_game(), 0,0)
    libtcod.console_delete(clr)
Exemple #35
0
# John Mason, 2012
###############################################################################

import libtcodpy as libtcod

import game
import default_config as config

libtcod.console_set_custom_font('courier12x12_aa_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(80, 50, 'BRUTAL ROGUELIKE: Slaves to Slaughter', False)
libtcod.sys_set_fps(60)

if config.QUICK_START:
	game_state = game.new_game

else:
	game_state = game.start_menu

while True:
	try:
		game_state()
	
	except game.SetState as exception:
		if exception.new_state == 'quit':
			break
		
		else:
			game_state = exception.new_state

libtcod.console_delete(0)
 def close(self):
     super(Manager_Menu, self).close()
     
     libtcod.console_delete(self.con)
     rog.refresh()
Exemple #37
0
def look(player):
	look_console = libtcod.console_new(50, 10)
	
	cursor_x = player.x
	cursor_y = player.y
	
	map = player.map
	memory = player.memory
	
	while True:
		draw_map(player)
		highlight_tile(cursor_x, cursor_y)
		
		can_see = player.fov.is_visible(cursor_x, cursor_y)
		
		actor = can_see and map.actor_at(cursor_x, cursor_y) or memory.actor_at(cursor_x, cursor_y)
		item = can_see and map.item_at(cursor_x, cursor_y) or memory.item_at(cursor_x, cursor_y)
		feature =  can_see and map.feature_at(cursor_x, cursor_y) or memory.feature_at(cursor_x, cursor_y)
		
		libtcod.console_clear(look_console)
		
		if actor or item or feature:
			if can_see:
				libtcod.console_print_left(look_console, 1, 1, libtcod.BKGND_NONE, 'You see:')
			
			else:
				libtcod.console_print_left(look_console, 1, 1, libtcod.BKGND_NONE, 'You recall:')
			
			offset = 0
			
			if actor:
				libtcod.console_put_char_ex(look_console, 1, 3, *clean_symbol(actor))
				libtcod.console_print_left(look_console, 3, 3, libtcod.BKGND_NONE, actor.name)
				
				offset += 1
			
			if item:
				libtcod.console_put_char_ex(look_console, 1, 3 + offset, *clean_symbol(item))
				libtcod.console_print_left(look_console, 3, 3 + offset, libtcod.BKGND_NONE, item.name)
				
				offset += 1
			
			if feature:
				libtcod.console_put_char_ex(look_console, 1, 3 + offset, *clean_symbol(feature))
				libtcod.console_print_left(look_console, 3, 3 + offset, libtcod.BKGND_NONE, feature.name)
		
		else:
			libtcod.console_print_left(look_console, 1, 1, libtcod.BKGND_NONE, 'You cannot see this location.')
			
		libtcod.console_blit(look_console, 0, 0, 50, 10, 0, 30, 40)
		
		libtcod.console_flush()
		
		key = libtcod.console_wait_for_keypress(True)
		
		if key.vk == libtcod.KEY_ESCAPE or key.c == ord('l'):
			break
		
		elif key.vk in DIRECTION_KEYS:
			dx, dy = DIRECTION_KEYS[key.vk]
			cursor_x += dx
			cursor_y += dy
			level = 0
		
		cursor_x %= 80 # mmmm hardcoded
		cursor_y %= 40
	
	libtcod.console_delete(look_console)
 def consoles_delete(self):
     libtcod.console_delete(self.con_mid)
     if self.con_top: libtcod.console_delete(self.con_top)
     if self.con_bot: libtcod.console_delete(self.con_bot)
Exemple #39
0
 def __del__(self):
     dlib.console_delete(self._intern)