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


Python Agent.render方法代码示例

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


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

示例1: World

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import render [as 别名]
class World(object):
    def __init__(self, cx, cy):
        self.cx = cx
        self.cy = cy
        self.target = Vector2D(cx / 2, cy / 2)
        self.hunter = Agent(self, 10, 0.8, 'wander')
        self.agents = []
        self.paused = True
        self.show_info = True

        self.obstacles = []

        self.hidingspots = []



    def update(self, delta):
        if not self.paused:
            self.hidingspots[:]=[]
            for obstacle in self.obstacles:
                self.hidingspots.append(self.get_hiding_position(self.hunter, obstacle))

            for agent in self.agents:
                agent.update(delta)
            self.hunter.update(delta)

    def render(self):
        
        for hidingspot in self.hidingspots:
            egi.blue_pen()
            egi.cross(hidingspot, 5)

        for obstacle in self.obstacles:
            obstacle.render()

        self.hunter.render()

        for agent in self.agents:
            agent.render()

        if self.show_info:
            infotext = ', '.join(set(agent.mode for agent in self.agents))
            egi.white_pen()
            egi.text_at_pos(0, 0, infotext)

    def wrap_around(self, pos):
        ''' Treat world as a toroidal space. Updates parameter object pos '''
        max_x, max_y = self.cx, self.cy
        if pos.x > max_x:
            pos.x = pos.x - max_x
        elif pos.x < 0:
            pos.x = max_x - pos.x
        if pos.y > max_y:
            pos.y = pos.y - max_y
        elif pos.y < 0:
            pos.y = max_y - pos.y

    def transform_points(self, points, pos, forward, side, scale):
        ''' Transform the given list of points, using the provided position,
            direction and scale, to object world space. '''
        # make a copy of original points (so we don't trash them)
        wld_pts = [pt.copy() for pt in points]
        # create a transformation matrix to perform the operations
        mat = Matrix33()
        # scale,
        mat.scale_update(scale.x, scale.y)
        # rotate
        mat.rotate_by_vectors_update(forward, side)
        # and translate
        mat.translate_update(pos.x, pos.y)
        # now transform all the points (vertices)
        mat.transform_vector2d_list(wld_pts)
        # done
        return wld_pts
    def transform_point(self, point, pos, forward, side):
        ''' Transform the given single point, using the provided position,
            and direction (forward and side unit vectors), to object world space. '''
        # make a copy of the original point (so we don't trash it)
        wld_pt = point.copy()
        # create a transformation matrix to perform the operations
        mat = Matrix33()
        # rotate
        mat.rotate_by_vectors_update(forward, side)
        # and translate
        mat.translate_update(pos.x, pos.y)
        # now transform the point (in place)
        mat.transform_vector2d(wld_pt)
        # done
        return wld_pt

    def get_hiding_position(self, hunter, obstacle):
        DistFromBoundry = 30.0
        DistAway = 30 + DistFromBoundry

        ToObj = obstacle.pos - hunter.pos

        ToObj.normalise()

        return(ToObj*DistAway)+obstacle.pos
开发者ID:csillamitterer,项目名称:AI-For-Games,代码行数:101,代码来源:world.py


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