当前位置: 首页>>代码示例>>Python>>正文


Python State.compute_fov方法代码示例

本文整理汇总了Python中State.State.compute_fov方法的典型用法代码示例。如果您正苦于以下问题:Python State.compute_fov方法的具体用法?Python State.compute_fov怎么用?Python State.compute_fov使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在State.State的用法示例。


在下文中一共展示了State.compute_fov方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Screen

# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import compute_fov [as 别名]
class Screen(object):
    """docstring for Screen"""
    def __init__(self, screen_width, screen_height, map_width, map_height, fps_limit, start_fullscreen, font):
        libtcod.console_set_custom_font(font, libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
        libtcod.console_init_root(screen_width, screen_height, 'pyrogue', start_fullscreen)
        self.screen_width = screen_width
        self.screen_height = screen_height
        self.fps_limit = fps_limit
        self.console = libtcod.console_new(screen_width, screen_height)
        self.state = State(map_width, map_height)
        self.fov_recompute = True
        self.mode = 'playing'

    def step(self):
        if self.fov_recompute:
            self.state.compute_fov()
            self.fov_recompute = False
        self.draw_objects()
        self.draw_map()
        self.draw_stats()
        self.blit()
        self.clear_objects()
        player_action = self.handle_keys()
        if player_action == 'exit':
            self.mode = 'exit'
        elif self.mode == 'playing' and player_action != "didnt-take-turn":
            self.state.take_turn()

    def draw_objects(self):
        fov_map = self.state.fov_map
        for obj in self.state.objects:
            if libtcod.map_is_in_fov(fov_map, obj.x, obj.y):
                libtcod.console_set_foreground_color(self.console, obj.color)
                libtcod.console_print_left(self.console, obj.x, obj.y, obj.color, obj.character)

    def draw_map(self):
        game_map = self.state.game_map
        fov_map = self.state.fov_map
        for x in xrange(len(game_map)):
            for y in range(len(game_map[x])):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map[x][y].block_sight
                if not visible and game_map[x][y].explored:
                    if wall:
                        libtcod.console_set_back(self.console, x, y, color_dark_wall, libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_back(self.console, x, y, color_dark_ground, libtcod.BKGND_SET)
                elif visible:
                    if wall:
                        libtcod.console_set_back(self.console, x, y, color_light_wall, libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_back(self.console, x, y, color_light_ground, libtcod.BKGND_SET)
                    game_map[x][y].explore()

    def draw_stats(self):
        fighter = self.state.player.fighter
        hp_string = 'HP: %d/%d' % (fighter.hp, fighter.max_hp)
        libtcod.console_set_foreground_color(self.console, libtcod.white)
        libtcod.console_print_left(self.console, 1, self.screen_height - 2, libtcod.BKGND_NONE, hp_string)

    def clear_objects(self):
        for obj in self.state.objects:
            libtcod.console_print_left(self.console, obj.x, obj.y, libtcod.BKGND_NONE, ' ')

    def blit(self):
        libtcod.console_blit(self.console, 0, 0, self.screen_width, self.screen_height, 0, 0, 0)
        libtcod.console_flush()

    def handle_keys(self):
        key = libtcod.console_wait_for_keypress(True)
        if key.vk == libtcod.KEY_ESCAPE:
            return 'exit'
        elif key.vk == libtcod.KEY_ENTER and libtcod.KEY_ALT:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
        elif key.vk == libtcod.KEY_CONTROL and ord('s'):
            libtcod.sys_save_screenshot()

        move = False
        if self.mode == 'playing':
            if libtcod.console_is_key_pressed(libtcod.KEY_UP):
                self.move_player((0, -1))
                move = True
                return 'move'
            elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
                self.move_player((0, 1))
                move = True
                return 'move'
            elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
                self.move_player((-1, 0))
                move = True
                return 'move'
            elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
                self.move_player((1, 0))
                move = True
                return 'move'
        if move:
            return 'move'
        else:
            return "didnt-take-turn"

#.........这里部分代码省略.........
开发者ID:romanlevin,项目名称:pyrogue,代码行数:103,代码来源:Screen.py


注:本文中的State.State.compute_fov方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。