本文整理汇总了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