當前位置: 首頁>>代碼示例>>Python>>正文


Python Group.has方法代碼示例

本文整理匯總了Python中pygame.sprite.Group.has方法的典型用法代碼示例。如果您正苦於以下問題:Python Group.has方法的具體用法?Python Group.has怎麽用?Python Group.has使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pygame.sprite.Group的用法示例。


在下文中一共展示了Group.has方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: EventLoop

# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import has [as 別名]
class EventLoop(object):
    def __init__(self):
        self.objs = {}
        self.events = []
        self.render = RenderUpdates()
        self.projectiles = Group()
        self.enemies = Group()
        self.you = None
        self.bg_sprite = BGSprite(pygame.display.get_surface())

        # Since we don't care about MOST EVENTS
        pygame.event.set_allowed(None)
        pygame.event.set_allowed([ MOUSEBUTTONDOWN, KEYDOWN, QUIT, UPDATEEVENT, SPAWNEVENT ])

    def add_object(self, obj, type=""):
        if isinstance(obj, HandlesEvents):
            if obj.events == ALL:
                try:
                    self.objs[ALL].append(obj)
                except KeyError:
                    self.objs[ALL] = [ obj ]
            else:
                for event in obj.events:
                    try:
                        self.objs[event].append(obj)
                    except KeyError:
                        self.objs[event] = [ obj ]
        if isinstance(obj, Sprite):
            self.render.add(obj)
            if type == "enemy":
                self.enemies.add(obj)
            if type == "projectile":
                self.projectiles.add(obj)
            if type == "you":
                self.you = obj

    def rm_object(self, obj):
        for key in self.objs.keys():
            self.render.remove(obj)
            if obj in self.objs[key]:
                self.objs[key].remove(obj)
            if self.projectiles.has(obj):
                self.projectiles.remove(obj)
            if self.enemies.has(obj):
                self.enemies.remove(obj)
            print "Removed {0}".format(obj)

    def enqueue(self, event):
        if isinstance(event, Event):
            return self.events.append(event)
        elif isinstance(event, list):
            return [ self.enqueue(ev) for ev in event ]

    def tick(self):
        try:
            event = self.events.pop()
        except IndexError:
            event = None

        if event is not None:
            if isinstance(event, TargettedEvent):
                event.get_target().handle_event(event)
                for obj in self.objs[ALL]:
                    obj.handle_event(event)
            else:
                for obj in self.objs[type(event)] + self.objs[ALL]:
                    if obj.handles_event(event):
                        obj.handle_event(event)


        if random.randint(0, 10000000) == 26:
            return win()
        if random.randint(0, 10000000) == 26:
            return lose()

        py_events = map(lambda event: PygameEvent(event), pygame.event.get())
        for py_event in py_events:
            for obj in reduce(lambda obj_list, obj: obj_list + obj, map(lambda key: self.objs[key], filter(lambda handler_type: issubclass(handler_type, PygameEvent) if handler_type != ALL else False, self.objs.keys())), []):
                if obj.handles_event(py_event):
                    obj.handle_event(py_event)
開發者ID:alecain,項目名稱:one,代碼行數:82,代碼來源:event.py


注:本文中的pygame.sprite.Group.has方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。