Пример #1
0
 def draw_messages(self):
     self.clear()
     y = 0
     for (line, color) in self.message_lines:
         tcod.console_set_default_foreground(self.console, color)
         tcod.console_print(self.console, 0, y, line)
         y += 1
Пример #2
0
 def draw(self, target_console):
     """Updates and blits the windows's console buffer to another console."""
     tcod.console_print_frame(self.console, 0, 0, self.w, self.h, True, tcod.BKGND_DEFAULT)
     for index in range (len(self.contents)):
         tcod.console_print(self.console, 3, index+2, self.contents[index])
     tcod.console_put_char_ex(self.console, 2, self.selection+2, '>', tcod.white, tcod.black)
     tcod.console_blit(self.console, 0, 0, self.w, self.h, target_console, self.x, self.y, 1.0, 0.9)
Пример #3
0
 def _render_summary(self, creature: Creature, prev_level: int):
     """
         Render the summary line at the top of the console.
     """
     summary_str = "Level {0} -> {1}".format(prev_level, creature.level)
     libtcod.console_set_default_foreground(self.console, settings.BATTLE_TEXT_COLOR)
     libtcod.console_print(self.console, 5, 3, summary_str)
Пример #4
0
 def Show_Inventory(self, Inventory):
     i = 0
     for x in Inventory.Inventory:
         if self.world.try_component(x, Components.Name):
             Name = self.world.component_for_entity(x, Components.Name)
             tcod.console_print(con, 10, 10 + i, Name.value)
             i += 1
Пример #5
0
    def _render_options(self, creature: Creature, x: int, y: int):
        """
            Renders all moves and additional options such as "Flee", "Capture".

            These are defined in the class level variable "options"
        """
        for row, move in enumerate(creature.moves):
            libtcod.console_print(self.console, x, y + row,
                                  "{0}. {1:15s}{2:>12s}  {3}/{4}".format(row + 1, 
                                                                         move.move_data.name, 
                                                                         move.move_data.type.name, 
                                                                         move.pp, 
                                                                         move.move_data.max_pp))

        for option in BattleRenderer.options:
            display = True

            # Special case code for capture, disable it if the player has no 
            # pokeballs remaining. Probably generalise when obvious what other
            # options there will be.
            if option["desc"] == "Capture" and len(self.game.game_data.player.available_pokeballs()) <= 0:
                display = False

            if display:
                actual_row = settings.SCREEN_HEIGHT + option["row"] - 1
                libtcod.console_print(self.console, x, actual_row, "{0}. {1}".format(option["char"], option["desc"]))
Пример #6
0
def test_console_printing(console, fg, bg):
    libtcodpy.console_set_background_flag(console,
                                          libtcodpy.BKGND_SET)
    assert (libtcodpy.console_get_background_flag(console) ==
                     libtcodpy.BKGND_SET)

    libtcodpy.console_set_alignment(console, libtcodpy.LEFT)
    assert (libtcodpy.console_get_alignment(console) ==
                     libtcodpy.LEFT)

    libtcodpy.console_print(console, 0, 0, 'print')
    libtcodpy.console_print_ex(console, 0, 0, libtcodpy.BKGND_SET,
                               libtcodpy.LEFT, 'print ex')

    assert (libtcodpy.console_print_rect(
        console, 0, 0, 8, 8, 'print rect') > 0
        )
    assert (libtcodpy.console_print_rect_ex(
        console, 0, 0, 8, 8, libtcodpy.BKGND_SET, libtcodpy.LEFT,
        'print rect ex') > 0
        )
    assert (libtcodpy.console_get_height_rect(
        console, 0, 0, 8, 8, 'get height') > 0
        )

    libtcodpy.console_set_color_control(libtcodpy.COLCTRL_1, fg, bg)
Пример #7
0
 def _render_pokeball_select(self, pokeballs: Dict[Pokeball, int], x: int, y: int):
     """
         Render the list of available pokeball types along with the key
         press required to select them.
     """
     for row, pokeball in enumerate(pokeballs.keys()):
         libtcod.console_print(self.console, x, y + row + 1, "{0}. {1:20s}{2}".format(pokeball.display_char, pokeball.name + " Ball", pokeballs[pokeball]))
Пример #8
0
def test_console_apf_read_write(console, offscreen, tmpdir):
    libtcodpy.console_print(console, 0, 0, 'test')

    apf_file = tmpdir.join('test.apf').strpath
    assert libtcodpy.console_save_apf(console, apf_file)
    assert libtcodpy.console_load_apf(offscreen, apf_file)
    assertConsolesEqual(console, offscreen)
Пример #9
0
def test_console_apf_read_write(console, offscreen, tmpdir):
    libtcodpy.console_print(console, 0, 0, 'test')

    apf_file = tmpdir.join('test.apf').strpath
    assert libtcodpy.console_save_apf(console, apf_file)
    assert libtcodpy.console_load_apf(offscreen, apf_file)
    assertConsolesEqual(console, offscreen)
Пример #10
0
def test_console_printing(console, fg, bg):
    libtcodpy.console_set_background_flag(console,
                                          libtcodpy.BKGND_SET)
    assert (libtcodpy.console_get_background_flag(console) ==
                     libtcodpy.BKGND_SET)

    libtcodpy.console_set_alignment(console, libtcodpy.LEFT)
    assert (libtcodpy.console_get_alignment(console) ==
                     libtcodpy.LEFT)

    libtcodpy.console_print(console, 0, 0, 'print')
    libtcodpy.console_print_ex(console, 0, 0, libtcodpy.BKGND_SET,
                               libtcodpy.LEFT, 'print ex')

    assert (libtcodpy.console_print_rect(
        console, 0, 0, 8, 8, 'print rect') > 0
        )
    assert (libtcodpy.console_print_rect_ex(
        console, 0, 0, 8, 8, libtcodpy.BKGND_SET, libtcodpy.LEFT,
        'print rect ex') > 0
        )
    assert (libtcodpy.console_get_height_rect(
        console, 0, 0, 8, 8, 'get height') > 0
        )

    libtcodpy.console_set_color_control(libtcodpy.COLCTRL_1, fg, bg)
Пример #11
0
    def _render_stats(self, creature: Creature, prev_level: int):
        """
            Render the statistics lines one by one.
        """
        libtcod.console_set_default_foreground(self.console, settings.BATTLE_TEXT_COLOR)

        for idx, stat in enumerate([stat for stat in creature.stats if stat.short_name is not None and stat.short_name != ""]):
            stat_str = "{0:7s}: {1:3d} -> {2:3d}".format(stat.short_name, creature.max_stat(stat, level=prev_level), creature.max_stat(stat))

            libtcod.console_print(self.console, 5, 4 + idx, stat_str)
Пример #12
0
def test_console_rexpaint_save_load(console, tmpdir, ch, fg, bg):
    libtcodpy.console_print(console, 0, 0, 'test')
    libtcodpy.console_put_char_ex(console, 1, 1, ch, fg, bg)
    xp_file = tmpdir.join('test.xp').strpath
    assert libtcodpy.console_save_xp(console, xp_file, 1)
    xp_console = libtcodpy.console_from_xp(xp_file)
    assert xp_console
    assertConsolesEqual(console, xp_console)
    assert libtcodpy.console_load_xp(None, xp_file)
    assertConsolesEqual(console, xp_console)
Пример #13
0
def test_console_rexpaint_save_load(console, tmpdir, ch, fg, bg):
    libtcodpy.console_print(console, 0, 0, 'test')
    libtcodpy.console_put_char_ex(console, 1, 1, ch, fg, bg)
    xp_file = tmpdir.join('test.xp').strpath
    assert libtcodpy.console_save_xp(console, xp_file, 1)
    xp_console = libtcodpy.console_from_xp(xp_file)
    assert xp_console
    assertConsolesEqual(console, xp_console)
    assert libtcodpy.console_load_xp(None, xp_file)
    assertConsolesEqual(console, xp_console)
Пример #14
0
 def _render_health_values(self, creature: Creature, x: int, y: int):
     """
         Utility function to render the health values <current>/<max> at 
         the given x,y coordinates.
     """
     hp_stat = self.game.static_game_data.stat(data.HP_STAT)
     current = creature.current_stat(hp_stat)
     max_hp = creature.max_stat(hp_stat)
     
     libtcod.console_set_default_foreground(self.console, settings.BATTLE_TEXT_COLOR)
     libtcod.console_print(self.console, x, y, "{0}/{1}".format(current, max_hp))
Пример #15
0
def test_console_rexpaint_list_save_load(console, tmpdir):
    con1 = libtcodpy.console_new(8, 2)
    con2 = libtcodpy.console_new(8, 2)
    libtcodpy.console_print(con1, 0, 0, 'hello')
    libtcodpy.console_print(con2, 0, 0, 'world')
    xp_file = tmpdir.join('test.xp').strpath
    assert libtcodpy.console_list_save_xp([con1, con2], xp_file, 1)
    for a, b in zip([con1, con2], libtcodpy.console_list_load_xp(xp_file)):
        assertConsolesEqual(a, b)
        libtcodpy.console_delete(a)
        libtcodpy.console_delete(b)
Пример #16
0
def test_console_rexpaint_list_save_load(console, tmpdir):
    con1 = libtcodpy.console_new(8, 2)
    con2 = libtcodpy.console_new(8, 2)
    libtcodpy.console_print(con1, 0, 0, 'hello')
    libtcodpy.console_print(con2, 0, 0, 'world')
    xp_file = tmpdir.join('test.xp').strpath
    assert libtcodpy.console_list_save_xp([con1, con2], xp_file, 1)
    for a, b in zip([con1, con2], libtcodpy.console_list_load_xp(xp_file)):
        assertConsolesEqual(a, b)
        libtcodpy.console_delete(a)
        libtcodpy.console_delete(b)
Пример #17
0
    def draw(self, world, window, scores, time):
        libtcod.console_print(window, 5, 45, scores)
        libtcod.console_print(window, 5, 47, time)

        for entity in world['entities']:
            # print(entity)
            libtcod.console_set_default_foreground(window, entity['color'])
            libtcod.console_put_char(window, entity['x'], entity['y'],
                                     entity['char'], libtcod.BKGND_NONE)
        libtcod.console_flush()
        for entity in world['entities']:
            self.clear(entity, self.window)
Пример #18
0
def render_log(log: list = None):
    log = log or settings.main_log
    panel = settings.log_pane
    tdl.console_set_default_background(panel, tdl.black)
    tdl.console_clear(panel)
    tdl.console_set_default_foreground(panel, tdl.white)

    for row_id, msg in enumerate(log[-7:]):
        # msg = ''.join(chr(settings.typeface_mapper.get(c) or space) for c in msg)
        tdl.console_print(panel, 0, row_id, fmt=msg)

    tdl.console_blit(panel, 0, 0, settings.screen_width, settings.log_height,
                     0, 0, settings.screen_height - settings.log_height)
Пример #19
0
    def _render_creature_details(self, creature: Creature, x: int, y: int, include_health_values: bool=False):
        """
            Renders the creature box for the defending creature.
        """
        height = BattleRenderer.creature_details_height_w_hp if include_health_values else BattleRenderer.creature_details_height_no_hp

        libtcod.console_set_default_foreground(self.console, settings.BATTLE_TEXT_COLOR)
        libtcod.console_print_frame(self.console, x, y, BattleRenderer.creature_details_width, height)
        libtcod.console_print(self.console, x + 1, y + 1, creature.nickname[:10])
        libtcod.console_print(self.console, x + BattleRenderer.creature_details_width - 6, y + 1, "LV.{0}".format(creature.level))
        
        self._render_health_bar(creature, BattleRenderer.creature_details_width - 2, x + 1, y + 3)
        if include_health_values:
            self._render_health_values(creature, x + BattleRenderer.creature_details_width - 8, y + 5)
Пример #20
0
def render_all(con, entities, gm, colors):  #gm=game_map
    # Draw all the tiles in the game map
    c_map = con.get('map')
    c_inv = con.get('inv')
    c_info = con.get('info')
    c_gmst = con.get('gmst')
    if gv.redraw_map:
        for y in range(gm.h):
            for x in range(gm.w):
                nx = x + gm.x * gm.w
                ny = y + gm.y * gm.h
                b = gm.policko(nx, ny).block
                if max(b) - entities[0].h + 1 in colors:
                    c = colors.get(max(b) - entities[0].h + 1)
                else:
                    c = libtcod.black
                #c = libtcod.white
                libtcod.console_set_default_foreground(c_map, c)
                libtcod.console_put_char(c_map, x, y, gm.tiles[nx][ny].char)
        gv.redraw_map = False
    libtcod.console_set_default_foreground(c_map, libtcod.white)

    draw_info(c_info)
    # Draw all visible entities in the list
    for entity in entities:
        if entity.visible:
            draw_entity(c_map, entity, gm)

    libtcod.console_blit(c_map, 0, 0, gv.map_width, gv.map_height, 0, 0, 0)

    if gv.GAME_STATE == C.GS_INVENTORY:
        draw_info(c_info, entities[0].inventory.get_selected())
        draw_inventory(c_inv, entities[0].inventory)
    else:
        cur = entities[-1]
        for ent in entities:
            if ent == cur: continue
            if (cur.x, cur.y, cur.h) == (ent.x, ent.y, ent.h):
                draw_info(c_info, ent)
    #libtcod.console.blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    if gv.GAME_STATE == C.GS_PAUSE:
        libtcod.console_print(c_gmst, 5, 0, "GAME PAUSED")
    libtcod.console_blit(c_gmst, -50, -2, gv.screen_width, 3, 0, 0, 0)
    libtcod.console_print(c_gmst, 5, 0, "           ")
Пример #21
0
def draw_inventory(con, inv: CInventory):

    i_w, i_h = 19, 20
    i_x = (gv.map_width - i_w - 2) // 2
    i_y = (gv.map_height - i_h - 2) // 2

    libtcod.console_rect(con, 1, 1, i_w, i_h, True)

    # print tabs
    libtcod.console_print(
        con, 1, 1, ' A ' + chr(179) + ' C ' + chr(179) + ' E ' + chr(179) +
        ' G ' + chr(179) + ' Q ')

    libtcod.console_hline(con, 1, 2, -1 + inv.x * 4)
    libtcod.console_put_char(con, inv.x * 4, 2, 217)
    libtcod.console_put_char(con, (inv.x + 1) * 4, 2, 192)
    libtcod.console_hline(con, (inv.x + 1) * 4 + 1, 2, 20 - (inv.x + 1) * 4)

    libtcod.console_put_char(con, 0, 0, 218)
    libtcod.console_hline(con, 1, 0, 20)
    libtcod.console_put_char(con, 1 + i_w, 0, 191)

    libtcod.console_vline(con, 0, 1, 20)
    libtcod.console_vline(con, 1 + i_w, 1, 20)

    libtcod.console_put_char(con, 0, 1 + i_h, 192)
    libtcod.console_hline(con, 1, 1 + i_h, 20)
    libtcod.console_put_char(con, 1 + i_w, 1 + i_h, 217)

    i = 0
    s = ""
    for item in inv.items:
        if item.type in inv.tabs[inv.x]:
            if i == inv.y:
                libtcod.console_set_default_foreground(con, libtcod.green)
            if item.equipped: s = "(E)"
            else: s = ""
            libtcod.console_print(con, 1, 3 + i,
                                  "{0:15} {1}".format(item.me.name, s))
            libtcod.console_set_default_foreground(con, libtcod.white)
            i += 1
    libtcod.console_blit(con, -i_x, -i_y, i_w + i_x + 2, i_h + i_y + 2, 0, 0,
                         0)
Пример #22
0
def draw_info(con, ent=None):
    i_w = 17
    i_h = 20
    libtcod.console_rect(con, 1, 1, i_w, i_h, True)
    """libtcod.console_put_char(con, 0, 0, 218)
    libtcod.console_hline(con, 1, 0, i_w)
    libtcod.console_put_char(con, 1 + i_w, 0, 191)

    libtcod.console_vline(con, 0, 1, i_h)
    libtcod.console_vline(con, 1 + i_w, 1, i_h)

    libtcod.console_put_char(con, 0, 1 + i_h, 192)
    libtcod.console_hline(con, 1, 1 + i_h, i_w)
    libtcod.console_put_char(con, 1 + i_w, 1 + i_h, 217)"""

    if ent != None:
        if ent.type == C.EN_ITEM:
            libtcod.console_set_default_foreground(con, libtcod.green)
            libtcod.console_print(con, 1, 1, ent.name)
            libtcod.console_set_default_foreground(con, libtcod.white)
            i = 2
            for key, val in ent.item.stats.items():
                if val != 0:
                    s = key + ': ' + str(val)
                    libtcod.console_print(con, 3, i, s)
                    i += 1
        elif ent.type == C.EN_HUMAN:
            libtcod.console_set_default_foreground(con, libtcod.green)
            libtcod.console_print(con, 1, 1, ent.name)
            libtcod.console_set_default_foreground(con, libtcod.white)
            s = str(ent.fighter.stats['hp']) + '/' + str(
                ent.fighter.stats['maxhp'])
            libtcod.console_print(con, 3, 2, 'HP: ' + s)
            i = 3
            for key, val in ent.fighter.stats.items():
                if key in ['hp', 'maxhp']: continue
                if val != 0:
                    s = key + ': ' + str(val)
                    libtcod.console_print(con, 3, i, s)
                    i += 1

    libtcod.console_blit(con, -50, -28, 67, 50, 0, 0, 0)
Пример #23
0
def render_all():
    global fov_recompute


    if fov_recompute:
        fov_recompute = False
        tcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)


    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            visible = tcod.map_is_in_fov(fov_map, x, y)
            wall = map[x][y].block_sight

            if not visible:
                if map[x][y].explored:
                    if wall:
                        tcod.console_set_char_background(con, x, y, color_dark_wall, tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(con, x, y, color_dark_ground, tcod.BKGND_SET)
            else:
                if wall:
                    tcod.console_set_char_background(con, x, y, color_light_wall, tcod.BKGND_SET)
                else:
                    tcod.console_set_char_background(con, x, y, color_light_ground, tcod.BKGND_SET)

                map[x][y].explored = True

    #draw all object in object list
    for object in objects:
        if (object != player):
            object.draw()

    player.draw()

    tcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)


    tcod.console_set_default_foreground(con, tcod.white)
    tcod.console_print(con, 1, SCREEN_HEIGHT - 2, 'HP: ' + '  ' + '/' + '  ')
    tcod.console_print(con, 1, SCREEN_HEIGHT - 2, 'HP: ' + str(player.fighter.hp) + '/' + str(player.fighter.max_hp))
Пример #24
0
 def _render_species(self, pokedex, left_most_column):
     """
         Iterate over all species and put them onto the screen in the 
         appropriate location.
         
         Only displays seen and known species. Each of these can be 
         displayed differently.
     """
     for pokedex_number in pokedex:
         status, species = pokedex[pokedex_number]
     
         name = "???"
         color = settings.POKEDEX_UNKNOWN_COLOR
         if status == 1:
             name = species.name
             color = settings.POKEDEX_SEEN_COLOR
         elif status == 2:
             name = species.name
             color = settings.POKEDEX_KNOWN_COLOR
 
         column, row = self.calculate_position_of_pokedex_number(pokedex_number - 1, left_most_column)
         
         libtcod.console_set_default_foreground(self.console, color)
         libtcod.console_print(self.console, column * PokedexRenderer.column_width + 1, row + PokedexRenderer.header_height + 1, str(pokedex_number) + ". " + name)
Пример #25
0
def update_panel(level):
    is_magic = "Magic " if level.world == "MAGIC" else ""
    tcod.console_print(panel, 1, 1,
                       "{}Level: {}".format(is_magic, level.number))
    render_hp_bar(level.player)
    render_str_bar(level.player)
    arm = 11 - level.player.armour
    tcod.console_print(
        panel, 1, 4, "XP: {}|{}   Arm: {}".format(level.player.xp_level,
                                                  level.player.xp, arm))
    if level.player.hunger >= HUNGRY_WEAK:
        hgr = "-- weak --"
    elif level.player.hunger >= HUNGRY:
        hgr = "hungry"
    else:
        hgr = ""
    tcod.console_print(panel, 1, 5, hgr)
    render_messages()
    while len(messages) > 0:
        del messages[0]
Пример #26
0
def cprint(x, y, txt):
    t.console_print(0, x, y, txt)
Пример #27
0
def test_console_blit(console, offscreen):
    libtcodpy.console_print(offscreen, 0, 0, 'test')
    libtcodpy.console_blit(offscreen, 0, 0, 0, 0, console, 0, 0, 1, 1)
    assertConsolesEqual(console, offscreen)
    libtcodpy.console_set_key_color(offscreen, libtcodpy.black)
Пример #28
0
 def write(self, x, y, fmt):
     xstr = make_colored_string(fmt)
     tcod.console_print(self._c, x, y, xstr)
Пример #29
0
 def write(self, x, y, fmt):
     xstr = make_colored_string(fmt)
     tcod.console_print(self._c, x, y, xstr)
Пример #30
0
def test_console_blit(console, offscreen):
    libtcodpy.console_print(offscreen, 0, 0, 'test')
    libtcodpy.console_blit(offscreen, 0, 0, 0, 0, console, 0, 0, 1, 1)
    assertConsolesEqual(console, offscreen)
    libtcodpy.console_set_key_color(offscreen, libtcodpy.black)
Пример #31
0
def update_position_display(player):
    '''Print player position on last line of the console.'''
    tcod.console_set_default_foreground(0, tcod.green)
    tcod.console_print(
        0, 0, SCR_HEIGHT - 1, 'x=' + str(player.col).zfill(2) + ',y=' +
        str(SCR_HEIGHT - 1 - player.row).zfill(2))
Пример #32
0
 def _render_message(self, message, x: int, y: int):
     """
         Utility function to render a message on top of the screen at the 
         given point.
     """
     libtcod.console_print(self.console, x + 1, y + 1, message)
Пример #33
0
    def draw_finish_screen(self, world, window, winner):
        for entity in world['entities']:
            self.clear(entity, self.window)

        libtcod.console_print(window, 20, 20, winner)
        libtcod.console_flush()
Пример #34
0
 def examine(self, memory):
     self.clear()
     if memory is None:
         return
     if memory.mob:
         drawables[memory.mob.info['name']].draw(self.console, Pos(1, 1))
         tcod.console_print(self.console, 3, 1,
                            get_short_mob_description(memory.mob))
         tcod.console_set_default_foreground(self.console, tcod.red)
         tcod.console_print(self.console, 3, 2, str(memory.mob.hp))
         tcod.console_set_default_foreground(self.console, tcod.white)
         tcod.console_print(self.console, 4 + len(str(memory.mob.hp)), 2,
                            "hp")
         if DEBUG:
             tcod.console_print(self.console, 3, 3, str(memory.mob.pos))
             tcod.console_print(self.console, 3, 4, str(memory.mob.target))
     else:
         drawables[memory.tile_name].draw(self.console, Pos(1, 1))
         tcod.console_print(self.console, 3, 1, memory.tile_name)
Пример #35
0
            print("name",mon.name,"hpmax mod",mon.stats.get('hpmax'))
            print("name",mon.name,"hpmax",mon.stats.hpmax)
            for mod in mon.stats.mods:
                print("-------------name","statmods",mod)'''


 
'''
            dbox(25,5,40,10,
                 "Sup n***a! I'm a straight up gangsta. Original-G. I ddon't play it like Shack, you'll know it was me, cuz the next time you see her she be like AHH!! Cap'n G!!!",
                 border=3,margin=2)'''

    #tt = time.time()

## TIMING
'''tr = time.time() - tt
libtcod.console_print(0,0,0,str(tr))
tt = time.time()'''
##


'''
# TESTING
print(pc.stats.get('atk'))
print(pc.stats.get('dmg'))
print(pc.stats.get('asp'))
wp = Weapon('chef knife')
wield(pc,wp)
print(pc.stats.get('atk'))
print(pc.stats.get('dmg'))
print(pc.stats.get('asp'))
Пример #36
0
	def print(self,x,y,fmt):
		(x,y) = self.tocam(x,y)
		tcod.console_print(self.con,x,y,fmt)
Пример #37
0
    def _render_details_box(self, species, status):
        """
            If a pokemon has been selected then this is called to display a 
            box with the specific details as an overlay on top of the pokedex.
        """
        libtcod.console_set_default_foreground(self.console, settings.POKEDEX_LINE_COLOR)
        libtcod.console_print_frame(self.console, 19, 15, 43, 16)  # TODO: Generalise to widths
        
        libtcod.console_print(self.console, 23, 16, u"No. {0.pokedex_number:0=3d}  {0.name}".format(species))

        if status == 2:
            libtcod.console_print(self.console, 23, 17, u"  {0.genus} Pokemon".format(species))
            libtcod.console_print(self.console, 23, 18, u"Type(s): {0}".format(', '.join(str(t) for t in species.types)))
            libtcod.console_print(self.console, 23, 19, "Height: {0}".format(species.imperial_height_str()))
            libtcod.console_print(self.console, 23, 20, "Weight: {0}".format(species.imperial_weight_str()))
            
            libtcod.console_print_rect(self.console, 20, 22, 41, 14, species.flavor_text)
        elif status == 1:
            libtcod.console_print(self.console, 23, 17, "  ????? Pokemon".format(species))
            libtcod.console_print(self.console, 23, 18, "Type(s): ?????")
            libtcod.console_print(self.console, 23, 19, "Height: ??'??\"")
            libtcod.console_print(self.console, 23, 20, "Weight: ????.? lbs.")
Пример #38
0
def main():
    screen_width = 80
    screen_height = 50
    map_width = 80
    map_height = 45

    room_max_size = 10
    room_min_size = 4
    max_rooms = 30

    fov_algorithm = 0
    fov_light_walls = True
    fov_radius = 10

    max_monsters_per_room = 3

    colors = {
        'dark_wall': tcod.Color(0, 0, 100),
        'dark_ground': tcod.Color(50, 50, 150),
        'light_wall': tcod.Color(130, 110, 50),
        'light_ground': tcod.Color(200, 180, 50)
    }

    fighter_component = Fighter(hp=30, defense=2, power=5)
    player = Entity(0,
                    0,
                    '@',
                    tcod.white,
                    'Player',
                    blocks=True,
                    fighter=fighter_component)
    entities = [player]

    tcod.console_set_custom_font(
        '.\\assets\\fonts\\arial10x10.png',
        tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)

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

    con = tcod.console_new(screen_width, screen_height)

    game_map = GameMap(map_width, map_height)
    game_map.make_map(max_rooms, room_min_size, room_max_size, map_width,
                      map_height, player, entities, max_monsters_per_room)

    fov_recompute = True

    fov_map = initialize_fov(game_map)

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

    game_state = GameStates.PLAYERS_TURN

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

        if fov_recompute:
            recompute_fov(fov_map, player.x, player.y, fov_radius,
                          fov_light_walls, fov_algorithm)

        render_all(con, entities, game_map, fov_map, fov_recompute,
                   screen_width, screen_height, colors)

        fov_recompute = False

        tcod.console_flush()

        clear_all(con, entities)

        action = handle_keys(key)

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

        if move and game_state == GameStates.PLAYERS_TURN:
            dx, dy = move
            destination_x = player.x + dx
            destination_y = player.y + dy

            if not game_map.is_blocked(destination_x, destination_y):
                target = get_blocking_entites_at_location(
                    entities, destination_x, destination_y)

                if target:
                    player.fighter.attack(target)
                else:
                    player.move(dx, dy)
                    fov_recompute = True

                game_state = GameStates.ENEMY_TURN
                print('Enemy Turn!')

        if exit:
            print('Thanks for playing!')
            return True

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

        if game_state == GameStates.ENEMY_TURN:
            for entity in entities:
                if entity.ai:
                    entity.ai.take_turn(player, fov_map, game_map, entities)

            game_state = GameStates.PLAYERS_TURN
            print('Player Turn!')

        if msg:
            tcod.console_print(con, 1, 1, '                  ')
            tcod.console_print(con, 1, 1, msg)
    print('window was closed')