Пример #1
0
    def print(self, lighted=False):

        # Подсветка текущей позиции
        current_bgcolor = get_bgcolor(lighted)
        terminal.bkcolor(current_bgcolor)

        # Сначала левую часть
        x = 0
        y = self.height
        text = self.left_text
        terminal.printf(x, y, text)

        # Потом правую
        x = self.right_text_start_position
        y = self.height
        text = self.right_text
        terminal.printf(x, y, text)

        # Возвращаем подсветку, как было
        terminal.bkcolor(bgcolor)

        # Стираем старую подсказку и печатаем новую
        self.clear_hint()
        self.print_hint()

        # И обновляем экран
        terminal.refresh()
Пример #2
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")
Пример #3
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
Пример #4
0
    def diagonal(self):
        if not self.player.has_skill(Diagonal):
            return

        if self.player.tp < self.player.diagonal_cost:
            self.scene.log(
                f"You don't have enough mana to cast Event Horizon.")
            return False

        targets = self.scene.map.diagonals(self.player.position)
        bearlib.bkcolor(Color.YELLOW)
        for target in targets:
            target.draw_tile(self.context)
        bearlib.bkcolor(self.window.bg_color)
        bearlib.refresh()

        key = bearlib.read()
        while key != bearlib.TK_ESCAPE:
            if key == bearlib.TK_ENTER or key == bearlib.TK_SPACE:
                enemies = []
                for target in targets:
                    for entity in target.entities:
                        if entity.type == EntityType.ENEMY:
                            enemies.append(entity)
                        break
                self.player.delta_tp -= self.player.diagonal_cost
                self.player.update_tp()

                for enemy in enemies:
                    enemy.delta_hp -= self.player.diagonal_damage
                    enemy.update_hp()
                self.scene.log(
                    f'You conjure a swarm of ephemeral black holes.')
                return True
            key = bearlib.read()
Пример #5
0
    def renderGame(self, map):
        term.bkcolor(term.color_from_argb(255, 25, 25, 25))
        term.clear()

        for panel in self.main.panel:
            self.main.panel[panel].render()
        term.refresh()
Пример #6
0
def set_background(dest, color):
    # LIBTCOD
    # libtcod.console_set_default_background(dest, color)
    # BEARLIB
    # TODO: Replace / Obsolete?
    #color = Utils.convert_color(color)
    terminal.bkcolor(color)
Пример #7
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)
Пример #8
0
    def freeze(self):
        if not self.player.has_skill(Freeze):
            return False

        if self.player.tp < self.player.freeze_cost:
            self.scene.log(f"You don't have enough mana to cast freeze.")
            return False

        target_square = self.scene.map.find_in_bounds_orthogonal(
            self.player.position)
        bearlib.bkcolor(Color.BLUE)
        self.scene.map.floor.cell(target_square).draw_tile(self.context)
        bearlib.bkcolor(self.window.bg_color)
        bearlib.refresh()

        key = bearlib.read()
        while key != bearlib.TK_ESCAPE:
            if key == bearlib.TK_ENTER or key == bearlib.TK_SPACE:
                target_tile = self.scene.map.floor.cell(target_square)
                enemy = None
                for entity in target_tile.entities:
                    if entity.type == EntityType.ENEMY:
                        enemy = entity
                        break
                if enemy is not None:
                    self.player.delta_tp -= self.player.freeze_cost
                    turns = randrange(1, 3)
                    # +1 -- Account for this current turn
                    enemy.freeze(turns + 2)
                    enemy.delta_hp -= self.player.freeze_damage
                    enemy.update_hp()
                    self.scene.log(
                        f'You freeze the {enemy.name} in suspended animation. {enemy.hp}/{enemy.max_hp}'
                    )
                    return True
                else:
                    self.scene.log("There's nothing there to freeze.")
                    return False
            try:
                direction = Direction(key)
            except ValueError:
                key = bearlib.read()
                continue

            # Clears background from previous tile.
            target_tile = self.scene.map.floor.cell(target_square)
            bearlib.bkcolor(self.window.bg_color)
            target_tile.draw_tile(self.context)

            delta = self.__delta_map[direction]
            target_square = self.player.position + delta
            target_tile = self.scene.map.floor.cell(target_square)
            bearlib.bkcolor(Color.BLUE)
            target_tile.draw_tile(self.context)
            for entity in target_tile.entities:
                entity.draw(self.context)
            bearlib.bkcolor(self.window.bg_color)
            bearlib.refresh()

            key = bearlib.read()
Пример #9
0
 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)
Пример #10
0
def draw_background(dest, x, y, color, flag=libtcod.BKGND_SET):
    # LIBTCOD
    # libtcod.console_set_char_background(dest, x, y, color, flag)
    # BEARLIB
    color = Utils.convert_color(color)
    terminal.bkcolor(color)
    terminal.put(x, y, terminal.pick(x, y, 0))
Пример #11
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)
Пример #12
0
 def terminal_update(self, is_active=False):
     terminal.bkcolor('#000000')
     self.view.frame = self.view.frame.with_size(
         Size(blt_state.width, blt_state.height))
     self.view.perform_layout()
     self.view.perform_draw(self.ctx)
     terminal.bkcolor('#000000')
Пример #13
0
def draw_view_item_window(lst, item: Item):
    rect = Rect.from_rect(settings.gui_rect)
    draw_window(rect, item.description, colors.white,
                colors.inventory_bk_color)
    terminal.bkcolor(colors.inventory_bk_color)
    draw_select_box(lst, rect.x + 1, rect.y + 3)
    terminal.refresh()
Пример #14
0
def render_all(entities, gamemap):
    #blt.clear()
    # Draw all the tiles in the game map
    blt.layer(0)
    blt.bkcolor("black")
    for y in range(gamemap.height):
        for x in range(gamemap.width):
            blt.puts(
                x, y, "[color=%s]%s[/color]" %
                (gamemap.tiles[x][y].color, gamemap.tiles[x][y].char))

    blt.layer(100)
    # Draw all entities in the list
    for entity in entities:
        draw_entity(entity)

    # Draw all items on the list
    blt.layer(10)
    for i in items:
        draw_item(i)

    blt.layer(255)

    draw_UI()
    blt.layer(254)
    blt.puts(0, 49, "[color=lighter yellow]%s[/color]" % fps_value)
    DrawReticle()

    ### Draw animations

    blt.refresh()
Пример #15
0
def render_tactical_panel(x, y, total_width, total_height, entities, player):
    terminal.layer(0)
    target = ''
    for ent in entities:
        if ent.combatship:
            if ent.combatship.targeted:
                target = ent
                break
    initialize_with_bkcolor('black', 'darkest azure', total_width,
                            total_height, x, y)
    draw_panel_box('white', total_width, total_height, x, y)
    terminal.print_(int(x + total_width / 2 - len('TACTICAL PANEL (t)') / 2),
                    y, 'TACTICAL PANEL (t)')
    if target:
        target_name = target.name
        target_hull = target.combatship.hull
        target_shields = target.combatship.shields
        target_armament = target.inventory.items
    else:
        target_name = 'None'
        target_hull = r'N/A'
        target_shields = r'N/A'
        target_armament = []
    terminal.print_(x + 1, y + 2, 'Target: {}'.format(target_name))
    terminal.print_(x + 1, y + 3, 'Hull: {}'.format(target_hull))
    terminal.print_(x + 1, y + 4, 'Shields: {}'.format(target_shields))
    terminal.print_(x + 1, y + 6, 'Armament:')
    for cnt, wpn in enumerate(target_armament):
        terminal.print_(x + 1, y + 7 + cnt, '  ' + wpn.name)
    terminal.bkcolor('black')
Пример #16
0
def mpGameLoop(client):
    _map = Map(70, 50)
    player = client.players[client.name]
    mapReady = False
    while True:
        client.Loop()
        if client.msgQ.qsize() > 0:
            msg = client.msgQ.get()
            if msg['action'] == 'gameMap':
                _map.mapFrom(msg['gameMap'])
                mapReady = True
                playerx, playery = _map.findPlayerLoc()
                player.x = playerx
                player.y = playery
                terminal.clear()
                _map.do_fov(player.x, player.y, constants.FOV_RADIUS)
        if mapReady:
            _map.render_map()
            terminal.layer(1)
            for k, v in client.players.items():
                v.draw()
            terminal.refresh()
            terminal.layer(1)
            for k, v in client.players.items():
                v.clear()
            ex = handle_keys(player, _map.game_map)
            if ex == 1:
                _map.do_fov(player.x, player.y, constants.FOV_RADIUS)
                client.Send({
                    'action': 'posUpdate',
                    'posUpdate': [player.x, player.y]
                })
            if ex == 2:
                terminal.bkcolor(black)
                break
Пример #17
0
def _render_room(blueprint, openings, room, conjunction_point):
    # Draw the currently pending room
    blt.clear()
    room.render(ANIMATION_RENDERER)
    blt.bkcolor(colors.CLEAR)
    blt.refresh()
    time.sleep(ANIMATION_FRAME_LENGTH / 1000)

    # If it was added successfully, show the world with its new addition.
    if conjunction_point is not None:
        blt.clear()

        ANIMATION_CAMERA.move_to(conjunction_point[0], conjunction_point[1])
        ANIMATION_RENDERER.transform(ANIMATION_CAMERA)

        for y in range(len(blueprint)):
            for x in range(len(blueprint[0])):
                blueprint[y][x].render(x, y, ANIMATION_RENDERER)

        for (x, y) in openings:
            ANIMATION_RENDERER.render(
                x, y, Symbol(' ', blt.color_from_name("white")), 0,
                colors.WORLD_GEN_OPENING)
        blt.bkcolor(colors.CLEAR)
        blt.refresh()
        time.sleep(ANIMATION_FRAME_LENGTH / 1000)

        ANIMATION_CAMERA.move_to(0, 0)
        ANIMATION_RENDERER.transform(ANIMATION_CAMERA)
Пример #18
0
def print_level(levels, level_n):
    """Отображает уровень."""
    level = levels[level_n].level
    start = levels[level_n].start
    end = levels[level_n].end

    dx, dy = 15, 0
    for y in range(50):
        for x in range(50):
            terminal.layer(0)
            if level[x][y].block:
                terminal.bkcolor(color["wall"])
                terminal.put(dx, dy, ' ')
            else:
                terminal.bkcolor(color["flor"])
                terminal.put(dx, dy, '.')

            terminal.layer(2)
            terminal.bkcolor(color["flor"])
            if len(level[x][y].item_on_me) > 0:
                for item in level[x][y].item_on_me:
                    terminal.put(dx, dy, item.char)
            dx += 1
        dx = 15
        dy += 1
    terminal.layer(1)
    terminal.bkcolor(color["flor"])
    terminal.printf(start.x1 + 15, start.y1, '>')
    terminal.printf(end.x1 + 15, end.y1, '<')
    terminal.layer(0)

    terminal.bkcolor(color["black"])
Пример #19
0
def draw_background(dest, x, y, color, flag=libtcod.BKGND_SET):
    # LIBTCOD
    # libtcod.console_set_char_background(dest, x, y, color, flag)
    # BEARLIB
    color = Utils.convert_color(color)
    terminal.bkcolor(color)
    terminal.put(x, y, terminal.pick(x,y, 0))
Пример #20
0
def set_background(dest, color):
    # LIBTCOD
    # libtcod.console_set_default_background(dest, color)
    # BEARLIB
    # TODO: Replace / Obsolete?
    #color = Utils.convert_color(color)
    terminal.bkcolor(color)
Пример #21
0
 def put(self, x: int, y: int, code: int, fg: str = None, bg: str = None):
     if fg:
         terminal.color(fg)
     if bg:
         terminal.bkcolor(bg)
     terminal.put(x + self.x, y + self.y, code)
     terminal.color("white")
     terminal.bkcolor("black")
Пример #22
0
 def draw(self):
     """Рисует существо."""
     self.bkcolor = terminal.pick_bkcolor(self.x, self.y)
     terminal.bkcolor(self.bkcolor)
     terminal.layer(self.layer_draw)
     terminal.put(self.x, self.y, self.char)
     terminal.layer(0)
     terminal.bkcolor(color["black"])
Пример #23
0
 def print(self, lighted=False):
     current_bgcolor = get_bgcolor(lighted)
     height = self.height
     text = self.normilized_text
     terminal.bkcolor(current_bgcolor)
     terminal.printf(start_position_x, height, text)
     terminal.bkcolor(bgcolor)
     terminal.refresh()
Пример #24
0
def draw_star(star, fov_map):
    visible = libtcod.map_is_in_fov(fov_map, star[0], star[1])
    if visible:
        terminal.bkcolor('darkest grey')
    terminal.color(star[2])
    terminal.print_(star[0], star[1], '.')
    terminal.color('black')
    terminal.bkcolor('black')
Пример #25
0
def initialize_with_bkcolor(old_color, new_color, width, height, startx,
                            starty):
    terminal.bkcolor(new_color)
    terminal.color('white')
    for i in range(width):
        for j in range(height):
            terminal.print_(startx + i, starty + j, ' ')
    terminal.bkcolor(old_color)
Пример #26
0
    def draw_entities(self):
        for _, (player, player_position) in self.world.get_components(
                Player, Position):
            # Set player offset relative to display
            x_offset = 16 - player_position.x
            y_offset = 10 - player_position.y

            # Set the bounding box for filtering out entities
            x_min = player_position.x - 16
            x_max = player_position.x + 16
            y_min = player_position.y - 10
            y_max = player_position.y + 10

            entity_pairs = self.world.get_components(Display,
                                                     LastKnownPosition)

            if not entity_pairs:
                return

            entity_pairs.sort(key=lambda pair: pair[1][0].draw_order)

            for entity, (display, position) in entity_pairs:
                if not x_min <= position.x <= x_max or not y_min <= position.y <= y_max:
                    continue

                if self.world.has_component(entity, Visible):
                    bkcolor = 0xFF100800
                    color = display.color

                    bkcolor = filter_color(bkcolor, player)
                    color = filter_color(color, player)
                else:
                    bkcolor = 0xFF000000
                    color = 0xFF666666

                if self.world.has_component(entity, Blinded):
                    bkcolor = 0xFFFFFFFF
                    color = 0xFF000000

                    bkcolor = filter_color(bkcolor, player)
                    color = filter_color(color, player)

                terminal.bkcolor(bkcolor)
                terminal.color(color)

                # Render assassins as underscores until they are in range
                if self.world.has_component(
                        entity, Assassin) and not self.world.has_component(
                            entity, Adjacent):
                    code = 0x005F
                else:
                    code = display.code

                terminal.put(
                    position.x + x_offset,
                    position.y + y_offset,
                    code,
                )
Пример #27
0
def draw_window(rect_, caption, color="white", bkcolor="black"):
    push_colors()
    terminal.color(color)
    terminal.bkcolor(bkcolor)
    terminal.clear_area(rect_.x, rect_.y, rect_.width, rect_.height)
    draw_line(rect_.x + 1, rect_.y + 2, rect_.width - 2, "[U+2594]")
    draw_rect(rect_)
    terminal.print_(rect_.center_x, rect_.y + 1, "[align=center]" + caption)
    pop_colors()
Пример #28
0
    def render(self):
        """Render all on-screen objects."""
        blt.clear()

        self.world.active_player.render_screen(self.world)

        blt.bkcolor(colors.CLEAR)

        blt.refresh()
Пример #29
0
def DrawCharSheet():
    blt.layer(0)
    blt.bkcolor("blue")

    for x in range(5, screen_width - 5):
        for y in range(5, screen_height - 5):
            blt.puts(x, y, "[color=red][bkcolor=blue]X[/bkcolor][/color]")

    blt.layer(0)
Пример #30
0
 def _print_button(self, position):
     init_text = self.button_names[position]
     normilized_text = init_text.center(self.width)
     x = self.init_coord_x
     y = self.init_coord_y + position
     if self.position == position:
         terminal.bkcolor(BG_COLOR_LIGHTED)
     terminal.printf(x, y, normilized_text)
     terminal.bkcolor(BG_COLOR_NORMAL)
Пример #31
0
    def draw(self, x, y, bgUnderItem, spacing_x, spacing_y):
        terminal.color(terminal.color_from_argb(*self.color_fg))
        terminal.bkcolor(terminal.color_from_argb(*bgUnderItem))
        terminal.put(x*spacing_x, y*spacing_y, self.image)

        # Draw highlight rectangle if needed.
        if self.highlight:
            terminal.color(terminal.color_from_argb(*self.highlight))
            terminal.put(x*spacing_x, y*spacing_y, '\u2610')
Пример #32
0
def draw_background(dest, x, y, color, flag=libtcod.BKGND_SET, verbose=False):
    # LIBTCOD
    # libtcod.console_set_char_background(dest, x, y, color, flag)
    # BEARLIB
    # TODO: Replace / Obsolete?
    #color = Utils.convert_color(color)
    if verbose:
        print color.getRGB()
    terminal.bkcolor(color)
    terminal.put(x, y, terminal.pick(x,y, 0))
Пример #33
0
 def draw(self, xy: vec, layer: int = 0) -> None:
     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
     if self.bbox is None:
         blt.print_(xy.x, xy.y, self.text)
     else:
         blt.print_(xy.x, xy.y, self.text, self.bbox.x, self.bbox.y,
                    self.align_h.value + self.align_v.value)
Пример #34
0
def set_background(dest, color):
    # LIBTCOD
    # libtcod.console_set_default_background(dest, color)
    # BEARLIB
    color = Utils.convert_color(color)
    terminal.bkcolor(color)
Пример #35
0
def clear_layer(layer, color='black'):
    terminal.bkcolor(color)
    terminal.layer(layer)
    terminal.clear_area(0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT)