當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。