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


Python Path.update方法代码示例

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


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

示例1: PathfinderPlayer

# 需要导入模块: from Path import Path [as 别名]
# 或者: from Path.Path import update [as 别名]
class PathfinderPlayer(sf.CircleShape):
    def __init__(self, x, y):
        sf.CircleShape.__init__(self)
        self.radius = 10
        self.position = (x, y)
        self.outline_color = sf.Color.BLUE
        self.outline_thickness = 5
        self.path = None

    def update(self, sight_blockers, mouse_position):
        self.path = Path(self.position, mouse_position)
        self.path.update(sight_blockers)
开发者ID:gannj001,项目名称:Tank-Game,代码行数:14,代码来源:PathfinderPlayer.py

示例2: EnemyTank

# 需要导入模块: from Path import Path [as 别名]
# 或者: from Path.Path import update [as 别名]
class EnemyTank(TankBody):
    def __init__(self, texture=sf.Texture.from_file("res/EnemyTankDetailed.png")):
        TankBody.__init__(self, texture)
        self.turret = EnemyTankTurret(sf.Texture.from_file("res/EnemyTankTurret.png"))
        self.turret.set_body(self)
        self.target = None
        self.path = None

    def check_shells(self, objects):
        for ob in objects:
            if isinstance(ob, Shell):
                if intersects(ob.global_bounds, self.global_bounds):
                    self.health -= ob.damage
                    objects.remove(ob)

    def check_sight_to_target(self, objects):
        blockers = []
        for ob in objects:
            if ob.blocks_sight:
                blockers.append(ob)
        ret = True
        for blocker in blockers:
            if not check_sight(self.position, self.target.position, blocker):
                ret = False
                print "Sight blocked"
        return ret

    def move(self):
        dx = self.path[1].position.x - self.position.x
        dy = self.path[1].position.y - self.position.y
        angle = math.degrees(math.atan2(dy, dx)) + 90
        if abs(angle - self.rotation) < 3:
            self.rotation = angle
        else:
            if calc_shortest_direction(self.rotation, angle) >= 0:
                self.rotate(3)
            else:
                self.rotate(-3)

        if abs(angle - self.rotation) < 10:
            self.forward()
            # elif 170 < abs(angle - self.rotation) < 190:
            #     self.backward()

    def range(self):
        ret = False
        dx = abs(self.position.x - self.target.position.x)
        dy = abs(self.position.y - self.target.position.y)
        dist = math.sqrt(dx ** 2 + dy ** 2)
        if dist < 300:
            ret = True
        return ret

    def update(self, objects):
        for ob in objects:
            if isinstance(ob, PlayerTank) or isinstance(ob, PlayerGun):
                self.target = ob

        if self.target:
            sight = self.check_sight_to_target(objects)
            range_to_target = self.range()
            if not sight or not range_to_target:
                self.path = Path(self.position, self.target.position)
                sight_blockers = []
                for ob in objects:
                    if ob.blocks_sight:
                        sight_blockers.append(ob)
                self.path.update(sight_blockers)
                self.move()
            else:
                self.slow_down()
            self.calc_position()
        self.check_collisions(objects)

        self.turret.update(objects)

        self.check_shells(objects)
开发者ID:gannj001,项目名称:Tank-Game,代码行数:79,代码来源:EnemyTank.py


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