Example #1
0
def help_screen():
    T.console_clear(None)
    CON.default_fg = T.light_grey
    for i, line in enumerate(HELP_TEXT.split('\n')):
        CON.print_(1, 1+i, line)
    T.console_flush()
    readkey()
def play_game():
    global key, mouse
 
    player_action = None
 
    mouse = libtcod.Mouse()
    key = libtcod.Key()
    while not libtcod.console_is_window_closed():
        #render the screen
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS|libtcod.EVENT_MOUSE,key,mouse)
        render_all()
 
        libtcod.console_flush()
 
        #level up if needed
        check_level_up()
 
        #erase all objects at their old locations, before they move
        for object in objects:
            object.clear()
 
        #handle keys and exit game if needed
        player_action = handle_keys()
        if player_action == 'exit':
            save_game()
            break
 
        #let monsters take their turn
        if game_state == 'playing' and player_action != 'didnt-take-turn':
            for object in objects:
                if object.ai:
                    object.ai.take_turn()
Example #3
0
def console(session_console):
    console = session_console
    tcod.console_flush()
    console.default_fg = (255, 255, 255)
    console.default_bg = (0, 0, 0)
    console.default_blend = tcod.BKGND_SET
    console.default_alignment = tcod.LEFT
    console.clear()
    return console
Example #4
0
def title_screen():
    T.console_clear(None)
    for i, txt in enumerate(TITLE_SCREEN):
        if isinstance(txt, tuple):
            color, s = txt
            CON.default_fg = color
        else:            
            s = txt
        CON.print_(SCREEN_W//2, i+5, s, alignment=T.CENTER)
    T.console_flush()
    readkey()
def test_sys_custom_render(console):
    if libtcodpy.sys_get_renderer() != libtcodpy.RENDERER_SDL:
        pytest.xfail(reason='Only supports SDL')

    escape = []
    def sdl_callback(sdl_surface):
        escape.append(True)
        libtcodpy.console_set_dirty(0, 0, 0, 0)
    libtcodpy.sys_register_SDL_renderer(sdl_callback)
    libtcodpy.console_flush()
    assert escape, 'proof that sdl_callback was called'
Example #6
0
def message(s, color=T.white):
    s = s[0].upper() + s[1:]
    print(s)
    while len(MESSAGES) > BUFFER_H-1 and \
            MESSAGES[-BUFFER_H][0]:
        m = MESSAGES.pop()
        MESSAGES.append((True, '[more]', T.green))
        _draw_messages()
        T.console_flush()
        readkey()
        MESSAGES.pop()
        new_ui_turn()
        MESSAGES.append(m)

    MESSAGES.append((True, s, color))
    _draw_messages()
    T.console_flush()
def target_tile(max_range=None):
    #return the position of a tile left-clicked in player's FOV (optionally in a range), or (None,None) if right-clicked.
    global key, mouse
    while True:
        #render the screen. this erases the inventory and shows the names of objects under the mouse.
        libtcod.console_flush()
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS|libtcod.EVENT_MOUSE,key,mouse)
        render_all()
        (x, y) = (mouse.cx, mouse.cy)
 
        if mouse.rbutton_pressed or key.vk == libtcod.KEY_ESCAPE:
            return (None, None)  #cancel if the player right-clicked or pressed Escape
 
        #accept the target if the player clicked in FOV, and in case a range is specified, if it's in that range
        if (mouse.lbutton_pressed and libtcod.map_is_in_fov(fov_map, x, y) and
            (max_range is None or player.distance(x, y) <= max_range)):
            return (x, y)
Example #8
0
def look_mode():
    global MESSAGES
    from game import decode_key

    x, y = GAME.player.x, GAME.player.y
    _messages = MESSAGES
    MESSAGES = []
    message('Look mode - use movement keys, ESC/q to exit.', T.green)
    new_ui_turn()
    _draw_messages()
    redraw = True
    while True:
        if redraw:
            T.console_blit(CON_MAP, 0, 0, MAP_W, MAP_H,
                           None, 1, 1)
            c = T.console_get_char(CON_MAP, x, y)
            color = T.console_get_char_foreground(CON_MAP, x, y)

            T.console_put_char_ex(None, x+1, y+1, c,
                                  T.black, color)

            describe_tile(x, y)

            _draw_messages()
            T.console_flush()

            # now clear the message buffer of last messages
            while MESSAGES and MESSAGES[-1][0]:
                MESSAGES.pop()

            redraw = False
        cmd = decode_key(readkey())
        if cmd == 'quit':
            break
        elif isinstance(cmd, tuple):
            name, args = cmd
            if name == 'walk':
                dx, dy = args
                if in_map(x+dx, y+dy):
                    x, y = x+dx, y+dy
                    redraw = True

    MESSAGES = _messages
Example #9
0
def how_to_play(window):
    how_to_play_board = create_how_to_play_screen()
    horizontal_offset = int((ui.SCREEN_WIDTH / 2) -
                            (len(how_to_play_board[0]) / 2))
    vertical_offset = int((ui.SCREEN_HEIGHT / 2) -
                          (len(how_to_play_board) / 2))

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    how_to_play_descr = True
    libtcod.console_clear(window)
    while how_to_play_descr:

        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        for i, line in enumerate(how_to_play_board):
            for j, char in enumerate(line):
                if char in ["'", "`", "-", "\\", "/", "."]:
                    libtcod.console_set_default_foreground(
                        window, libtcod.light_chartreuse)
                else:
                    libtcod.console_set_default_foreground(
                        window, libtcod.white)
                libtcod.console_put_char(window, j + horizontal_offset,
                                         i + vertical_offset, char,
                                         libtcod.BKGND_NONE)
                libtcod.console_blit(window, 0, 0, ui.SCREEN_WIDTH,
                                     ui.SCREEN_HEIGHT, 0, 0, 0)
                libtcod.console_flush()

        action = handle_keys(key)
        back_to_menu = action.get('back')
        fullscreen = action.get('fullscreen')

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

        if back_to_menu:
            how_to_play_descr = False
            libtcod.console_clear(window)
            return -1
Example #10
0
def handle_main_menu_operations(con, main_menu_background_image, constants,
                                show_load_error_message, key, mouse, player,
                                entities, game_map, message_log, game_state,
                                show_main_menu):
    exit_game_break = False
    main_menu(con, main_menu_background_image, constants['screen_width'],
              constants['screen_height'], constants['window_title'], key,
              mouse, game_state)

    if show_load_error_message:
        message_box(con, 'No save game to load', 50, constants['screen_width'],
                    constants['screen_height'])

    libtcod.console_flush()

    options = get_main_menu_options()
    action = handle_main_menu(key, mouse, game_state, options, con, constants,
                              player)

    new_game = action.get(Action.NEW_GAME)
    load_saved_game = action.get(Action.LOAD_GAME)
    exit_game = action.get(Action.EXIT)

    if show_load_error_message and (new_game or load_saved_game or exit_game):
        show_load_error_message = False
    elif new_game:
        reset_game()
        player, entities, game_map, message_log, game_state = get_game_variables(
            constants)
        game_state = GameStates.PLAYERS_TURN

        show_main_menu = False
    elif load_saved_game:
        try:
            player, entities, game_map, message_log, game_state = load_game()
            show_main_menu = False
        except FileNotFoundError:
            show_load_error_message = True
    elif exit_game:
        exit_game_break = True

    return exit_game_break, action, show_load_error_message, player, entities, game_map, message_log, game_state, show_main_menu
Example #11
0
def main():
    screen_width = 80
    screen_height = 50

    player_x = int(screen_width / 2)
    player_y = int(screen_height/ 2)

    libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial', False)

    con = libtcod.console_new(screen_width, screen_height)

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key ,mouse)

        libtcod.console_set_default_foreground(con, libtcod.white)
        libtcod.console_put_char(con, player_x, player_y, '@', libtcod.BKGND_NONE)
        libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
        libtcod.console_flush()
        
        libtcod.console_put_char(con, player_x, player_y, ' ', libtcod.BKGND_NONE)

        action = handle_keys(key)

        move =action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            player_x += dx
            player_y += dy

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
Example #12
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = tcod.console_get_height_rect(con, 0, 0, width,
                                                 SCREEN_HEIGHT, header)

    if header == '':
        header_height = 0

    height = len(options) + header_height + 2

    window = tcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)

    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 1, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

    y = header_height + 1
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letter_index += 1

    x = int(SCREEN_WIDTH / 2 - width / 2)
    y = int(SCREEN_HEIGHT / 2 - height / 2)

    tcod.console_blit(window, 0, 0, width, height, 0, x, y - 3, 1.0, 0.7)

    tcod.console_flush()
    key = tcod.console_wait_for_keypress(True)

    if key.vk == tcod.KEY_ENTER and key.lalt:
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())

    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index

    return None
Example #13
0
def HeightGradMap(
    World,
):  # ------------------------------------------------------------ Print Map (Heightmap Gradient) -------------------------------------------------------------------
    for x in range(WORLD_WIDTH):
        for y in range(WORLD_HEIGHT):
            hm_v = World[x][y].height
            HeightColor = tcod.Color(255, 255, 255)
            tcod.color_set_hsv(
                HeightColor, 0, 0, hm_v
            )  # Set lightness to hm_v so higher heightmap value -> "whiter"
            tcod.console_put_char_ex(
                0,
                x,
                y + SCREEN_HEIGHT / 2 - WORLD_HEIGHT / 2,
                "\333",
                HeightColor,
                tcod.black,
            )
    tcod.console_flush()
    return
Example #14
0
def target_tile(max_range=None):
    global key, mouse
    #return the position of a tile left-clicked in player's FOV (optionally in a range), or (None,None) if right-clicked.
    while True:
        #render the screen. this erases the inventory and shows the names of objects under the mouse.
        libtcod.console_flush()
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
        render_all()

        (x, y) = (mouse.cx, mouse.cy)

        if mouse.rbutton_pressed or key.vk == libtcod.KEY_ESCAPE:
            return (None, None
                    )  #cancel if the player right-clicked or pressed Escape

        #accept the target if the player clicked in FOV, and in case a range is specified, if it's in that range
        if (mouse.lbutton_pressed and libtcod.map_is_in_fov(fov_map, x, y)
                and (max_range is None or player.distance(x, y) <= max_range)):
            return (x, y)
Example #15
0
def main():
    screen_width = 80
    screen_height = 50
    map_width = 80
    map_height = 45
    player = Entity(int(screen_width/2), int(screen_height/2), '@', libtcod.white)
    npc = Entity(int(screen_width/2 - 5), int(screen_height/2), '@', libtcod.yellow)
    entities = [npc, player]
    key = libtcod.Key()
    mouse = libtcod.Mouse()

    libtcod.console_set_custom_font('arial10X10.png', libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial revised', False)

    con = libtcod.console_new(screen_width,screen_height)

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        render_all(con, entities, screen_width, screen_height)

        libtcod.console_flush()

        clear_all(con, entities)

        action = handle_keys(key)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            player.move(dx,dy)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
Example #16
0
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')
 
    #calculate total height for the header (after auto-wrap) and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height
 
    #create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height)
 
    #print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
 
    #print all the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
        y += 1
        letter_index += 1
 
    #blit the contents of "window" to the root console
    x = SCREEN_WIDTH//2 - width//2
    y = SCREEN_HEIGHT//2 - height//2
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
 
    #present the root console to the player and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:  #(special case) Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    #convert the ASCII code to an index; if it corresponds to an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Example #17
0
def _main():
    """An example program for when this module is run directly."""
    WIDTH, HEIGHT = 120, 60
    TITLE = 'sdlevent.py engine'

    with tcod.console_init_root(WIDTH, HEIGHT, TITLE, order='F') as console:
        tcod.sys_set_fps(24)
        while True:
            for event in wait():
                print(event)
                if event.type == 'QUIT':
                    raise SystemExit()
                elif event.type == 'MOUSEMOTION':
                    console.ch[:,-1] = 0
                    console.print_(0, HEIGHT - 1, repr(event))
                else:
                    console.blit(console, 0, 0, 0, 1, WIDTH, HEIGHT - 2)
                    console.ch[:,-3] = 0
                    console.print_(0, HEIGHT - 3, repr(event))

            tcod.console_flush()
Example #18
0
    def run(self):
        tcod.console_flush()
        for tick in itertools.count():
            if self.gen:
                done = self.gen.run_tick()
                if not tick % TICKS_PER_FRAME:
                    self.gen.draw(self.root)
                    tcod.console_flush()
                    if self.animate:
                        self.save_screenshot()

                    self.handle_input()
                if done:
                    ct = time.time() - self.start_time
                    print(f'Completed in {ct:0.2f} seconds')
                    self.gen = None
            else:
                self.handle_input(True)

            if not self.running:
                break
Example #19
0
def main():
	if len(sys.argv) > 1:
		randomseed = int(sys.argv[1])
		seed(randomseed)

	global draw_offset_x
	global draw_offset_y

	p1 = NoiseGrid(size=64, precision=4)
	p2 = NoiseGrid(size=64, precision=4)
	p3 = NoiseGrid(size=64, precision=4)
	noisegrids = [p1, p2, p3]

	libtcod.console_set_custom_font('arial10x10.png', 
		libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
	root = libtcod.console_init_root(screen_width, screen_height, 
			'world gen', False, 
			libtcod.RENDERER_SDL2, vsync=True)
	con = libtcod.console.Console(screen_width, screen_height)
	printbiome = ''

	world = WorldMap(map_width, map_height)
	region = None
	adjregions = {}
	draw_offset_x = (int)((screen_width - map_width) / 2)
	draw_offset_y = (int)((screen_height - map_height) / 2)
	printworld(root, con, world)
	libtcod.console_flush()

	viewstate = ViewState.WORLD

	while True:
		for event in tcod.event.wait():
			if event.type == "QUIT":
				raise SystemExit()
	
		# print canvas
		con.clear()
		#printUI(con, world, region, viewstate)
		libtcod.console_flush()
Example #20
0
def main():

    global map
    global fov_map
    global EXPLORE_MODE

    tcod.console_set_custom_font(
        '/Users/adun/Desktop/RoguelikeTutorial/arial10x10.png',
        tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)

    tcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_TITLE,
                           FULL_SCREEN)

    tcod.sys_set_fps(LIMIT_FPS)

    make_map()

    fov_map = tcod.map_new(MAP_WIDTH, MAP_HEIGHT)
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            tcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight,
                                    not map[x][y].blocked)

    while not tcod.console_is_window_closed():

        if EXPLORE_MODE:

            render_all2()
        else:
            render_all()

        tcod.console_flush()

        # erase all objects at their old locations, before they move
        for object in objects:
            object.clear()

        player_action = handle_keys()
        if player_action == 'exit':
            break
Example #21
0
    def render_menu(self, header, options, width):
        header_height = self.owner.console.get_height_rect(
            0, 0, width, config.SCREEN_HEIGHT, header)
        height = len(options) + header_height

        window = tcod.console.Console(width, height)

        window.default_fg = tcod.white
        window.print_rect(0,
                          0,
                          width,
                          height,
                          string=header,
                          bg_blend=tcod.BKGND_NONE,
                          alignment=tcod.LEFT)
        y = header_height
        letter_index = ord('a')
        for option_text in options:
            text = '(' + chr(letter_index) + ') ' + option_text
            window.print(0,
                         y,
                         string=text,
                         bg_blend=tcod.BKGND_SET,
                         alignment=tcod.LEFT)
            y += 1
            letter_index += 1

        x = int(config.SCREEN_WIDTH / 2 - width / 2)
        y = int(config.SCREEN_HEIGHT / 2 - height / 2)
        window.blit(self.owner.root_console,
                    dest_x=x,
                    dest_y=y,
                    src_x=0,
                    src_y=0,
                    width=width,
                    height=height,
                    fg_alpha=1.0,
                    bg_alpha=0.7)
        tcod.console_flush()
        tcod.console_wait_for_keypress(True)
Example #22
0
    def _render_main_menu(self, app):
        current_menu = None
        if app.game and app.game.current_menu:
            current_menu = app.game.current_menu
        elif app.current_menu:
            current_menu = app.current_menu

        if current_menu:
            if current_menu.type == MenuType.GRAPHIC:
                self._main_menu(self.app_window, current_menu,
                                self.screen_width, self.screen_height)
            elif current_menu.type == MenuType.STANDARD:
                self._menu(
                    self.app_window,
                    current_menu,
                    int(self.screen_width / 1.5),
                    self.screen_width,
                    self.screen_height,
                )

        libtcod.console_flush()
        libtcod.console_clear(self.app_window)
Example #23
0
def play_game():
    global key, mouse
    player_action = None
    mouse = libtcod.Mouse()
    key = libtcod.Key()
    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
        render_all()
        libtcod.console_flush()
        check_level_up()
        for object in objects:
            object.clear()
    #handle keys and exit game if needed
        player_action = handle_keys()
        if player_action == 'exit':
            save_game()
            break
        if game_state == 'playing' and player_action != 'didnt-take-turn':
            for object in objects:
                if object.ai:
                    object.ai.take_turn()
Example #24
0
File: main.py Project: Jipes/TYRMA
def message(new_msg, color = libtcod.white,x=None,y=None):
    #split the message if necessary, among multiple lines
    if x==None or libtcod.map_is_in_fov(fov_map, x, y):
        new_msg_lines = textwrap.wrap(new_msg, MSG_WIDTH)

        for line in new_msg_lines:
            #if the buffer is full, remove the first line to make room for the new one
            if len(game_msgs) == MSG_HEIGHT:
                del game_msgs[0]

            #add the new line as a tuple, with the text and the color
            game_msgs.append( (line, color) )
            y = 1
            libtcod.console_set_default_background(panel, libtcod.black)
            libtcod.console_clear(panel)
            render_all()
            for (line, color) in game_msgs:
                libtcod.console_set_default_foreground(panel, color)
                libtcod.console_print_ex(panel, MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line)
                y += 1
            libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
            libtcod.console_flush()
Example #25
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError("Can't have more than 26 options in popup menu")
    fmt = "\n".join([header.center(width)+"\n"] +
                    options +
                    ["\n" + "--- press space to continue ---".center(width)])
    height = len(fmt.splitlines()) + 3
    popup = tcod.console_new(width, height)
    tcod.console_set_default_background(popup, (0, 0, 20))
    tcod.console_clear(popup)
    tcod.console_print_rect(popup, 1, 1, width+2, height+2, fmt=fmt)
    tcod.console_blit(src=popup, x=0, y=0,
                      w=width+2, h=height,
                      dst=root,
                      xdst=SCREEN_WIDTH//2-width//2,
                      ydst= 0, # SCREEN_HEIGHT//2-height//2,
                      ffade=1.0, bfade=0.8)
    tcod.console_flush()
    key = tcod.console_wait_for_keypress(flush=True)
    while key.c != 32:  # Space
        key = tcod.console_wait_for_keypress(flush=True)
    tcod.console_clear(popup)
Example #26
0
def main():
	screen_width = 80
	screen_height = 50
	

	font_path = 'arial10x10.png'
	font_flags = tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD
	tcod.console_set_custom_font(font_path, font_flags)

	window_title = "tenrl"
	fullscreen = False
	tcod.console_init_root(screen_width, screen_height, window_title, fullscreen)

	while not tcod.console_is_window_closed():
		tcod.console_set_default_foreground(0, tcod.white)
		tcod.console_put_char(0, 1, 1, '@', tcod.BKGND_NONE)
		tcod.console_flush()
		
		key = tcod.console_check_for_keypress()
		
		if key.vk == tcod.KEY_ESCAPE:
			return True
Example #27
0
    def update(self):
        self.root.clear()

        if self.container.input_mode is not GameState.TITLE_SCREEN:
            self.map_panel.update()
            self.message_panel.update()
            self.preview_panel.update()
            self.delay_panel.update()

        if self.container.input_mode is GameState.STATUS_VIEW:
            self.stat_panel.update()

        if self.container.input_mode is GameState.STATUS_USE:
            self.stat_panel.update()

        if self.container.input_mode is GameState.STATUS_DROP:
            self.stat_panel.update()

        if self.container.input_mode is GameState.TITLE_SCREEN:
            self.title_screen.update()

        tcod.console_flush()
Example #28
0
def rendering_proc(player,
                   entities,
                   game_map,
                   message_log,
                   game_state,
                   con,
                   panel,
                   constants,
                   fov_map,
                   mouse,
                   fov_recompute=False):
    if fov_recompute:
        recompute_fov(fov_map, player.x, player.y, constants['fov_radius'],
                      constants['fov_light_walls'], constants['fov_algorithm'])
    render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, constants['screen_width'],
               constants['screen_height'], constants['bar_width'],
               constants['panel_height'], constants['panel_y'],
               constants['colors'], game_state, mouse)
    fov_recompute = False
    libtcod.console_flush()
    clear_all(con, entities)
Example #29
0
    def update(self):

        self.flush = False

        if self.cursor.blink():
            self.redraw_cursor = True

        if self.render_text:
            self.update_render_text()
            self.redraw_cursor = True

        if self.redraw_cursor:
            self.cursor.draw()
            self.flush = True

        if self.flush:
            libtcod.console_flush()

        #now we've updated, turn all update variables to False
        self.redraw_cursor = False
        self.render_text = False
        self.flush = False
Example #30
0
def main():
    screen_width = 80
    screen_height = 80

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(screen_width,
                              screen_height,
                              'Image',
                              fullscreen=False)
    con = libtcod.console_new(screen_width, screen_height)

    n = 20
    backgr = 0.7
    im = Image.open(
        'D:\\(un)important\\python\\3year\\project\\other\\test4.png')

    rgbim = im.convert('RGB')
    rgbim.thumbnail((n, n), Image.ANTIALIAS)

    for x in range(rgbim.size[0]):
        for y in range(rgbim.size[1]):
            r, g, b = rgbim.getpixel((x, y))
            backcolor = libtcod.Color(int(r * backgr), int(g * backgr),
                                      int(b * backgr))
            libtcod.console_set_char_background(con, x, y, backcolor,
                                                libtcod.BKGND_SET)
            ch = get_char(x, y, rgbim)
            libtcod.console_set_default_foreground(
                con, libtcod.Color(int(r), int(g), int(b)))
            libtcod.console_put_char(con, x, y, ch, libtcod.BKGND_NONE)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
    libtcod.console_flush()

    key = libtcod.Key()
    mouse = libtcod.Mouse()
    libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, mouse, True)
Example #31
0
def main():
    # I don't like a bunch of var at the start of every file and/or class - so every long living var
    # well be defined within the config folder - grouped by dev who will return an list with the necessessary  values
    constants = get_window_constants()

    # FONT loading for the tile-set
    tcod.console_set_custom_font(constants['font_file'],
                                 constants['font_flags'],
                                 constants['char_horiz'],
                                 constants['char_vertic'])

    # main window
    console = tcod.console_init_root(
        constants['screen_width'], constants['screen_height'],
        constants['window_title'], constants['run_in_full_screen'],
        constants['renderer'], constants['render_order'],
        constants['render_vsync'])

    # Key and mouse-events handling
    state = State()
    credits_end = False

    # the main game loop
    while not tcod.event == tcod.event.Quit:
        # clear everything
        console.clear()
        # Honour to whom honour is due
        if not credits_end:
            credits_end = tcod.console_credits_render(
                constants['credit_x_pos'], constants['credit_y_pos'],
                constants['credit_alpha_enabled'])

        # Key, mouse and other events
        for event in tcod.event.get():
            state.dispatch(event)

        # bring new painted content to the front
        tcod.console_flush()
Example #32
0
def main():
    """Example program for tcod.event"""
    TITLE = None

    tcod.console_set_custom_font(
        "potash_10x10.png",
        tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_ASCII_INROW)

    generate_quadrants()

    with tcod.console_init_root(
            WIDTH,
            HEIGHT,
            TITLE,
            order="F",
            renderer=tcod.RENDERER_SDL2,
            vsync=True,
    ) as console:
        # tcod.sys_set_fps(30)
        pad = np.zeros((HEIGHT * 2, WIDTH * 2, 3), np.uint8)
        dots = [Dot() for _ in range(200)]
        while True:
            pad[...] //= 2
            for dot in dots:
                dot.draw(pad)
                dot.step()

            console.draw_semigraphics(pad)
            console.print(0,
                          HEIGHT - 1,
                          str(tcod.sys_get_fps()),
                          fg=(255, 255, 255),
                          bg=(0, 0, 0))
            tcod.console_flush()
            for event in tcod.event.get():
                if event.type == "QUIT" or (event.type == "KEYDOWN" and
                                            event.sym == tcod.event.K_ESCAPE):
                    raise SystemExit()
Example #33
0
def main():

    libtcod.console_set_custom_font(
        'courier12x12.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    # TODO
    # tcod_test.py:37: DeprecationWarning: A renderer should be given, see the online documentation.
    # libtcod.console_init_root(screen_width, screen_height, 'NecroPlanter', False)
    libtcod.console_init_root(screen_width, screen_height, 'NecroPlanter',
                              False)

    # TODO
    # tcod_test.py:39: DeprecationWarning: Use the tcod.event module to check for "QUIT" type events.
    # while not libtcod.console_is_window_closed():
    while not libtcod.console_is_window_closed():

        # TODO
        # tcod_test.py:40: DeprecationWarning: Set the `con.default_fg` attribute instead.
        # libtcod.console_set_default_foreground(0, libtcod.white)
        libtcod.console_set_default_foreground(0, libtcod.white)

        libtcod.console_put_char(0, 1, 1, '@', libtcod.BKGND_NONE)
        libtcod.console_put_char(0, 5, 5, '#', libtcod.BKGND_NONE)
        libtcod.console_put_char(0, 6, 6, '$', libtcod.BKGND_NONE)

        # setMap(mapObj.print_groups())
        # print the map, starting it at 4,4
        setMap(mapObj, 4, 4)

        libtcod.console_flush()

        # tcod_test.py:47: DeprecationWarning: Use the tcod.event.get function to check for events.
        # key = libtcod.console_check_for_keypress()
        key = libtcod.console_check_for_keypress()

        if key.vk == libtcod.KEY_ESCAPE:
            return True
Example #34
0
def menu(header, options, width):
    if len(options) > 26: raise ValueError('CANNOT HAVE MORE THAN 26 OPTIONS YOU SILLY WILLY!!!')

    #calculate total height for header
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    #create off-screen console for menu window
    window = libtcod.console_new(width, height)
    
    #print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)

    #print all the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ')' + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
        y += 1
        letter_index += 1

    #blit window contents to the root console
    x = SCREEN_WIDTH/2 - width/2
    y = SCREEN_HEIGHT/2 - height/2
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    #present the root console and wait for keypress
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

    #convert ascii code to an index, if it is an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Example #35
0
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')
    headerHeight = tcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + headerHeight
    window = tcod.console_new(width, height)
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE, tcod.LEFT, header)
    y = headerHeight
    letterIndex = ord('a')
    for optionText in options:
        text = '(' + chr(letterIndex) + ') ' + optionText
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letterIndex += 1
    x = SCREEN_WIDTH / 2 - width / 2
    y = SCREEN_HEIGHT /2 - height / 2
    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
    tcod.console_flush()
    key = tcod.console_wait_for_keypress(True)

    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Example #36
0
def main():
    SW = 100
    SH = 40

    tcod.console_set_custom_font(
        'arial12x12.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)
    root = tcod.console_init_root(SW,
                                  SH,
                                  "Tales of the Golden Lotus",
                                  renderer=tcod.RENDERER_OPENGL2,
                                  vsync=False)
    world = esper.World()
    ui.MANAGER.push_screen(ui.MainScreen(world, root))

    while True:
        root.clear()
        for sc in ui.MANAGER.screens:
            sc.on_draw()

        tcod.console_flush()

        for ev in tcod.event.get():
            ui.MANAGER.cur_screen.dispatch(ev)
Example #37
0
def render_all(action, consoles, entities, game, game_map, game_state_machine,
               message_log, mouse, neighborhood, player):
    ' Render all things that appear on the screen. '
    if game.debug_mode and not action:
        action = True

    render_map(action, consoles, entities, game, game_map, game_state_machine,
               neighborhood, player)

    if action or game.redraw_map:
        render_message_log(consoles, message_log)
        render_item_description(consoles, player)
        render_item_menu(consoles, player)
        render_panel(consoles, player)  # TODO: Rename

    _game_state = game_state_machine.state.__str__()

    if _game_state == 'CompareItems':
        render_compare_items(consoles, entities, player)

    if _game_state == 'ConsumeSoul':
        render_consume_soul(consoles, entities, player)

    if _game_state == 'CharacterSheet':
        render_character_sheet(consoles, player)

    if _game_state == 'VictoryScreen':
        render_victory_screen(consoles)

    if _game_state == 'OpeningScreen':
        render_opening_screen(consoles)

    if game.debug_mode == True:
        get_things_under_mouse(consoles, entities, game_map, neighborhood,
                               mouse)

    libtcod.console_flush()
Example #38
0
def game():
    player = Player()

    # Console
    t.console_init_root(screen_width, screen_height, "My Game")

    while not t.console_is_window_closed():
        t.console_set_default_foreground(0, t.white)
        t.sys_check_for_event(t.EVENT_KEY_PRESS, key, mouse)

        # Draw player
        map_draw()
        cchar(player.x, player.y, '@')

        t.console_flush()
        cclear()

        if key.vk == t.KEY_ESCAPE:
            return
        if key.vk == t.KEY_UP:
            player.move(player.x, player.y - 1)
        elif key.vk == t.KEY_DOWN:
            player.move(player.x, player.y + 1)
        if key.vk == t.KEY_LEFT:
            player.move(player.x - 1, player.y)
        elif key.vk == t.KEY_RIGHT:
            player.move(player.x + 1, player.y)
        if key.vk == t.KEY_SPACE:
            set_map(player.x, player.y, '.')
        if key.vk == t.KEY_CONTROL:
            set_map(player.x, player.y, 'o')
        if key.vk == t.KEY_1:
            set_map(player.x, player.y, ' ')
            set_map(player.x - 1, player.y, ' ')
            set_map(player.x + 1, player.y, ' ')
            set_map(player.x, player.y - 1, ' ')
            set_map(player.x, player.y + 1, ' ')
Example #39
0
def draw_all():
    T.console_clear(None)
    _draw_map()
    _draw_messages()
    _draw_status()
    T.console_flush()
Example #40
0
 def flush(self):
     tcod.console_flush()
        playerx -= 1
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        playerx += 1
 
 
#############################################
# Initialization & Main Loop
#############################################
 
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False)
libtcod.sys_set_fps(LIMIT_FPS)
 
playerx = SCREEN_WIDTH//2
playery = SCREEN_HEIGHT//2
 
while not libtcod.console_is_window_closed():
 
    libtcod.console_set_default_foreground(0, libtcod.white)
    libtcod.console_put_char(0, playerx, playery, '@', libtcod.BKGND_NONE)
 
    libtcod.console_flush()
 
    libtcod.console_put_char(0, playerx, playery, ' ', libtcod.BKGND_NONE)
 
    #handle keys and exit game if needed
    exit = handle_keys()
    if exit:
        break
Example #42
0
 def on_draw(self, dt):
     tcod.console_clear(tcod.root_console)
     self.draw()
     tcod.console_flush()
Example #43
0
def draw_inventory(title='Inventory', items=None):
    _draw_items(title, items or GAME.player.items)
    T.console_flush()