Exemplo n.º 1
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)
Exemplo n.º 2
0
 def render(self, renderer):
     for tile in self.body:
         renderer.render(10 + tile[0], 5 + tile[1],
                         Symbol(' ', blt.color_from_name("white")), 0,
                         colors.WORLD_GEN_HIGHLIGHT)
     for opening in self.openings:
         renderer.render(10 + opening[0], 5 + opening[1],
                         Symbol('V', blt.color_from_name("white")), 0,
                         colors.WORLD_GEN_OPENING)
Exemplo n.º 3
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')
    header_text = textwrap.wrap(header, width)
    header_height = len(header_text)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    # top left corner of menu
    x = var.SCREEN_WIDTH / 2 - width / 2
    y = var.SCREEN_HEIGHT / 2 - height / 2

    terminal.color(terminal.color_from_name('white'))
    terminal.bkcolor(terminal.color_from_name('transparent'))
    y_location = 0
    letter_index = ord('a')
    for line in header_text:
        terminal.printf(x, y + y_location, line)
        y_location += 1
    for option_text in options:
        text = '(' + chr(letter_index) + ')' + option_text
        terminal.printf(x, y + y_location, text)
        y_location += 1
        letter_index += 1
    terminal.refresh()

    key = terminal.read()

    # if key == terminal.TK_MOUSE_LEFT:
    #     (menu_x, menu_y) = (terminal.state(terminal.TK_MOUSE_X), terminal.state(terminal.TK_MOUSE_Y))
    #     # check if click is within the menu and on a choice
    #     if menu_x >= x and menu_x < x + width and menu_y >= y + header_height and menu_y < y + height - header_height:
    #         return menu_y
    #
    # if key == terminal.TK_MOUSE_RIGHT or key == terminal.TK_ESCAPE:
    #     return None # cancel if the player right-clicked or pressed escape
    if key == terminal.TK_ENTER and terminal.check(terminal.TK_ALT):
        # alt+enter changes fullscreen
        fullscreen = terminal.check(terminal.TK_FULLSCREEN)
        fullscreen = not fullscreen
        terminal.set('window.fullscreen=' + fullscreen)

    if terminal.check(terminal.TK_WCHAR):
        index = terminal.state(terminal.TK_WCHAR) - ord('a')
        if index >= 0 and index < len(options):
            return index
        return None

    terminal.clear()
    return None
Exemplo n.º 4
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")
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
0
 def __init__(self, color):
     if isinstance(color, str):
         self.colorname = color
         self.color = terminal.color_from_name(self.colorname)
     else:
         self.colorname = color
         self.color = color
Exemplo n.º 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")
Exemplo n.º 9
0
    def make_minimap():

        minimap = np.ones_like(game_map.tiles, dtype=int)
        for x in range(game_map.width):
            for y in range(game_map.height):
                minimap[y][x] = blt.color_from_name("dark gray")
                if len(game_map.tiles[x][y].entities_on_tile) > 0:
                    if game_map.tiles[x][y].entities_on_tile[
                            -1].name == "tree":
                        minimap[y][x] = blt.color_from_name("dark green")
                    elif "wall" in game_map.tiles[x][y].entities_on_tile[
                            -1].name:
                        minimap[y][x] = blt.color_from_name("dark amber")
                    elif game_map.tiles[x][y].entities_on_tile[
                            -1].name == "player":
                        minimap[y][x] = blt.color_from_name(None)
                    elif game_map.tiles[x][y].entities_on_tile[-1].fighter \
                            and game_map.tiles[x][y].entities_on_tile[-1].name != "player":
                        minimap[y][x] = blt.color_from_name("light red")
                    else:
                        minimap[y][x] = blt.color_from_name("light gray")
                elif game_map.tiles[x][y].blocked:
                    minimap[y][x] = blt.color_from_name("light gray")
                # if not game_map.tiles[x][y].explored:
                #     minimap[y][x] = blt.color_from_name("#000000")

        minimap = minimap.flatten()
        minimap = (c_uint32 * len(minimap))(*minimap)
        blt.set(
            "U+F900: %d, raw-size=%dx%d, resize=%dx%d, resize-filter=nearest" %
            (addressof(minimap), game_map.width, game_map.height, 500, 500))
Exemplo n.º 10
0
def draw_entity(entity: Entity, game_map: GameMap, camera_view: dict):
    if game_map.in_fov(entity.position):
        # set layer to draw on
        terminal.layer(Layers.PLAYER)
        # change color
        color = terminal.color_from_name(entity.color)
        terminal.color(color)
        view_x, view_y = camera_view[entity.position]
        terminal.put(view_x, view_y, entity.char)
Exemplo n.º 11
0
def render_bar(layer: int, x, y, total_width, name, value, maximum, bar_color, back_color):
    bar_width = int(float(value) / maximum * total_width)

    blt.layer(layer)
    last_bg = blt.state(blt.TK_BKCOLOR)
    blt.bkcolor(blt.color_from_name(back_color))
    blt.clear_area(x, y, total_width, 1)
    blt.bkcolor(last_bg)

    if bar_width > 0:
        last_bg = blt.state(blt.TK_BKCOLOR)
        blt.bkcolor(blt.color_from_name(bar_color))
        blt.clear_area(x, y, bar_width, 1)
        blt.bkcolor(last_bg)

    text: str = f"{name}: {value}/{maximum}"
    x_centered = x + int((total_width - len(text)) / 2)
    blt.color("white")
    blt.puts(x_centered, y, text)
 def __init__(self, pos, world):
     world_width = world.FLOOR_WIDTH
     world_height = world.FLOOR_HEIGHT
     symbol = Symbol('@', blt.color_from_name("dark white"))
     super().__init__(pos[0], pos[1], symbol, 10, Faction.PLAYER)
     self.camera = Camera(self.x, self.y, world_width, world_height)
     self.world_renderer = Renderer()
     self.memory_map = [[None for x in range(world_width)] for y in range(world_height)]
     self.fov_map = []
     self.update_memory_map(world)
Exemplo n.º 13
0
    def draw(self, camera, game_map):
        # Draw the entity to the terminal
        terminal.color(terminal.color_from_name("white"))

        if game_map.fov[self.x,
                        self.y] or (self.stairs
                                    and game_map.explored[self.x, self.y]):
            (x, y) = camera.to_camera_coordinates(self.x, self.y)
            if x is not None:
                terminal.put(x=x * 4, y=y * 2, c=self.char)
Exemplo n.º 14
0
 def render(self, x, y, renderer, bkcolor=None):
     """Render this tile at the given world coordinates."""
     if bkcolor is None:
         if self.blocked:
             color = colors.WALL
         else:
             color = colors.FLOOR
     else:
         color = bkcolor
     renderer.render(x, y, Symbol(' ', blt.color_from_name("white")), 0,
                     color)
Exemplo n.º 15
0
def kill_monster(monster):
    death_message = Message(f'{monster.name.capitalize()} is killed!',
                            "orange")

    monster.char = 0x1006
    monster.color = terminal.color_from_name("dark red")
    monster.blocks = False
    monster.fighter = None
    monster.ai = None
    monster.name = 'remains of ' + monster.name
    monster.render_order = RenderOrder.CORPSE
    return death_message
Exemplo n.º 16
0
 def draw_terrain(self, map_pos, screen_pos):
     """Draw terrain at map_x, map_y to the terminal at screen_x, screen_y"""
     if map_pos in MAP:
         num = self.terrain_data[map_pos.y][map_pos.x]
     else:
         num = -1
     if num == -1:
         # Outside the map
         terminal.puts(screen_pos.x, screen_pos.y, ' ')
     elif num < -0.2:
         # Water
         terminal.color(terminal.color_from_name('blue'))
         terminal.puts(screen_pos.x, screen_pos.y, '~')
     elif num < 0.5:
         # Grass
         terminal.color(terminal.color_from_name('green'))
         terminal.puts(screen_pos.x, screen_pos.y, '.')
     else:
         # Mountains
         terminal.color(terminal.color_from_name('gray'))
         terminal.puts(screen_pos.x, screen_pos.y, '^')
Exemplo n.º 17
0
    def render_map(self, game_map):
        if game_map:
            for point, tile in game_map:
                color = terminal.color_from_name("white")
                ch = const.Tiles.UNSEEN
                if tile.label == TileType.EMPTY:
                    color = terminal.color_from_name("black")
                    # ch = const.Tiles.UNSEEN
                elif tile.label == TileType.FLOOR:
                    color = terminal.color_from_name("grey")
                    ch = const.Tiles.FLOOR
                elif tile.label == TileType.WALL:
                    color = terminal.color_from_name("black")
                    ch = const.Tiles.WALL
                elif tile.label == TileType.CORRIDOR:
                    color = terminal.color_from_name("dark_grey")
                    ch = const.Tiles.CORRIDOR
                terminal.layer(const.Layers.MAP)
                terminal.bkcolor(color)
                terminal.put(point.x, point.y, ch)

        terminal.put(10, 10, "\uE003")
    def __init__(self,
                 symbol=None,
                 bkcolor=None,
                 blocked=False,
                 transparent=True):
        # symbol
        if symbol is None:
            self.symbol = Symbol(' ', blt.color_from_name("white"))
        else:
            self.symbol = symbol

        self.blocked = blocked
        self.transparent = transparent
def kill_monster(monster):
    death_message = '[color=orange]{0} is dead![/color]'.format(
        monster.name.capitalize())

    monster.char = '%'
    monster.color = terminal.color_from_name('red')
    monster.blocks = False
    monster.fighter = None
    monster.ai = None
    monster.name = 'remains of ' + monster.name
    monster.render_order = RenderOrder.CORPSE

    return death_message
Exemplo n.º 20
0
    def draw_minimap(self):
        blt.layer(1)
        x0 = self.owner.ui.side_panel.offset_x
        y0 = self.owner.ui.side_panel.offset_y
        game_map = self.owner.levels.current_map

        minimap = np.ones_like(game_map.tiles, dtype=int)
        for x in range(game_map.width):
            for y in range(game_map.height):
                visible = self.owner.player.light_source.fov_map.fov[y, x]
                if visible:
                    minimap[y][x] = blt.color_from_name("dark gray")
                    if len(game_map.tiles[x][y].entities_on_tile) > 0:
                        if game_map.tiles[x][y].entities_on_tile[
                                -1].name == "tree":
                            minimap[y][x] = blt.color_from_name("dark green")
                        elif "wall" in game_map.tiles[x][y].entities_on_tile[
                                -1].name:
                            minimap[y][x] = blt.color_from_name("dark amber")
                        elif game_map.tiles[x][y].entities_on_tile[
                                -1].name == "player":
                            minimap[y][x] = blt.color_from_name(None)
                        elif game_map.tiles[x][y].entities_on_tile[-1].fighter \
                                and game_map.tiles[x][y].entities_on_tile[-1].name != "player":
                            minimap[y][x] = blt.color_from_name("light red")
                        else:
                            minimap[y][x] = blt.color_from_name("light gray")
                    elif game_map.tiles[x][y].blocked:
                        minimap[y][x] = blt.color_from_name("light gray")
                elif game_map.tiles[x][y].explored:
                    if len(game_map.tiles[x][y].entities_on_tile) > 0:
                        minimap[y][x] = blt.color_from_name("light gray")
                    else:
                        minimap[y][x] = blt.color_from_name("dark gray")

        minimap = minimap.flatten()
        minimap = (c_uint32 * len(minimap))(*minimap)

        blt.set(
            "U+F900: %d, raw-size=%dx%d, resize=%dx%d, resize-filter=nearest" %
            (addressof(minimap), game_map.width, game_map.height, 200, 240))

        blt.put(x0 + 3, y0 + 3, 0xF900)
Exemplo n.º 21
0
def main_menu():
    quit = False
    # function to handle the main menu
    while not quit:
        # show the background
        terminal.printf(0, 0, '[0xEFFF]')
        # show the game's title and some credits
        terminal.color(terminal.color_from_name('light yellow'))
        terminal.bkcolor(terminal.color_from_name('transparent'))
        title = 'TOMBS OF THE ANCIENT KINGS'
        terminal.printf(var.SCREEN_WIDTH / 2 - len(title) / 2 - 1,
                        var.SCREEN_HEIGHT / 2 - 4, title)
        credits = 'By Nuzcraft'
        terminal.printf(var.SCREEN_WIDTH / 2 - len(credits) / 2 - 1,
                        var.SCREEN_HEIGHT - 2, credits)
        # show options and wait for the player's choice
        choice = menu(
            '', ['Play a new game', 'Continue last game', 'Options', 'Quit'],
            24)

        if choice == 0:  # new game
            new_game()
            play_game()
            terminal.clear()
        elif choice == 1:  # load game
            try:
                load_game()
            except:
                terminal.clear()
                msgbox('\n No saved game to load. \n', 24)
                terminal.clear()
                continue
            play_game()
        elif choice == 2:  # options
            terminal.clear()
            options()
        elif choice == 3:  # quit
            quit = True
Exemplo n.º 22
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)
Exemplo n.º 23
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    # render a bar (HP, exp, etc.) first calculate the width of the bar
    bar_width = int(float(value) / maximum * total_width)
    # render the background
    terminal.bkcolor(back_color)
    for i in range(total_width):
        terminal.put(x + i, y, ' ')
    # now render the bar on top
    terminal.bkcolor(bar_color)
    for i in range(bar_width):
        terminal.put(x + i, y, ' ')
    # finally, some text with the values
    text = name + ': ' + str(value) + '/' + str(maximum)
    # find the offset for the text
    new_x = total_width / 2 - len(text) / 2
    terminal.color('white')
    terminal.bkcolor(terminal.color_from_name('transparent'))
    terminal.printf(new_x, y, text)
Exemplo n.º 24
0
def _render_cycle(blueprint, path):
    blt.clear()
    ANIMATION_CAMERA.move_to(path[0][0], path[0][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 path:
        ANIMATION_RENDERER.render(x, y,
                                  Symbol(' ', blt.color_from_name("white")), 0,
                                  colors.WORLD_GEN_CYCLE)

    blt.bkcolor(colors.CLEAR)
    blt.refresh()
    time.sleep(ANIMATION_FRAME_LENGTH / 1000)

    ANIMATION_CAMERA.move_to(0, 0)
    ANIMATION_RENDERER.transform(ANIMATION_CAMERA)
Exemplo n.º 25
0
    def draw(self, entity, x, y):
        if entity.hidden:
            return
        player = self.owner.player
        game_map = self.owner.levels.current_map
        # Draw the entity to the screen
        blt.layer(entity.layer)
        blt.color(entity.color)
        c = blt.color_from_name(entity.color)
        if not entity.cursor:
            light_map = player.player.lightmap
            argb = argb_from_color(c)
            a = argb[0]
            r = min(int(argb[1] * light_map[entity.y][entity.x]), 255)
            g = min(int(argb[2] * light_map[entity.y][entity.x]), 255)
            b = min(int(argb[3] * light_map[entity.y][entity.x]), 255)

            blt.color(blt.color_from_argb(a, r, g, b))

        if not (player.light_source.fov_map.fov[entity.y, entity.x]
                and game_map.tiles[entity.x][entity.y].explored):
            blt.color("dark gray")

        # Cursor needs some offset in ascii
        if self.owner.options.gfx == "ascii" and entity.name == "cursor":
            blt.put_ext(x * self.owner.options.tile_offset_x,
                        y * self.owner.options.tile_offset_y,
                        -3 * self.owner.options.tile_offset_x,
                        -5 * self.owner.options.tile_offset_y, entity.char)
        else:
            if entity.boss and not entity.fighter:
                blt.put((x - 1) * self.owner.options.tile_offset_x,
                        (y - 1) * self.owner.options.tile_offset_y,
                        entity.char)
            else:
                blt.put(x * self.owner.options.tile_offset_x,
                        y * self.owner.options.tile_offset_y, entity.char)
Exemplo n.º 26
0
def kill_player(player):
    player.char = 0x1006
    player.color = terminal.color_from_name("dark red")

    return Message('You are killed!', "red"), GameStates.PLAYER_DEAD
Exemplo n.º 27
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)
Exemplo n.º 28
0
def render_all(entities: list, player, game_map, fov_map, fov_recompute: bool, message_log, screen_width: int, screen_height: int, bar_width: int, panel_height: int, panel_y: int, colors):
    blt.layer(0)
    if fov_recompute:
        if game_map.dungeon:
            for x, y, tile in game_map.dungeon:
                visible: bool = libtcod.map_is_in_fov(fov_map, x, y)
                if visible:
                    if tile in [dungeon.FLOOR, dungeon.CORRIDOR]:
                        blt.bkcolor(blt.color_from_name(colors.get("light_ground", "#FF1493")))
                    elif tile == dungeon.DOOR:
                        blt.bkcolor(blt.color_from_name(colors.get("light_door", "#FF1493")))
                    elif tile == dungeon.WALL:
                        blt.bkcolor(blt.color_from_name(colors.get("light_wall", "#FF1493")))

                    # mark tile as explored
                    game_map.tiles[x][y].explored = True

                elif game_map.tiles[x][y].explored:
                    if tile in [dungeon.FLOOR, dungeon.CORRIDOR]:
                        blt.bkcolor(blt.color_from_name(colors.get("dark_ground", "#FF1493")))
                    elif tile == dungeon.DOOR:
                        blt.bkcolor(blt.color_from_name(colors.get("dark_door", "#FF1493")))
                    elif tile == dungeon.WALL:
                        blt.bkcolor(blt.color_from_name(colors.get("dark_wall", "#FF1493")))
                elif tile == dungeon.CAVE:
                    blt.bkcolor(blt.color_from_name("light brown"))
                    blt.put(x, y, ' ')
                else:
                    blt.bkcolor(blt.color_from_name("black"))
                blt.put(x, y, ' ')

            for de in game_map.dungeon.deadends:
                x, y = de
                visible: bool = libtcod.map_is_in_fov(fov_map, x, y)
                if visible:
                    blt.bkcolor(blt.color_from_name("orange"))
                    game_map.tiles[x][y].explored = True
                    blt.put(x, y, ' ')
                elif game_map.tiles[x][y].explored:
                    blt.bkcolor(blt.color_from_name("dark orange"))
                    blt.put(x, y, ' ')
        else:
            # Draw all tiles in the game map
            for y in range(game_map.height):
                for x in range(game_map.width):
                    wall: bool = game_map.tiles[x][y].block_sight

                    if wall:
                        blt.bkcolor(blt.color_from_name(colors.get("dark_wall")))
                        blt.put(x, y, ' ')
                    else:
                        blt.bkcolor(blt.color_from_name(colors.get("dark_ground")))
                        blt.put(x, y, ' ')

    entities_in_render_order = sorted(entities, key=lambda ent: ent.render_order.value)

    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(entity, fov_map)

    # libtcod.console_print_ex(con, 1, screen_height - 2, libtcod.BKGND_NONE, libtcod.LEFT,
    # 'HP: {0:02}/{1:02}'.format(player.fighter.hp, player.fighter.max_hp))
    # blt.color(blt.color_from_name("white"))
    # blt.bkcolor(blt.color_from_name("black"))
    # blt.print(x=1, y=screen_height - 2, s=f"HP: {player.fighter.hp:02}/{player.fighter.max_hp:02}")

    current_layer = 10
    render_bar(current_layer, 1, panel_y, bar_width, "HP", player.fighter.hp, player.fighter.max_hp, "light red", "darkest red")

    y = 2
    for message in message_log.messages:
        blt.color(blt.color_from_name(message.color))
        blt.puts(message_log.x, panel_y + y, message.text)
        y += 1

    blt.refresh()
Exemplo n.º 29
0
def clear_entity(entity):
    # erase the character that represents this object
    blt.bkcolor(blt.color_from_name("transparent"))
    blt.put_ext(entity.x, entity.y, 0, 0, ' ', None)
Exemplo n.º 30
0
def draw_entity(entity, fov_map):
    if libtcod.map_is_in_fov(fov_map, entity.x, entity.y):
        blt.color(blt.color_from_name(entity.color))
        blt.bkcolor(blt.color_from_name("transparent"))
        blt.put_ext(entity.x, entity.y, 0, -2, entity.char, None)
def kill_player(player):
    player.char = '%'
    player.color = terminal.color_from_name('red')

    return f'[color=red]You died![/color]', GameStates.PLAYER_DEAD