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


Python Timer.subscribe方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import subscribe [as 别名]
class Arena:
    """the game fiels"""

    def __init__(self,surface : Surface, dimension:Rect = None ):
        if dimension == None:
            dimension = surface.get_rect()

        self.surface = surface
        self.dimension = dimension

        self.__IDCounter = 0

        self.actors = []
        self.bullets = []
        self.power_ups = []

        self.Timer = Timer()

        self.Timer.subscribe(self.Simulate)
        self.Timer.subscribe(self.Paint)

    def Simulate(self, timepassed):
        for actor in self.actors:
            actor.Frame(timepassed)
            if not actor.disposed:
                for other_actor in self.actors:
                    if (other_actor != actor) and actor.Check_collide(other_actor):
                        PhisicEngine.Collided(actor, other_actor)
                        actor.Collide(other_actor)
                        other_actor.Collide(actor)
        for bullet in self.bullets:
            bullet.Frame(timepassed)
            if not bullet.disposed:
                for actor in self.actors:
                    if bullet.Check_collide(actor):
                        actor.Collide(bullet)
                        bullet.Collide(actor)
        for power_up in self.power_ups:
            power_up.Frame(timepassed)
            if not power_up.disposed:
                for actor in self.actors:
                    if power_up.Check_collide(actor):
                        actor.Collide(power_up)
                        power_up.Collide(actor)

    def Paint(self,timepassed):
        for actor in self.actors:
            actor.Paint()
        for bullet in self.bullets:
            bullet.Paint()
        for power_up in self.power_ups:
            power_up.Paint()

    def AddAct(self,Actor):
        self.actors.append(Actor)
    def AddBul(self,Bullet):
        self.bullets.append(Bullet)
    def AddPwu(self,PowerUp):
        self.power_ups.append(PowerUp)

    def RmvAct(self,Actor):
        if Actor in self.actors:
            self.actors.remove(Actor)
    def RmvBul(self,Bullet):
        if Bullet in self.bullets:
            self.bullets.remove(Bullet)
    def RmvPwu(self,PowerUp):
        if PowerUp in self.power_ups:
            self.power_ups.remove(PowerUp)

    def getID(self):
        self.__IDCounter += 1
        return (self.__IDCounter - 1)
    
    @staticmethod
    def wrap_to_arena(obj):
        if obj.position.x < obj.arena.dimension.left:
            obj.position.x = obj.arena.dimension.right
        elif obj.position.x > obj.arena.dimension.right:
            obj.position.x = obj.arena.dimension.left
        if obj.position.y < obj.arena.dimension.top:
            obj.position.y = obj.arena.dimension.bottom
        elif obj.position.y > obj.arena.dimension.bottom:
            obj.position.y = obj.arena.dimension.top
开发者ID:zannabianca1997,项目名称:total_shoot_out,代码行数:86,代码来源:Arena.py


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