Пример #1
0
def print_shadowed_text(
        x,
        y,
        text,
        shadow_offset=1,
        shadow_color="black",
        align=[terminal.TK_ALIGN_DEFAULT, terminal.TK_ALIGN_DEFAULT]):

    # Print text with colored shadow (default is black). Text alignment can also be set.

    vertical_align = align[0]
    horizontal_align = align[1]

    terminal.composition(terminal.TK_ON)

    terminal.puts(x,
                  y,
                  f"[color={shadow_color}][offset=0, {shadow_offset}]{text}",
                  align=vertical_align | horizontal_align)

    terminal.puts(
        x,
        y,
        f"[color={shadow_color}][offset={shadow_offset}, {shadow_offset}]{text}",
        align=vertical_align | horizontal_align)

    terminal.puts(x, y, text, align=vertical_align | horizontal_align)

    terminal.composition(terminal.TK_OFF)
Пример #2
0
    def draw(self):
        # Draw the menu to the terminal.
        if len(self.options) > 26:
            raise ValueError('Cannot have a menu with more than 26 options.')

        previous_layer = terminal.state(terminal.TK_LAYER)
        terminal.layer(RenderLayer.MENU.value)

        self.draw_background(background_color=self.background_color)

        # Print the header with wrapped text to the center of the menu
        terminal.color('white')
        terminal.composition(terminal.TK_ON)
        for i, _ in enumerate(self.header_wrapped):
            render_functions.print_shadowed_text(
                self.topleft_x + int((self.width / 2) + 1),
                self.topleft_y + i,
                self.header_wrapped[i],
                align=[terminal.TK_ALIGN_DEFAULT, terminal.TK_ALIGN_CENTER])

        # Print options under the menu, aligned to the left (left is the default)
        current_y = self.header_height + 1
        letter_index = ord('a')
        for option_text in self.options:
            text = f"{chr(letter_index)}) {option_text}"
            render_functions.print_shadowed_text(self.topleft_x,
                                                 self.topleft_y + current_y,
                                                 text)
            current_y += 1
            letter_index += 1

        terminal.composition(terminal.TK_OFF)

        terminal.layer(previous_layer)
Пример #3
0
    def pprint(self, x: int, y: int, string: str):
        """
        Pretty prints a string starting at (x,y).
        :param x: x coordinate

        :param y: y coordinate

        :param string: String to print to screen
        """
        bearlib.layer(1)
        bearlib.composition(bearlib.TK_ON)
        pos = x
        cell_size, _ = self.window.cell_size.split('x')
        cell_width = int(cell_size)
        for c in string:
            if pos >= self.window.width - x - 1:
                pos = pos + 1
                offset = (pos - x) * (cell_width / 2)
                bearlib.put_ext(x, y, int(offset), 0, c)
            else:
                pos = pos + 1
                offset = 0 - pos * (cell_width / 2)
                bearlib.put_ext(pos, y, int(offset), 0, c)
        bearlib.layer(0)
        bearlib.composition(bearlib.TK_OFF)
Пример #4
0
    def pprint_center(self, text: List[str]):
        """
        Prints a string or list of strings in the center of the window

        :param text: List of strings to be printed
        """
        height = self.window.height
        width = self.window.width
        cellsize, _ = self.window.cell_size.split('x')
        cell_width = int(cellsize)
        center = int(width / 2)

        bearlib.clear()
        bearlib.layer(1)
        bearlib.composition("TK_ON")
        y = int(height / 2 - len(text) / 2)
        for i, s in enumerate(text):
            middle_char = int(len(s) / 2)
            x = int(center - middle_char)
            pos = 0
            for c in s:
                offset = (center - x) * (cell_width / 2)
                bearlib.put_ext(x, y + i, int(offset), 0, c)
                x = x + 1
                pos = pos + 1
        bearlib.composition("TK_OFF")
        bearlib.layer(0)
        bearlib.refresh()
Пример #5
0
def main():
    # Opens and initializes terminal settings, then starts game.

    # Load config and adjust settings for the game based off of the config data.
    with open("config.json", "r") as read_file:
        config = json.load(read_file)

    config['tile_spacing_x'] = int(config['tile_font_width'] /
                                   config['cellsize_x'])
    config['tile_spacing_y'] = int(config['tile_font_height'] /
                                   config['cellsize_y'])
    config['window_width'] = config['camera_width'] * config['tile_spacing_x']
    config[
        'window_height'] = config['camera_height'] * config['tile_spacing_y']

    # Open terminal/config terminal.
    terminal.open()
    terminal.set("window: title='Etheria', size=%sx%s, cellsize=%sx%s" %
                 (config['window_width'], config['window_height'],
                  config['cellsize_x'], config['cellsize_y']))
    terminal.set("input.filter = [keyboard, mouse]")
    terminal.set(
        "text font: 'fonts/PxPlus_IBM_CGAthin.ttf', size=8x16, spacing=2x1")
    terminal.set(
        "bar font: 'fonts/PxPlus_IBM_CGAthin.ttf', size=4x4, spacing=1x6")
    terminal.set(
        "minimap font: 'fonts/PxPlus_IBM_CGAthin.ttf', size=4x4, spacing=1x2")
    terminal.set("main font: 'fonts/VeraMono.ttf', size=20x20, spacing=5x5")
    terminal.font('main')
    terminal.composition(True)

    # Start the game, close the terminal after game is exited.
    start_game(config)
    terminal.close()
Пример #6
0
def print_shadow(x, y, text, shadow_offset=1):
    if not text:
        # None error
        return
    print(f'print shadow: {x, y, text, shadow_offset}')
    try:
        """Print text with shadow."""
        # remove color options for drawing shadow which has to be always black
        pattern = r'\[/?color.*?\]'
        no_color_text = re.sub(pattern, '', text)

        terminal.composition(terminal.TK_ON)

        # print shadow text
        terminal.printf(
            x, y,
            '[color=black][offset=0, {0}]{1}'.format(shadow_offset,
                                                     no_color_text))
        terminal.printf(
            x, y,
            '[color=black][offset={0}, {0}]{1}'.format(shadow_offset,
                                                       no_color_text))

        # print foreground text
        terminal.printf(x, y, text)

        terminal.composition(terminal.TK_OFF)
    except Exception as e:
        print(f'print shadow error with : {text}')
        print(f'exception was: {e}')
        terminal.printf(x, y, text)
Пример #7
0
    def render_map(self):
        if self.map:
            y = 0
            while y < self.h:
                x = 0
                while x < self.w:
                    # need the x/y coordinates for the tile relative to the players dungeon location
                    # not where the tile will be placed
                    y_index = self.player["dy"] - (self.h // 2) + (y // settings.DUNGEON_TILE_SIZE)
                    x_index = self.player["dx"] - (self.w // 2) + (x // settings.DUNGEON_TILE_SIZE)

                    # create a tuple to compare with the map
                    coord = x_index, y_index

                    # check that there is a tile to be rendered within the bounds of the map object
                    # this prevents the rendering of the same map showing multiple times recursively
                    if coord in self.map:
                        terminal.composition(terminal.TK_ON)
                        for tile in self.map[coord]:
                            if tile:
                                terminal.put(x, y, tile)
                        terminal.composition(terminal.TK_OFF)

                    x += settings.DUNGEON_TILE_SIZE
                y += settings.DUNGEON_TILE_SIZE
Пример #8
0
def initialize_screen():
    blt.open()
    blt.set(
        "window: size=120x40, cellsize=auto, title='roguelike dev does the tutorial'; font: default"
    )
    blt.bkcolor(blt.color_from_name('0,0,0'))
    blt.composition(True)

    # needed to avoid insta-close
    blt.refresh()
    blt.color('white')

    # tiles
    # we use Unicode code point 3002 instead of a normal dot because the dot will be necessary for message log
    blt.set("0x3002: gfx/stonefloor.png, align=top-left")
    # no such problems with @ and #
    blt.set("0x23: gfx/wall.png, align=top-left")  # "#"
    blt.set("0x40: gfx/human_m.png, align=top-left")  # "@"
    blt.set("0x003E: gfx/stairs.png, align=top-left")  # ">"
    # items
    blt.set("0x2215: gfx/longsword.png, align=center")  # "∕"
    blt.set("0x203D: gfx/scroll.png, align=center")  # "‽"
    # NPCs (we use Unicode private area here)
    blt.set("0xE000: gfx/kobold.png,  align=center")  # ""
    blt.set("0xE001: gfx/goblin.png, align=center")
Пример #9
0
    def open_blt_terminal(*args, **kwargs):
        # print('Open blt')
        blt.open()
        blt.composition(True)
        # print('start game')

        fn(*args, **kwargs)
        blt.close()
Пример #10
0
    def render(self):
        super().render()

        self.render_map()

        terminal.composition(terminal.TK_ON)
        for obj in self.objects:
            terminal.put(obj.x, obj.y, obj.c)
        terminal.composition(terminal.TK_OFF)
Пример #11
0
def test_text_input():
    blt.set("window.title='Omni: text input'")
    blt.composition(False)

    max_chars = 32
    text = ""
    character = ' '
    result = 0
    char_result = 0

    while True:
        blt.clear()
        blt.color("white")

        blt.puts(2, 1, "Select different input tests by pressing corresponding number:")

        blt.puts(2, 3, "[color=orange]1.[/color] read_str")
        draw_frame(5, 4, max_chars + 2, 3)
        blt.puts(6, 5, "%s" % text)
        blt.puts(5 + max_chars + 2 + 1, 5, "[color=gray] %s" % ("OK" if result >= 0 else "Cancelled"))

        blt.puts(2, 8, "[color=orange]2.[/color] read_char")
        draw_frame(5, 9, 5, 3)
        blt.put(7, 10, character)
        blt.puts(11, 10, "[color=gray]%s" % key_names.get(char_result, str(char_result)))

        blt.refresh()

        key = blt.read()
        if key in (blt.TK_CLOSE, blt.TK_ESCAPE):
            break

        elif key == blt.TK_1:
            blt.color("orange")
            draw_frame(5, 4, max_chars + 2, 3)
            result, text = blt.read_str(6, 5, text, max_chars)

        elif key == blt.TK_2:
            blt.color("orange")
            draw_frame(5, 9, 5, 3)

            while True:
                blt.put(7, 10, character)  
                blt.clear_area(11, 10, 16, 1)
                blt.puts(11, 10, "[color=gray]%s" % key_names.get(char_result, str(char_result)))
                blt.refresh()

                character = ' '
                key = blt.read()
                if key in (blt.TK_ESCAPE, blt.TK_CLOSE, blt.TK_RETURN):
                    break
                elif blt.check(blt.TK_WCHAR):
                    character = blt.state(blt.TK_WCHAR)
                    char_result = key
                elif key < blt.TK_KEY_RELEASED:
                    char_result = key
Пример #12
0
 def draw(self, context):
     if bearlib.state(bearlib.TK_COLOR) == int(self.color):
         context.color(self.window.fg_color)
     else:
         context.color(self.color)
     context.layer(self.layer)
     bearlib.composition(bearlib.TK_OFF)
     context.put(self.position, self.glyph)
     context.layer(0)
     context.color(self.window.fg_color)
Пример #13
0
def test():
    blt.open()
    # blt.set("window: size=80x25, cellsize=auto, title='Omni: menu'; font: default")
    # blt.set("window: size=80x25, cellsize=auto, title='Omni: menu'; font: arial.ttf, size=8")  # font: UbuntuMono-R.ttf, size=12"
    blt.set("window: size=80x25, cellsize=auto, title='Omni: menu'; font: .\Fonts\cp437_16x16_alpha.png, size=16x16, codepage=437")  # font: UbuntuMono-R.ttf, size=12"
    blt.composition(blt.TK_ON)
    blt.color("white")
    test_basic_output()
    test_tilesets()
    blt.close()
Пример #14
0
def game_initialize():
    global GAME, PLAYER, FOV_CALCULATE

    blt.open()
    # default terminal size is 80x25
    # we need nonstandard size to fit the test map
    blt.set("window: size=120x25, cellsize=auto, title='roguelike dev does the tutorial'; font: default")

    # we need composition to be able to draw tiles on top of other tiles
    blt.composition(True)

    # needed to avoid insta-close
    blt.refresh()
    blt.color('white')
    # tiles
    # we use Unicode code point 3002 instead of a normal dot because the dot will be necessary for message log
    blt.set("0x3002: gfx/floor_sand.png, align=center")
    # no such problems with @ and #
    blt.set("0x23: gfx/untitled.png, align=center")  # "#"
    blt.set("0x40: gfx/human_m.png, align=center")  # "@"
    blt.set("0x003E: gfx/stairs_down.png, align=center")  # ">"
    # items
    blt.set("0x2215: gfx/longsword.png, align=center")  # "∕"
    blt.set("0x203D: gfx/scroll.png, align=center") # "‽"
    # NPCs (we use Unicode private area here)
    blt.set("0xE000: gfx/kobold.png,  align=center")  # ""
    blt.set("0xE001: gfx/goblin.png, align=center")

    # if we have a savegame, load it
    '''
    if os.path.isfile('savegame.json'):
        GAME, PLAYER = load_game()

        # fix player ref
        # player is always last in the entities list
        # the assumption isn't true if you pick up and drop some items
        # so we handle it in load_game()
        #player_id = len(GAME.current_entities) - 1
        #GAME.current_entities[player_id] = PLAYER

        # handle FOV
        FOV_CALCULATE = True
        # recreate the fov
        global FOV_MAP
        FOV_MAP = map_make_fov(GAME.current_map)

        # fix issue where the map is black on turn 1
        map_calculate_fov()

    else:
    '''
    GAME, PLAYER, FOV_CALCULATE = start_new_game()

        # fix issue where the map is black on turn 1
    map_calculate_fov()
Пример #15
0
    def __init__(self):
        #####################################
        # Initialize BearLibTerminal Window #
        #####################################
        terminal.open()
        font = f'font: MegaFont.ttf, size={self.tile_size}'
        terminal.set(f"window: title={self.title}; {font}")
        terminal.set("input.filter = keyboard+, mouse+")
        terminal.printf(25, 2, self.title)
        terminal.composition(terminal.TK_ON)
        terminal.refresh()
        '''
		display = Display()
		root = display.screen().root
		printWindowHierrarchy(root, '-')
		'''
        self.window_id = get_current_win()
        ###################################################################
        # Global Hotkeys using the keyboard module as a low level wrapper #
        ###################################################################
        keyboard.add_hotkey(config.get('innit', 'key_toggle'),
                            self.global_hotkey,
                            args=(' '))
        keyboard.add_hotkey('ctrl+shift+esc', self.global_hotkey, args=('s'))
        keyboard.add_hotkey(config.get('innit', 'key_next'),
                            self.global_hotkey,
                            args=('n'))
        keyboard.add_hotkey(config.get('innit', 'key_prev'),
                            self.global_hotkey,
                            args=('b'))
        keyboard.add_hotkey(config.get('innit', 'key_pause'),
                            self.global_hotkey,
                            args=('p'))
        keyboard.add_hotkey(config.get('innit', 'key_volup'),
                            self.global_hotkey,
                            args=('u'))
        keyboard.add_hotkey(config.get('innit', 'key_voldn'),
                            self.global_hotkey,
                            args=('m'))
        keyboard.add_hotkey(config.get('innit', 'key_stop'),
                            self.global_hotkey,
                            args=('s'))
        keyboard.add_hotkey(config.get('innit', 'key_mark_watched'),
                            self.global_hotkey,
                            args=('w'))
        # these keys only work when the program is in focus
        keyboard.add_hotkey('enter', self.global_hotkey, args=('f'))
        keyboard.add_hotkey('space', self.global_hotkey, args=(' '))
        keyboard.add_hotkey('esc', self.global_hotkey, args=('q'))
        keyboard.add_hotkey('left', self.global_hotkey, args=('4'))
        keyboard.add_hotkey('right', self.global_hotkey, args=('6'))
        keyboard.add_hotkey('up', self.global_hotkey, args=('8'))
        keyboard.add_hotkey('down', self.global_hotkey, args=('2'))
        self.start_main_loop()
Пример #16
0
def test():
    blt.open()
    # blt.set("window: size=80x25, cellsize=auto, title='Omni: menu'; font: default")
    # blt.set("window: size=80x25, cellsize=auto, title='Omni: menu'; font: arial.ttf, size=8")  # font: UbuntuMono-R.ttf, size=12"
    blt.set(
        "window: size=80x25, cellsize=auto, title='Omni: menu'; font: .\Fonts\cp437_16x16_alpha.png, size=16x16, codepage=437"
    )  # font: UbuntuMono-R.ttf, size=12"
    blt.composition(blt.TK_ON)
    blt.color("white")
    test_basic_output()
    test_tilesets()
    blt.close()
Пример #17
0
def menu(header, options, width, title=None):
    global FOV_CALCULATE

    FOV_CALCULATE = True

    menu_x = int((120 - width) // 4)

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = 2

    menu_h = int(header_height + 1 + 26)
    menu_y = int((25 - menu_h) // 2)

    # create a window

    create_window(menu_x, menu_y, width, menu_h, title)
    create_window(2, 30, 27, 9, 'd')
    create_window(31, 30, 27, 9, 'd')
    create_window(60, 30, 27, 9, 'd')
    create_window(89, 30, 27, 9, 'd')

    blt.puts(menu_x, menu_y, header)

    # print all the options
    y = menu_y + header_height + 1
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        blt.puts(menu_x, y, text)
        y += 1
        letter_index += 1

    blt.refresh()
    # present the root console to the player and wait for a key-press
    blt.set('input: filter = [keyboard]')
    while True:
        key = blt.read()
        if blt.check(blt.TK_CHAR):
            # convert the ASCII code to an index; if it corresponds to an option, return it
            key = blt.state(blt.TK_CHAR)
            index = key - ord('a')
            if 0 <= index < len(options):
                blt.set('input: filter = [keyboard, mouse+]')
                blt.composition(True)
                return index
        else:
            blt.set('input: filter = [keyboard, mouse+]')
            blt.composition(True)
            return None
Пример #18
0
    def initialize(self):
        # Initialize game data from external files
        game_data = json_data.JsonData()
        json_data.data = game_data
        self.data = game_data

        window_title = 'SpiritQuestRL'
        size = 'size=200x80'
        title = 'title=' + window_title
        cellsize = 'cellsize=auto'
        resizable = 'resizeable=true'
        window = "window: " + size + "," + title + "," + cellsize + "," + resizable

        blt.composition(True)
        blt.open()
        blt.set(window)
        blt.set("font: default")
        blt.set("input: filter=[keyboard]")

        # Needed to avoid insta-close and flush the input queue
        blt.refresh()
        blt.read()

        self.options = Options()

        # Load tiles
        init_tiles(self.options)

        # Init UI
        self.ui = UIElements()
        self.ui.owner = self

        self.actions = Actions()
        self.actions.owner = self

        self.render_functions = RenderFunctions(self.ui.offset_x,
                                                self.ui.offset_y)
        self.render_functions.owner = self

        self.ui.draw()

        # Call main menu and start game loop
        main_menu_component = MainMenu(title_screen=True)
        self.menus = Menus(main_menu=main_menu_component)
        self.menus.owner = self

        self.menus.main_menu.show()

        self.menus.main_menu.title_screen = False
        self.game_loop()
Пример #19
0
 def init_terminal(self):
     blt.open()
     blt.set(f"""window.size={TERMINAL_SIZE_X}x{TERMINAL_SIZE_Y},
                 window.cellsize={TERMINAL_CELL_SIZE_X}x{TERMINAL_CELL_SIZE_Y},
                 resizeable=true, minimum-size={TERMINAL_SIZE_X}x{TERMINAL_SIZE_Y}""")
     blt.set("font: res/fonts/VeraMono.ttf, size=12x24, spacing=1x1")
     blt.set("terrain font: res/tilesets/Curses_square_24.png, size=24x24, codepage=437, spacing=2x1")
     blt.set("U+E100: res/character/soldier_24.png, size=24x24")
     blt.set("U+E101: res/character/mercenary_24.png, size=24x24")
     blt.set("U+E102: res/character/echoes-map-skogul.png, size=32x32")
     blt.set("U+E103: res/character/echoes-map-spartan.png, size=32x32")
     blt.set("U+E104: res/character/echoes-map-conqueror.png, size=32x32")
     blt.set("window.title='SimplyRL'")
     blt.set("input.filter={keyboard, mouse+}")
     blt.composition(True)
     blt.refresh()
Пример #20
0
def create_terminal(w,h) -> bool:
    term = terminal.open()
    terminal.set('window: size='+str(w)+'x'+str(h)+', cellsize=10x10, title=Crimson Sands')
    terminal.set("input: filter={keyboard+, mouse+}")

    #Fonts
    terminal.set("text font: fonts\\consolab.ttf, size=8x14")
    terminal.set("big font: fonts\\consolab.ttf, size=12x16")
    terminal.set("font: fonts\\DejaVuSansMono-Bold.ttf, size=10x10")
    terminal.set("headi font: fonts\\DejaVuSansMono-BoldOblique.ttf, size=16")
    terminal.set("head font: fonts\\DejaVuSansMono-Bold.ttf, size=14")
    terminal.set("bodyi font: fonts\\DejaVuSansMono-BoldOblique.ttf, size=13")
    terminal.set("body font: fonts\\DejaVuSansMono-Bold.ttf, size=12")
    
    terminal.composition(terminal.TK_OFF)
    terminal.refresh()
    return term
Пример #21
0
def run():
    terminal.open()
    terminal.set("window: size=100x50, cellsize8x12, resizeable=true;")
    terminal.setf("font: Andux_cp866ish.png, size=8x12, codepage=437")
    terminal.composition(True)

    terminal.refresh()

    #p1 = Particle(50, 25, 0, 10, 90, 1)
    #p2 = Particle(50, 25, 0, 10, 70, 1)
    #emitter = Emitter(25, 25, 40, 90, .05, 2, 4)
    emitter = read_config()
    emitter.setColor([255, 138, 138, 255], [0, 0, 0, 0], [55, 138, 1, 255],
                     [0, 0, 0, 0])
    emitter.restart()

    #sudo_pool = [p1, p2]
    emitter.start(0)
    timer1 = time.perf_counter()
    flag = True

    while flag:
        timer2 = time.perf_counter()
        delta = timer2 - timer1

        while terminal.has_input():
            key = terminal.read()
            if key == 21:
                emitter = read_config()
                emitter.setColor([255, 138, 138, 255], [0, 0, 0, 0],
                                 [55, 138, 1, 255], [0, 0, 0, 0])
                emitter.restart()
                emitter.start(0)
            if key == 27 or key == 224:
                flag = False

        emitter.update(delta, 1.0)
        terminal.clear()

        for p in emitter._particlePool:
            render(p, emitter._pos)
        terminal.refresh()
        system('clear')

        timer1 = time.perf_counter()
    exit
Пример #22
0
 def run(self):
     stop = False
     blt.composition(True)
     while not stop:
         blt.clear()
         self.draw()
         blt.refresh()
         while blt.has_input():
             kp = blt.read()
             if kp == blt.TK_CLOSE:
                 stop = True
             elif kp == blt.TK_ESCAPE:
                 stop = True
             elif kp == blt.TK_SPACE:
                 self.init_terrain_map()
                 self.init_tile_map()
     blt.close()
Пример #23
0
    def __init__(self, main):
        self.main = main

        term.open()

        term.set("window: size={:}x{:}".format(
            Render.SCREEN[WIDTH], Render.SCREEN[HEIGHT]))
        term.set("font: " + Render.GRAPHICSPATH +
                 Render.FONT + ", size=12x24, codepage=437")
        term.set("0x1000: " + Render.GRAPHICSPATH + Render.TILES +
                 ", size=24x24, spacing=2x1, align=center")
        term.set("0x2000: " + Render.GRAPHICSPATH + Render.ITEMS +
                 ", size=48x24, spacing=4x1, align=center")
        term.set("0x3000: " + Render.GRAPHICSPATH + Render.TITLE +
                 ", size=800x285, align=center")

        term.composition(True)
        term.refresh()
Пример #24
0
def draw_box_bar(x, y, total_width, name, value, maximum, bar_color,
                 back_color, target):
    # render a bar (HP, experience, etc). first calculate the width of the bar

    pos = Pos(Constants.MAP_CONSOLE_WIDTH + 4, 35)

    bar_width = int(float(value) / maximum * total_width)
    og_y = y
    height = 1
    offset_color = Color("128, 128, 128")

    if name != '':
        set_background(target, libtcod.black)
        set_foreground(target, Color("51, 51, 51"))
        print_line(target, x, y, name)
        y += 1
        height += 1

    #print "Bar Colors"
    #print bar_color
    #print back_color
    ''' render MAX value '''
    # set_background(target, back_color-offset_color)
    # set_foreground(target, bar_color-offset_color)
    for x1 in range(x, x + total_width):
        draw_char(target, x1, y, Utils.get_unicode(219), back_color,
                  libtcod.BKGND_SET)
        draw_char(target, x1, y, Utils.get_unicode(255), bar_color,
                  libtcod.BKGND_SET)
    ''' render current value '''
    #set_background(target, back_color)
    # set_foreground(target, bar_color)
    for x1 in range(x, x + bar_width):
        draw_char(target, x1, y, Utils.get_unicode(219), back_color,
                  libtcod.BKGND_SET)
        draw_char(target, x1, y, Utils.get_unicode(254), bar_color,
                  libtcod.BKGND_SET)

    if Utils.is_mouse_in(x, og_y, total_width, height):
        terminal.composition(terminal.TK_OFF)
        line = str(value) + "/" + str(maximum)
        set_foreground(target, 'white')
        print_line(target, x, y, line)
        terminal.composition(terminal.TK_ON)
Пример #25
0
def render_map_camera():
    start = time.perf_counter()

    current_map = World.fetch('current_map')
    min_x, max_x, min_y, max_y = get_screen_bounds()
    map_width = current_map.width
    map_height = current_map.height

    y = 0
    for ty in range(min_y, max_y):
        x = 0
        for tx in range(min_x, max_x):
            if 0 <= tx < map_width and 0 <= ty < map_height:
                terminal.composition(terminal.TK_ON)
                idx = current_map.xy_idx(tx, ty)
                if current_map.revealed_tiles[idx]:
                    glyph, sprite, char_color = get_tile_glyph(
                        idx, current_map)
                    draw_tile(x, y, glyph, sprite, char_color, Layers.MAP)

                if current_map.stains[idx] and current_map.visible_tiles[idx]:
                    char_color = 'dark red'
                    sprite = f'props/blood{current_map.stains[idx]}.png'
                    glyph = ' '
                    draw_tile(x, y, glyph, sprite, char_color, Layers.STAINS)

                if config.SHOW_BOUNDARIES and not current_map.revealed_tiles[
                        idx]:
                    if Interface.mode == GraphicalModes.ASCII or Interface.mode == GraphicalModes.TILES:
                        terminal.printf(x, y, f'[color=gray]-[/color]')
                    else:
                        print(
                            f'render camera: graphical mode {Interface.mode} not implemented.'
                        )
                        raise NotImplementedError

                terminal.composition(terminal.TK_OFF)
            x += (1 * Interface.zoom)
        y += (1 * Interface.zoom)

    delta_time = (time.perf_counter() - start) * 1000
    print(f'delta time: for render map : {delta_time}')
Пример #26
0
def run():
    terminal.open()
    terminal.set("window: size=100x50, cellsize=8x12, resizeable=true;")
    terminal.setf("font: Andux_cp866ish.png, size=8x12, codepage=437;")
    terminal.composition(True)

    terminal.refresh()
    # p1 = Particle(50, 25, 0, 10, 90, 1)
    # p2 = Particle(50, 25, 0, 10, 70, 1)

    pool = [p1, p2]

    while terminal.read() != terminal.TK_CLOSE:
        terminal.clear()
        #for par in pool:
        #    render(par)
        #    par.update(1)
        pass

    terminal.close()
Пример #27
0
def draw_box_bar(x, y, total_width, name, value, maximum, bar_color, back_color, target):
    # render a bar (HP, experience, etc). first calculate the width of the bar

    pos = Pos(Constants.MAP_CONSOLE_WIDTH + 4, 35)

    bar_width = int(float(value) / maximum * total_width)
    og_y = y
    height = 1
    offset_color = Color("128, 128, 128")

    if name != '':
        set_background(target, libtcod.black)
        set_foreground(target, Color("51, 51, 51"))
        print_line(target, x, y, name)
        y += 1
        height += 1

    #print "Bar Colors"
    #print bar_color
    #print back_color

    ''' render MAX value '''
    # set_background(target, back_color-offset_color)
    # set_foreground(target, bar_color-offset_color)
    for x1 in range(x, x+total_width):
        draw_char(target, x1, y, Utils.get_unicode(219), back_color, libtcod.BKGND_SET)
        draw_char(target, x1, y, Utils.get_unicode(255), bar_color, libtcod.BKGND_SET)

    ''' render current value '''
    #set_background(target, back_color)
    # set_foreground(target, bar_color)
    for x1 in range(x, x+bar_width):
        draw_char(target, x1, y, Utils.get_unicode(219), back_color, libtcod.BKGND_SET)
        draw_char(target, x1, y, Utils.get_unicode(254), bar_color, libtcod.BKGND_SET)

    if Utils.is_mouse_in(x, og_y, total_width, height):
        terminal.composition(terminal.TK_OFF)
        line = str(value) + "/" + str(maximum)
        set_foreground(target, 'white')
        print_line(target, x, y, line)
        terminal.composition(terminal.TK_ON)
Пример #28
0
 def initialize_terminal(self):
     terminal.open()
     terminal.set("""U+E000: assets/rogue.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E050: assets/floors.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E060: assets/walls.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E070: assets/doors.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E100: assets/basic-monsters.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E150: assets/corpse.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E200: assets/items.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E250: assets/weapons.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E275: assets/swordslash.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E300: assets/armor.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E350: assets/arrows.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E360: assets/spellbooks.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E370: assets/lightning_bolt.png, size=16x16,
                  align=center, resize=32x32""")
     terminal.set("""U+E380: assets/fireball.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""U+E500: assets/white.png, size=16x16, align=center,
                     resize=32x32""")
     terminal.set("""window: size=181x52, cellsize=auto, title='roguelike',
                  font: assets/Px437_IBM_VGA8.ttf""")
     terminal.set("""huge font: assets/Px437_IBM_VGA8.ttf, size=16x32,
                  spacing=2x2""")
     terminal.set("input.filter={keyboard, mouse+}")
     terminal.composition(True)
Пример #29
0
def render_bar(x, y, width, name, value, max_value, bar_color, back_color,
               text_color):
    value_bar = int(value / max_value * width)
    tile = Interface.get_code('system/ui5.png')

    # background bar
    terminal.color(back_color)
    for i in range(width):
        terminal.put(x + i, y, tile)

    # value bar
    if value_bar > 0:
        terminal.color(bar_color)
        for i in range(value_bar):
            terminal.put(x + i, y, tile)

    # text on it
    terminal.composition(terminal.TK_ON)
    text = f'{Texts.get_text(name)}: {value}/{max_value}'
    center_bar_x = x - (len(text) // 2) + (width // 2)
    terminal.color(text_color)
    print_shadow(center_bar_x, y, text)
    terminal.composition(terminal.TK_OFF)
Пример #30
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):

    bar_width = int(float(value) / maximum * total_width)

    terminal.color(terminal.color_from_name(back_color))
    for _i in range(total_width):
        terminal.put(x + _i, y, 0x2588)

    if bar_width > 0:
        terminal.color(terminal.color_from_name(bar_color))
        for _i in range(bar_width):
            terminal.put(x + _i, y, 0x2588)

    terminal.composition(terminal.TK_ON)

    text = f"{name}: {value}/{maximum}"

    x_centered = x + int((total_width - len(text)) / 2)

    terminal.color(terminal.color_from_name("white"))
    print_shadowed_text(x_centered, y, text)

    terminal.composition(terminal.TK_OFF)
Пример #31
0
def create_window(x, y, w, h, title=None):
    #test
    blt.composition(False)

    last_bg = blt.state(blt.TK_BKCOLOR)
    blt.bkcolor(blt.color_from_argb(200, 0, 0, 0))
    blt.clear_area(x - 2, y - 2, w + 2, h + 2)
    blt.bkcolor(last_bg)

    # upper border
    border = '┌' + '─' * (w) + '┐'
    blt.puts(x - 1, y - 1, border)
    # sides
    for i in range(h):
        blt.puts(x - 1, y + i, '│')
        blt.puts(x + w, y + i, '│')
    # lower border
    border = '└' + '─' * (w) + '┘'
    blt.puts(x - 1, y + h, border)

    if title is not None:
        leng = len(title)
        offset = (w + 2 - leng) // 2
        blt.puts(x + offset, y - 1, title)
Пример #32
0
def test_tilesets():
    blt.set("window.title='Omni: tilesets'")
    blt.composition(True)

    # Load tilesets
    blt.set("U+E100: ./Images/Runic.png, size=8x16")
    blt.set("U+E200: ./Images/Tiles.png, size=32x32, align=top-left")
    blt.set("U+E400: ./Images/test_tiles.png, size=16x16, align=top-left")
    blt.set("U+E300: ./Fonts/fontawesome-webfont.ttf, size=24x24, spacing=3x2, codepage=./Fonts/fontawesome-codepage.txt")
    blt.set("zodiac font: ./Fonts/Zodiac-S.ttf, size=24x36, spacing=3x3, codepage=437")

    blt.clear()
    blt.color("white")

    blt.print_(2, 1, "[color=orange]1.[/color] Of course, there is default font tileset.")

    blt.print_(2, 3, "[color=orange]2.[/color] You can load some arbitrary tiles and use them as glyphs:")
    blt.print_(2+3, 4,
        "Fire rune ([color=red][U+E102][/color]), "
        "water rune ([color=lighter blue][U+E103][/color]), "
        "earth rune ([color=darker green][U+E104][/color])")

    blt.print_(2, 6, "[color=orange]3.[/color] Tiles are not required to be of the same size as font symbols:")
    blt.put(2+3+0, 7, 0xE200+7)
    blt.put(2+3+5, 7, 0xE200+8)
    blt.put(2+3+10, 7, 0xE200+9)

    blt.print_(2, 10, "[color=orange]4.[/color] Like font characters, tiles may be freely colored and combined:")

    blt.put_ext(2+3+0, 11, 0, 0, tiles['stone_wall'], [blt.color_from_name("red"),
                                                       blt.color_from_name("red"),
                                                       blt.color_from_name("blue"),
                                                       blt.color_from_name("red")])
    blt.put_ext(2 + 3 + 2, 11, 0, 0, tiles['stone_wall'], [blt.color_from_name("red"),
                                                           blt.color_from_name("blue"),
                                                           blt.color_from_name("red"),
                                                           blt.color_from_name("red")])
    blt.put_ext(2 + 3 + 0, 13, 0, 0, tiles['stone_wall'], [blt.color_from_name("red"),
                                                           blt.color_from_name("red"),
                                                           blt.color_from_name("blue"),
                                                           blt.color_from_name("blue")])
    blt.put_ext(2 + 3 + 2, 13, 0, 0, tiles['stone_wall'], [blt.color_from_name("blue"),
                                                           blt.color_from_name("blue"),
                                                           blt.color_from_name("red"),
                                                           blt.color_from_name("red")])

    blt.put_ext(2 + 3 + 0 + 5, 11, 0, 0, '#', [blt.color_from_name("yellow"),
                                                           blt.color_from_name("black"),
                                                           blt.color_from_name("black"),
                                                           blt.color_from_name("black")])
    blt.put_ext(2 + 3 + 1 + 5, 11, 0, 0, 'A', [blt.color_from_name("black"),
                                                           blt.color_from_name("yellow"),
                                                           blt.color_from_name("yellow"),
                                                           blt.color_from_name("black")])
    blt.put_ext(2 + 3 + 0 + 5, 12, 0, 0, 'A', [blt.color_from_name("black"),
                                                           blt.color_from_name("black"),
                                                           blt.color_from_name("yellow"),
                                                           blt.color_from_name("yellow")])
    blt.put_ext(2 + 3 + 1 + 5, 12, 0, 0,'@', [blt.color_from_name("dark yellow"),
                                                           blt.color_from_name("dark yellow"),
                                                           blt.color_from_name("dark yellow"),
                                                           blt.color_from_name("dark yellow")])

    blt.put_ext(2 + 3 + 0 + 7, 11, 0, 0, 'A', [blt.color_from_name("black"),
                                               blt.color_from_name("yellow"),
                                               blt.color_from_name("black"),
                                               blt.color_from_name("black")])

    blt.put_ext(2 + 3 + 0 + 7, 12, 0, 0, 'A', [blt.color_from_name("yellow"),
                                               blt.color_from_name("yellow"),
                                               blt.color_from_name("black"),
                                               blt.color_from_name("black")])


    '''
    # blt.color("lightest red")
    blt.put(2+3+4, 11,tiles['stairs'])
    # blt.color("purple")
    blt.put(2+3+8, 11, tiles['gold'])
    #blt.color("darkest red")
    blt.put(17, 11, 0xE400+0)
    blt.put(18, 11, 0xE400+0)
    blt.put(19, 11, 0xE400+1)
    blt.put(20, 11, 0xE400 + 0)
    blt.put(20, 11, 0xE400 + 2)

    blt.put(17, 12, 0xE400 + 10)
    blt.put(18, 12, 0xE400 + 10)
    blt.put(19, 12, 0xE400 + 11)
    blt.put(20, 12, 0xE400 + 10)
    blt.put(20, 12, 0xE400 + 12)
    '''
    blt.put(21, 11, 0xE400+0)
    blt.color("blue")
    blt.put(18, 11, '@')

    blt.color("white")
    order = [11, 10, 14, 12, 13]
    for i in range(len(order)):
        blt.put(30 + i * 4, 11, 0xE200 + order[i]);
        blt.put(30 + (len(order)+1) * 4, 11, 0xE200 + order[i])

    blt.put(30 + len(order) * 4, 11, 0xE200 + 15)

    blt.print_(2, 15, "[color=orange]5.[/color] And tiles can even come from TrueType fonts like this:")
    for i in range(6):
        blt.put(5 + i * 5, 15, 0xE300 + i)

    blt.print_(5, 18, "...or like this:\n[font=zodiac]D F G S C")

    blt.refresh()

    key = None
    while key not in (blt.TK_CLOSE, blt.TK_ESCAPE):
        key = blt.read()

    # Clean up
    blt.set("U+E100: none; U+E200: none; U+E300: none; zodiac font: none")
    blt.composition(False)
Пример #33
0
def main():
    game = Game()
    show_load_error_message = False

    game.game_state: GameStates = GameStates.MAIN_MENU
    game.previous_state: GameStates = game.game_state

    blt.open()
    blt.composition(True)
    blt.set(
        f"window: size={CONSTANTS.screen_width}x{CONSTANTS.screen_height}, title={CONSTANTS.window_title}, cellsize=8x8"
    )
    blt.set("input: filter={keyboard, mouse+}")
    blt.set(f"{CONSTANTS.map_font}")
    blt.set(f"{CONSTANTS.ui_font}")
    blt.set(f"{CONSTANTS.bar_font}")
    blt.set(f"{CONSTANTS.hover_font}")

    while game.game_running:
        if game.game_state == GameStates.MAIN_MENU:

            blt.clear()

            if show_load_error_message:
                message_box(
                    header="No save game to load",
                    width=50,
                    screen_width=CONSTANTS.screen_width,
                    screen_height=CONSTANTS.screen_height,
                )

            main_menu(CONSTANTS.camera_width)
            blt.refresh()

            if blt.has_input():

                terminal_input = blt.read()
                print(terminal_input)
                action = handle_main_menu(terminal_input)

                new_game: bool = action.get("new_game", False)
                load_saved_game: bool = action.get("load_game", False)
                exit_game: bool = action.get("exit_game", False)

                if show_load_error_message and (new_game or load_saved_game
                                                or exit_game):
                    show_load_error_message = False
                elif new_game:
                    game = game.new_game()
                    game.map_generator.make_map(
                        width=CONSTANTS.map_width,
                        height=CONSTANTS.map_height,
                        entities=game.entities,
                        min_monsters=CONSTANTS.min_monsters,
                    )
                    game.game_state = GameStates.PLAYER_TURN
                    game.player.position = game.map_generator.player_start_point

                elif load_saved_game:
                    try:
                        game = game.load_game()
                    except FileNotFoundError:
                        show_load_error_message = True
                elif exit_game:
                    break
        else:
            blt.clear()
            play_game(game)

            game.game_state = GameStates.MAIN_MENU