Beispiel #1
0
def draw_map(game_map):
    if game_map:
        terminal.layer(Layers.MAP)
        terminal.color(terminal.color_from_name("white"))

        for point, tile in game_map:
            terminal.put(point.x, point.y, tile.char)
Beispiel #2
0
def render_entities_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

    subjects = World.get_components(PositionComponent, RenderableComponent)
    for entity, (position, renderable) in subjects:
        hidden = World.get_entity_component(entity, HiddenComponent)
        idx = current_map.xy_idx(position.x, position.y)
        terminal.layer(renderable.render_order.value)
        if current_map.visible_tiles[idx] and not hidden:
            entity_screen_x = position.x - min_x
            entity_screen_y = position.y - min_y
            if 0 <= entity_screen_x <= map_width and 0 <= entity_screen_y <= map_height:
                if Interface.mode == GraphicalModes.ASCII:
                    terminal.printf(
                        entity_screen_x * Interface.zoom,
                        entity_screen_y * Interface.zoom,
                        f'[color={renderable.fg}]{renderable.glyph}[/color]')
                elif Interface.mode == GraphicalModes.TILES:
                    terminal.color(f'{renderable.fg}')
                    terminal.put(entity_screen_x * Interface.zoom,
                                 entity_screen_y * Interface.zoom,
                                 Interface.get_code(renderable.sprite))
                else:
                    print(
                        f'render camera: graphical mode {Interface.mode} not implemented.'
                    )
                    raise NotImplementedError

    delta_time = (time.perf_counter() - start) * 1000
    print(f'delta time: for render entities : {delta_time}')
Beispiel #3
0
    def draw_light_sources(self):
        player = self.owner.player
        light_map = player.player.lightmap
        game_map = self.owner.levels.current_map
        game_camera = self.owner.game_camera
        for light in self.light_sources:
            light_fov = np.where(light.fov_map.fov)
            center = np.array([light.owner.y, light.owner.x])

            for i in range(light_fov[0].size):
                y, x = int(light_fov[0][i]), int(light_fov[1][i])
                if player.light_source.fov_map.fov[y, x]:
                    v = np.array([y, x])
                    dist = float(cityblock(center, v))
                    light_level = game_map.tiles[x][y].natural_light_level * \
                                  (1.0 / (0.2 + 0.1 * dist + 0.025 * dist * dist))

                    if light_map[y][x] < light_level:
                        light_map[y][x] = light_level

        player_fov = np.where(player.light_source.fov_map.fov)
        for j in range(player_fov[0].size):
            y, x = int(player_fov[0][j]), int(player_fov[1][j])
            cam_x, cam_y = game_camera.get_coordinates(x, y)
            blt.layer(0)
            c = blt.color_from_name(game_map.tiles[x][y].color)
            argb = argb_from_color(c)
            flicker = random.uniform(
                0.95, 1.05) if self.owner.options.flicker is True else 1
            a = argb[0]
            r = min(int(argb[1] * light_map[y][x] * flicker), 255)
            g = min(int(argb[2] * light_map[y][x] * flicker), 255)
            b = min(int(argb[3] * light_map[y][x] * flicker), 255)

            blt.color(blt.color_from_argb(a, r, g, b))
            blt.put(cam_x * self.owner.options.tile_offset_x,
                    cam_y * self.owner.options.tile_offset_y,
                    game_map.tiles[x][y].char)

            if len(game_map.tiles[x][y].layers) > 0:
                i = 1
                for tile in game_map.tiles[x][y].layers:
                    blt.layer(i)
                    c = blt.color_from_name(tile[1])
                    argb = argb_from_color(c)
                    a = argb[0]
                    r = min(int(argb[1] * light_map[y][x] * flicker), 255)
                    g = min(int(argb[2] * light_map[y][x] * flicker), 255)
                    b = min(int(argb[3] * light_map[y][x] * flicker), 255)
                    blt.color(blt.color_from_argb(a, r, g, b))
                    blt.put(cam_x * self.owner.options.tile_offset_x,
                            cam_y * self.owner.options.tile_offset_y, tile[0])
                    i += 1

            if len(game_map.tiles[x][y].entities_on_tile) > 0:
                for entity in game_map.tiles[x][y].entities_on_tile:

                    if not entity.cursor:
                        self.clear(entity, cam_x, cam_y)
                        self.draw(entity, cam_x, cam_y)
Beispiel #4
0
def draw_rect(dest, x, y, w, h, frame=False, f_color=None, bk_color=None, title=None):
    terminal.layer(dest)

    if title:
        if len(title) % 2 == 0:
            adj = 1
        else:
            adj = 2
        offset_x1 = ((w - len(title)) / 2) + adj
        offset_x2 = (w - len(title)) - (offset_x1 - 2)
    else:
        offset_x1 = w
        offset_x2 = 0

    for x1 in range(w):
        for y1 in range(h):
            terminal.color(bk_color)
            draw_char(dest, x1 + x, y1 + y, Utils.get_unicode(219))
            if frame:
                terminal.color(f_color)
                if (x1, y1) == (0, 0):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_NW)
                elif (x1, y1) == (w - 1, 0):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_NE)
                elif (x1, y1) == (0, h - 1):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_SW)
                elif (x1, y1) == (w - 1, h - 1):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_SE)
                elif x1 == 0 or x1 == w - 1:
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_E)
                elif  y1 == h - 1:
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_N)
    if title:
        print_line(dest, x, y, " " )
        print_line(dest, x, y, "{0}".format(title).center(w, ' '))
Beispiel #5
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)
Beispiel #6
0
    def create_menu_content(self):
        render_order = 1
        menu_contents = list()

        # HEADER
        box = BoxMenu(render_order, linebreak=3)
        render_order += 1
        color = config.COLOR_MAIN_MENU_TITLE
        text = f'[color={color}] {self.header} [/color]'
        box.add(text, MenuAlignement.CENTER)
        menu_contents.append(box)

        terminal.color(config.COLOR_MENU_BASE)
        logs = World.fetch('logs')
        print(f'menu: logs are {logs}')
        box = BoxMenu(render_order, linebreak=3)
        render_order += 1
        count = 0
        for log in logs:
            if count < config.LOG_LIMIT_DEATH_SCREEN:
                box.add(log, MenuAlignement.CENTER)
                count += 1
        menu_contents.append(box)

        # HOW TO QUIT?
        box = BoxMenu(render_order, linebreak=0)
        render_order += 1
        text = f' {Texts.get_text("PRESS_ESCAPE_TO_MAIN_MENU")} '
        text = f'[color=darker yellow]{text}[/color]'
        box.add(text, MenuAlignement.CENTER)
        menu_contents.append(box)

        self.menu_contents = menu_contents
Beispiel #7
0
def terminal_set_color(alpha, color):
    color_argb = colors.convert_argb(alpha, color)
    terminal.color(
        terminal.color_from_argb(a=color_argb[0],
                                 r=color_argb[1],
                                 g=color_argb[2],
                                 b=color_argb[3]))
Beispiel #8
0
def draw_actor_stats(actor):
    r = settings.gui_rect
    terminal.color('azure')

    draw_rect(r)

    x = r.left + 2
    y = r.top + 2
    width = r.width - 4

    draw_gui_stat(actor.fighter.hp, x, y, width, settings.hp_colors)

    y += 3
    draw_gui_stat(actor.fighter.water, x, y, width, settings.water_colors)

    y += 3
    draw_gui_stat(actor.fighter.food, x, y, width, settings.food_colors)

    y += 3
    draw_gui_stat(actor.fighter.fatigue, x, y, width,
                  colors.get_bright_range(colors.brown))

    y += 3
    terminal.print_(x, y, "Position: {}x{}".format(actor.x, actor.y))

    y += 4
    terminal.color("#AA6939")
    terminal.print_(x, y, "Inventory:")
    draw_double_line(x, y + 1, width)
    draw_mini_inventory(actor.inventory, x, y + 3, width)
Beispiel #9
0
    def update(self):
        if self.owner:
            layer = self.owner.layer
            x = self.owner.pos.x
            y = self.owner.pos.y
        else:
            layer = terminal.state(terminal.TK_LAYER)
            x = 0
            y = 0

        if mouse.clicked_rect(self.x + x, self.y + y, self.length, 1):
            terminal.layer(layer)
            terminal.color('white')
            terminal.puts(self.x + 1 + x, self.y + y,
                          self.skin['BACKGROUND'] * self.length)
            terminal.color('black')
            terminal.refresh()
            result, text = terminal.read_str(self.x + x + 1, self.y + y,
                                             self.text, self.length)
            terminal.refresh()
            if text.isnumeric() and (self.min_val <= int(text) <=
                                     self.max_val):
                self.text = str(text)
                self.error = None
                self.updated = True
            else:
                self.error = 'Text must be numeric and between ' + str(
                    self.min_val) + ' and ' + str(self.max_val) + '.'

            self.active = True
            self.dirty = True
Beispiel #10
0
def test_layers():
    blt.set("window.title='Omni: layers'")

    pixel = c_uint32(blt.color_from_name("dark gray"))

    blt.set("U+E000: %d, raw-size=1x1, resize=48x48, resize-filter=nearest" % addressof(pixel))

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

    blt.puts(2, 1, "[color=orange]1.[/color] Without layers:")
    blt.put(7, 3, 0xE000)   
    blt.puts(5, 4, "[color=dark green]abcdefghij")

    blt.puts(2, 8, "[color=orange]2.[/color] With layers:")
    blt.layer(1)
    blt.put(7, 10, 0xE000)
    blt.layer(0)
    blt.puts(5, 11, "[color=dark green]abcdefghij")

    blt.refresh()

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

    blt.set("U+E000: none")
Beispiel #11
0
 def draw(self):
     x = self.top
     frame_height = self.height
     scrollbar_height = self.scrollbar_height
     frame_offset = self.offset
     messages_len = self.contents.total_height
     cell_height = blt.state(blt.TK_CELL_HEIGHT)
     blt.color(self.color)
     self.scrollbar_column = self.left + self.width
     self.scrollbar_offset = int(
         (x + (frame_height - scrollbar_height) * (1 - frame_offset / (messages_len - frame_height + 1)))
         * cell_height)
     # top line
     for i in range(self.left - 1, self.left + self.width + 2):
         blt.put(i, self.top - 1, '+')
     # bottom line
     for i in range(self.left - 1, self.left + self.width + 2):
         blt.put(i, self.top + self.height, '+')
     # left line
     for i in range(self.top - 1, self.top + self.height + 1):
         blt.put(self.left - 1, i, '+')
     # right line
     for i in range(self.top - 1, self.top + self.height + 1):
         blt.put(self.left + self.width + 1, i, '+')
     # scrollbar
     for i in range(self.scrollbar_height):
         blt.put_ext(self.scrollbar_column, i, 0, self.scrollbar_offset, 0x2588)
Beispiel #12
0
def set_bkcolour(rgb, alpha=255):
    """Wrapper for the bearlibterminal bkcolor method, so I can spell properly"""
    hexcolour = alpha
    hexcolour = hexcolour * 256 + rgb[0]
    hexcolour = hexcolour * 256 + rgb[1]
    hexcolour = hexcolour * 256 + rgb[2]
    t.color(hexcolour)
Beispiel #13
0
def test_multiple_fonts():
    blt.set("window.title='Omni: multiple fonts in scene'")

    # Load several fonts
    blt.set("window.size=64x20; font: ../Media/VeraMono.ttf, size=10x20")
    blt.set("italic font: ../Media/VeraMoIt.ttf, size=10x20")
    blt.set("bold font: ../Media/VeraMoBd.ttf, size=10x20")
    blt.set("huge font: ../Media/VeraMono.ttf, size=20x40, spacing=2x2")

    blt.clear()
    blt.color("white")
    _, h = blt.puts(
        2,
        1, "If you [color=orange][font=italic]really[/font][/color] want, "
        "you can even put [color=orange][font=bold]emphasis[/font][/color] on a text. "
        "This works by loading several truetype tilesets with custom codepages to an "
        "unused code points and using [color=orange]font[/color] postformatting tag.",
        width=60)

    blt.puts(2,
             1 + h + 1,
             "[font=huge]It's pretty easy to print in bigger fonts as well.",
             width=60)
    blt.refresh()

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

    # Clean up
    blt.set(
        "window.size=80x25; font: default; italic font: none; bold font: none; huge font: none"
    )
Beispiel #14
0
def draw_rect(dest, x, y, w, h, frame=False, f_color=None, bk_color=None, title=None):
    terminal.layer(dest)

    if title:
        offset_x1 = ((w - len(title)) / 2) + 1
        offset_x2 = (w - len(title)) - (offset_x1 - 2)
    else:
        offset_x1 = w
        offset_x2 = 0

    for x1 in range(w):
        for y1 in range(h):
            terminal.color(bk_color)
            draw_char(dest, x1 + x, y1 + y, Utils.get_unicode(219))
            if frame:
                terminal.color(f_color)
                if (x1, y1) == (0, 0):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_NW)
                elif (x1, y1) == (w - 1, 0):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_NE)
                elif (x1, y1) == (0, h - 1):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_SW)
                elif (x1, y1) == (w - 1, h - 1):
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_SE)
                elif x1 == 0 or x1 == w - 1:
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_E)
                elif (y1 == 0 and (offset_x1-1 > x1 or x1 > w - offset_x2)) or y1 == h - 1:
                    draw_char(dest, x1 + x, y1 + y, Constants.BOX_N)
    if title:
        print_line(dest, x + (w / 2), y, "[wrap={0}x{1}][align=center-center]{2}".format(w, h, title))
Beispiel #15
0
    def update(self):
        if self.owner:
            layer = self.owner.layer
            x = self.owner.pos.x
            y = self.owner.pos.y
        else:
            layer = terminal.state(terminal.TK_LAYER)
            x = 0
            y = 0

        if mouse.clicked_rect(self.x + x, self.y + y, self.length, 1):
            terminal.layer(layer)
            terminal.color('white')
            terminal.puts(self.x + 1 + x, self.y + y,
                          self.skin['BACKGROUND'] * self.length)
            terminal.color('black')
            terminal.refresh()
            result, text = terminal.read_str(self.x + x + 1, self.y + y,
                                             self.text, self.length)
            terminal.refresh()
            self.text = text
            self.updated = True

            self.active = True
            self.dirty = True
Beispiel #16
0
def render_map_con(entities, players, game_map, width, height, ox=0, oy=0) -> None:
    terminal.layer(0)
    for player in players:
        for y in range(game_map.height):
            for x in range(game_map.width):   
                #Show if it's visible
                if (x,y) in player.fighter.fov_visible:
                    terminal.color('light amber')
                    terminal.put(x+ox, y+oy, 0x2588)
                    if (x,y) in player.fighter.fov_wall:
                        terminal.color('dark gray')
                        terminal.put(x+ox, y+oy, 0x2588)
                #Not visible but explored
                elif (x,y) in player.fighter.fov_explored:
                    if (x,y) in player.fighter.fov_wall:
                        terminal.color('darker gray')
                        terminal.put(x+ox, y+oy, 0x2588)
                    else:
                        terminal.color('darker amber')
                        terminal.put(x+ox, y+oy, 0x2588)
                #Not explored                     
                else:
                    terminal.color('dark gray')
                    terminal.put(x+ox, y+oy, 0x2588)
    


    print_entities(entities, ox, oy)
Beispiel #17
0
def mainloop():
    #main values
    closed = False
    gameType = 0  # 0 - default/ 1 - fight/ 2 - inventory/ 3 - map/ 4 - dialogue/6/7/8/9
    debug_value = 0
    debug_string = (" debug")
    screen_width = 120
    screen_height = 40
    BASE_damage = 5
    #player values
    map_x = 0
    map_y = 0
    player_infight = False
    player_alive = True
    player_lvl = 1
    player_EXP = 0
    player_stat1 = 5
    player_stat2 = 5
    player_stat3 = 5
    blt.set("window.title='pythonRPG'")
    blt.clear()
    blt.color("white")
    debug_view = ("[color=orange]Debug string:" + debug_string + "[/color]]"
                  )  #make string in puts rather than
    blt.puts(2, 3, debug_view)  #create another variable
    blt.refresh()
    while closed == False:
        blt.refresh()
Beispiel #18
0
    def print_stats(self,
                    hp: int = None,
                    tp: int = None,
                    tick: int = None,
                    left_arrow: bool = False,
                    right_arrow: bool = False):

        color = bearlib.state(bearlib.TK_COLOR)
        corner = self.map.view_rect.point_bottom_left
        bearlib.clear_area(corner.x, corner.y + 1, self.window.width,
                           self.window.height - corner.y + 1)

        if hp is None:
            hp = self.player.hp
        if tp is None:
            tp = self.player.tp
        hp_string = f'HP: {"|" * hp}{" " * (self.player.max_hp - self.player.hp)} '\
                    f'({self.player.hp}/{self.player.max_hp})'
        tp_string = f'MP: {"|" * tp}{" " * (self.player.max_tp - self.player.tp)} '\
                    f'({self.player.tp}/{self.player.max_tp})'
        xp_string = f'XP: {self.player.xp} - Level {self.player.level}'
        time_string = f'{"<" if left_arrow else " "}Time: {self.time.clock(tick)}{">" if right_arrow else ""}'
        bearlib.color(Color.RED)
        self.pprint(corner.x, corner.y + 1, hp_string)
        bearlib.color(Color.VIOLET)
        self.pprint(corner.x, corner.y + 2, tp_string)
        bearlib.color(Color.YELLOW)
        self.pprint(corner.x, corner.y + 3, xp_string)
        bearlib.color(color)
        self.pprint(corner.x, corner.y + 4, time_string)
        bearlib.color(self.window.fg_color)
Beispiel #19
0
def render_status_con(entities, players, game_map, width, height, con_type, log, ox=0, oy=0):
    if con_type == 1: entity = players[0]
    else:
        try:
            entity = players[0].fighter.targets[0]
        except:
            entity = None
           
    #Print paper dolls
    terminal.puts(ox, oy, '[font=text][color=white][bg_color=black]Hit Location')
    terminal.puts(ox+15, oy, '[font=text][color=white][bg_color=black]DERM')
    terminal.puts(ox+20, oy, '[font=text][color=white][bg_color=black]TIS')
    terminal.puts(ox+25, oy, '[font=text][color=white][bg_color=black]BONE')

    if entity is not None:
        p_y = 1
        for hit_location in entity.fighter.locations:
            terminal.color('white')
            terminal.puts(ox, oy+p_y, '[font=text]'+entity.fighter.name_location(p_y-1) + ':')
            terminal.puts(ox+15, oy+p_y, '[font=text]'+str(hit_location[0]))
            terminal.puts(ox+20, oy+p_y, '[font=text]'+str(hit_location[1]))
            terminal.puts(ox+25, oy+p_y, '[font=text]'+str(hit_location[2]))
            p_y += 1

    if con_type == 1: #Print char con
        s_y = 50
        for message in log.messages:
            terminal.puts(ox, oy+s_y, '[font=text]'+message.text)
            s_y += 1
Beispiel #20
0
    def animate(self, current_map, animations, camera, config, animation_data):
        # Scale color based on ticks left.
        terminal.font("main")
        color = animation_data['attack']['color_fg']['attacked'][:]
        color[0] += (self.ticks*5)

        # Put an indicator around attacker.
        terminal.color(terminal.color_from_argb(*animation_data['attack']['color_fg']['attacker']))
        dx, dy = camera.to_camera_coords(self.actor.x, self.actor.y)
        terminal.put(dx*config['tile_spacing_x'], dy*config['tile_spacing_y'],
                     animation_data['attack']['image']['attacker'])

        # Put an indicator around attacked target, fades based on amount of ticks left.
        terminal.color(terminal.color_from_argb(*color))
        dx, dy = camera.to_camera_coords(self.target.x, self.target.y)
        terminal.put(dx*config['tile_spacing_x'], dy*config['tile_spacing_y'], 
                     animation_data['attack']['image']['attacked'])

        # Make sure background stays the default color.
        terminal.bkcolor(terminal.color_from_argb(0, 0, 0, 0))

        # Remove animation once its maximum ticks are reached.
        if self.ticks <= 0:
            animations.remove(self)

        self.ticks -= 1
Beispiel #21
0
    def draw_messages(self):
        terminal.bkcolor(0xFF000000)
        terminal.color(0xFFFFFFFF)

        # Load new messages into a list
        messages = []
        for entity, message in self.world.get_component(Message):
            messages.append(message)
            self.world.delete_entity(entity)

        # Sort by priority
        messages.sort(key=lambda m: m.priority, reverse=True)

        prefix = "[color=#FF666666]>[/color] "
        for index, message in enumerate(messages):
            self.buffer.append(prefix + message.text)
            prefix = "  "

        self.buffer = self.buffer[-14:]
        s = "\n".join(self.buffer)
        w, h = terminal.measure(s, 50, 14)

        if h < 14:
            align = terminal.TK_ALIGN_TOP
        else:
            align = terminal.TK_ALIGN_BOTTOM

        terminal.puts(x=34, y=7, s=s, width=50, height=14, align=align)
Beispiel #22
0
    def update_widget(self, widget, refresh=False):
        """
        Actually draw widget chars on screen.

        If ``widget.chars`` or ``widget.colors`` have changed, this method will
        make these changes visible. It is also called by ``self.add_widget()``
        and other methods that have a ``refresh`` argument.

        :param widget: A widget to be updated.
        """
        if widget not in self.widget_locations:
            raise BearException('Cannot update non-added Widgets')
        pos = self.widget_locations[widget].pos
        layer = self.widget_locations[widget].layer
        terminal.layer(layer)
        terminal.clear_area(*self.widget_locations[widget].pos, widget.width, widget.height)
        running_color = self.default_color
        for y in range(widget.height):
            for x in range(widget.width):
                # Widget can have None as color for its empty cells
                if widget.colors[y][x] and widget.colors[y][x] != running_color:
                    running_color = widget.colors[y][x]
                    terminal.color(running_color)
                terminal.put(pos[0] + x, pos[1] + y, widget.chars[y][x])
                self._widget_pointers[layer][pos[0] + x][pos[1] + y] = widget
        if running_color != self.default_color:
            terminal.color(self.default_color)
        if refresh:
            self.refresh()
Beispiel #23
0
    def paste_on_window(self, x, y, width):
        mut_y = y
        max_y = self.get_height()

        previous_color = terminal.color(terminal.TK_COLOR)
        draw_background(x - self.margin,
                        y - self.margin,
                        width + x + (2 * self.margin),
                        y + max_y + self.margin,
                        'gray',
                        bordure=False)
        terminal.color(previous_color)
        best_cx = 0
        for content, alignement in self.content:
            if alignement == MenuAlignement.CENTER:
                content_without_color = remove_color_tag(content)
                cx = self.get_center_point(width, len(content_without_color))
                if not best_cx:
                    best_cx = cx
                else:
                    if cx < best_cx:
                        best_cx = cx

        for content, alignement in self.content:
            print(f'content is {content} with {best_cx + x}, mut_y {mut_y}')
            print_shadow(best_cx + x, mut_y, content)
            mut_y += 1
Beispiel #24
0
def draw_menu_option_state(lst):
    terminal.clear_area(30, 14, 60, 30)
    terminal.color("yellow")
    terminal.print_(30, 14, "Screen size")
    draw_double_line(30, 15, len("Screen size"))
    draw_select_box(lst, 30, 16)
    terminal.refresh()
Beispiel #25
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")
 def draw(self, xy: vec, layer: int = 0) -> None:
     blt.layer(layer)
     blt.color(self.fg_colour.blt_colour())
     if self.bg_colour is not None:
         blt.bkcolor(self.bg_colour.blt_colour())
     xy = xy + self.xy
     blt.put(xy.x, xy.y, self.char)
Beispiel #27
0
    def _render(self, offset: (int, int) = (0, 0)):
        """Renders the text of the selector."""
        sets = Settings()

        # Position
        x, y = offset
        x += self._x
        y += self._y

        # Text and color
        text = self._text
        fg = sets.colors['default_fg']
        bg = sets.colors['default_bg']

        # Active highlight
        if self.active:
            if self._mode == Highlight.INVERT:
                bg = sets.colors['default_fg']
                fg = sets.colors['default_bg']
            elif self._mode == Highlight.COLOR:
                fg = sets.colors['highlight_fg']
            elif self._mode == Highlight.ASTERISK:
                text = "* " + text
            elif self._mode == Highlight.DASH:
                text = "- " + text

        #console.print(x+self._x, y+self._y, self._text, fg=sets.colors['default_fg'], bg=sets.colors['default_bg'], alignment=self._align)
        # BearLibTerm print
        terminal.color(fg)
        terminal.bkcolor(bg)
        terminal.puts(x, y, text, *self.size,
                      self._horiz_align.value + self._vert_align.value)
Beispiel #28
0
    def draw(self):
        terminal.font('text')
        if not self.selected:
            terminal.color(terminal.color_from_argb(*self.color))
        else:
            terminal.color(terminal.color_from_argb(*self.selected_color))

        terminal.printf(self.x1, self.y1, self.text, terminal.TK_ALIGN_DEFAULT)
Beispiel #29
0
 def render(self):
     self.frame += 1
     if self.frame % 5 == 0:
         self.animate()
     term.layer(1)
     term.color(term.color_from_argb(255, *COLOR['WHITE']))
     term.put(self.center[X], self.center[Y], self.picture)
     super(MenuPanel, self).render()
Beispiel #30
0
 def draw(self, cell, panelPos):
     i = 0
     for color, tile in zip(cell.color, cell.stack):
         if tile is not None:
             term.layer(i)
             term.color(term.color_from_argb(255, *color))
             term.put(panelPos[X], panelPos[Y], tile)
         i += 1
Beispiel #31
0
def draw_char(x, y, char, color, layer):
    old_layer = terminal.TK_LAYER
    old_color = terminal.TK_COLOR
    terminal.layer(layer)
    terminal.color(color)
    terminal.printf(x, y, char)
    terminal.color(old_color)
    terminal.layer(old_layer)
Beispiel #32
0
 def _print_button(self, position):
     text = self.button_names[position]
     x = self.init_coord_x
     y = self.init_coord_y + position
     if self.position == position:
         terminal.color(TERMINAL_COLOR_LIGHTED)
     terminal.printf(x, y, text)
     terminal.color(TERMINAL_COLOR_NORMAL)
Beispiel #33
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()
Beispiel #34
0
def draw_char_ex(dest, x, y, dx, dy, char, color=None, flag=None, alpha=255):
    # LIBTCOD
    # libtcod.console_put_char_ex(dest, x, y, char, color, flag)

    # BEARLIB
    terminal.layer(dest)
    # TODO: CONVERT COLORS ON THEME IMPORT, INSTEAD OF INLINE (all render func)
    if color is not None:
        #color = Utils.convert_color(color, alpha)
        terminal.color(color)
    terminal.put_ext(x, y, dx, dy, char, None)
Beispiel #35
0
def set_foreground(dest, color):
    # LIBTCOD
    # libtcod.console_set_default_foreground(dest, color)
    # BEARLIB
    # TODO: Replace / Obsolete?
    #color = Utils.convert_color(color)
    #print color
    try:
        terminal.color(color)
    except:
        print "ERROR!"
        print color
Beispiel #36
0
def draw_char(dest, x, y, char, color=None, flag=None, alpha=255, verbose=False):
    # LIBTCOD
    # libtcod.console_put_char_ex(dest, x, y, char, color, flag)

    #BEARLIB
    terminal.layer(dest)
    # TODO: CONVERT COLORS ON THEME IMPORT, INSTEAD OF INLINE (all render func)
    if color is not None:
        if verbose:
            print color
            print int(color)
            print color.getRGB()
        #color = Utils.convert_color(color, alpha)
        #print "Color: {0}".format(color)
        #print "In DrawChar Color: {0}".format(color)
        terminal.color(color)
    terminal.put(x, y, char)
Beispiel #37
0
def test_basic_output():
    blt.set("window.title='Omni: basic output'")
    blt.clear()
    blt.color("white")

    # Wide color range
    n = blt.print_(2, 1, "[color=orange]1.[/color] Wide color range: ")
    long_word = "antidisestablishmentarianism."
    long_word_length = len(long_word)
    for i in range(long_word_length):
        factor = i / long_word_length
        red = int((1 - factor) * 255)
        green = int(factor * 255)
        blt.color(blt.color_from_argb(255, red, green, 0))
        blt.put(2 + n + i, 1, long_word[i])

    blt.color("white")

    blt.print_(2, 3, "[color=orange]2.[/color] Backgrounds: [color=black][bkcolor=gray] grey [/bkcolor] [bkcolor=red] red ")

    blt.print_(2, 5, "[color=orange]3.[/color] Unicode support: Кириллица Ελληνικά α=β²±2°")

    blt.print_(2, 7, "[color=orange]4.[/color] Tile composition: @ + [color=red]|[/color] = @[+][color=red]|[/color], a vs. ¨ a[+][color=red]¨[/color]")

    blt.printf(2, 9, "[color=orange]5.[/color] Box drawing symbols:")

    blt.print_(5, 11,
        "   ┌────────┐  \n"
        "   │!......s└─┐\n"
        "┌──┘........s.│\n"
        "│............>│\n"
        "│...........┌─┘\n"
        "│<.@..┌─────┘  \n"
        "└─────┘  ■█┘╙       \n"
    )





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

    while True:
        # Engine.Input.clear()
        Engine.Input.update()
        key = Engine.Input.key
        terminal.clear()
        terminal.color('white')
        # terminal.print_(terminal.state(terminal.TK_MOUSE_X), terminal.state(terminal.TK_MOUSE_Y),"HellowWorld")
        #test_anim.draw(terminal.state(terminal.TK_MOUSE_X),terminal.state(terminal.TK_MOUSE_Y))

        if key == terminal.TK_MOUSE_LEFT:
            x, y = terminal.state(terminal.TK_MOUSE_X), terminal.state(terminal.TK_MOUSE_Y)
            # animations.append(create_anim(x,y, Utils.heat_map_chrs, Utils.explosion_colors, number=50))
            #animations.append(Engine.Animation_System.Flame(x, y, size=25, density=70))
            choice = random.randint(0,5)

            # Engine.Animation_System.(Engine.Animation_System.A_FLAME, **kwargs)

            #choice = 0
            print choice

            # TODO: Cleaup Call. ADD KWARG support, Accept POS(x, y) instead of x,y. make all default variables overrideable via Kwargs

            animation_params={
                'origin': (x, y),
                'target': (x, y)
            }

            if choice == 0:
                    animations.append(
                            Engine.Animation_System.Animation('Flame', animation_params))   # , angle=random.randint(270, 270)))
            if choice == 1:
                    animations.append(
                            Engine.Animation_System.Animation('Burst', animation_params))
            if choice == 4:
                    animations.append(
                            Engine.Animation_System.Animation('Line', animation_params))
            if choice == 2:
                    animations.append(
                            Engine.Animation_System.Animation('IceBreath', animation_params))
            if choice == 3:
                    animations.append(
                            Engine.Animation_System.Animation('TinyFire', animation_params))
            if choice == 5:
                    animations.append(
                            Engine.Animation_System.Animation('Xmas', animation_params))

            #print len(animations)

        Render.draw_char(0, 15,15, '@')
        terminal.color('han')
        Render.draw_char(0, 17, 15, 'T')

        for ani in animations:
            result = ani.play()
            if result == 'Done':
                print "Want?"
                animations.remove(ani)

        #print len(animations)

        terminal.refresh()
Beispiel #39
0
def set_foreground(dest, color):
    # LIBTCOD
    # libtcod.console_set_default_foreground(dest, color)
    # BEARLIB
    color = Utils.convert_color(color)
    terminal.color(color)
Beispiel #40
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)