예제 #1
0
 def on_activate(self):
     self._Cprepare(_c.FollowPath, len(self.points), self.lead, self.align)
     ObjectManager.register(self)
     for i,p in enumerate(self.points):
         self._cObj.SetPoint(i, _c.Vec2(*p))
     self._cObj.SetSpeed(self.speed)
     self._cObj.Start()
예제 #2
0
 def on_activate(self):
     self._Cprepare(_c.FollowPath, len(self.points), self.lead, self.align)
     ObjectManager.register(self)
     for i, p in enumerate(self.points):
         self._cObj.SetPoint(i, _c.Vec2(*p))
     self._cObj.SetSpeed(self.speed)
     self._cObj.Start()
예제 #3
0
 def __init__(self, layer):
     self._cObj = _c.ParticleSystem()
     ObjectManager.register(self)
     l = Director.scene._cObj.GetLayer(layer)
     if l is None:
         raise ValueError("no layer named %r" % layer)
     self._cObj.Place(l)
     self.mutators = set()
예제 #4
0
 def __init__(self, layer):
     self._cObj = _c.ParticleSystem()
     ObjectManager.register(self)
     l = Director.scene._cObj.GetLayer(layer)
     if l is None:
         raise ValueError("no layer named %r" % layer)
     self._cObj.Place(l)
     self.mutators = set()
예제 #5
0
 def _Cactivate(self, cls, *arg):
     self._Cprepare(cls, *arg)
     if self.mode not in (StopMode, RepeatMode, PingPongMode):
         raise ValueError("invalid mode for interval action: %r" % self.mode)
     self._cObj.SetInterval(self.secs, self.mode)
     if self.fadein is not None:
         self._cObj.SetSmoothing(self.fadein, self.fadeout)
     self._cObj.Start()
     ObjectManager.register(self)
예제 #6
0
 def _Cactivate(self, cls, *arg):
     self._Cprepare(cls, *arg)
     if self.mode not in (StopMode, RepeatMode, PingPongMode):
         raise ValueError("invalid mode for interval action: %r" %
                          self.mode)
     self._cObj.SetInterval(self.secs, self.mode)
     if self.fadein is not None:
         self._cObj.SetSmoothing(self.fadein, self.fadeout)
     self._cObj.Start()
     ObjectManager.register(self)
예제 #7
0
파일: Scene.py 프로젝트: bcorfman/pug
def OnCollision(self, group1, group2, sprite1, sprite2):
    """Override so that the collision callback sig is:
callback( toSprite, fromSprite, toGroup, fromGroup)
"""
    try:
        sprite1 = ObjectManager.c2py(sprite1)
        sprite2 = ObjectManager.c2py(sprite2)
        func = self.scene._collision_handlers[group1,group2]
        func(sprite1, sprite2, group1, group2)
    except:
        traceback.print_exc(file=sys.stdout)
        raise
예제 #8
0
파일: opi2d.py 프로젝트: bcorfman/opioid2d
 def cleanup(self):
     SpritePool.clear()
     SpritePool.clearing = True
     Director._cDirector.SetScene(None)
     ObjectManager.purge()
     ObjectManager.purge()
     #print "purged"
     Display._cDisplay = None
     ObjectManager.objects.clear()
     #print "cleared"
     Director.scene = None
     #print "scene detached"
     _c.Director.Destroy()
     #print "cDirector destroyed"
     #print "quitting"
     _c.QuitOpioid2D()
예제 #9
0
파일: opi2d.py 프로젝트: bcorfman/opioid2d
 def cleanup(self):
     SpritePool.clear()
     SpritePool.clearing = True
     Director._cDirector.SetScene(None)
     ObjectManager.purge()
     ObjectManager.purge()
     #print "purged"        
     Display._cDisplay = None
     ObjectManager.objects.clear()
     #print "cleared"
     Director.scene = None
     #print "scene detached"
     _c.Director.Destroy()
     #print "cDirector destroyed"
     #print "quitting"
     _c.QuitOpioid2D()
예제 #10
0
 def tick(self, evs):
     mx, my = Mouse.get_position()
     scene = Director.get_scene()
     results = []
     i = 0
     for e in self._elements:
         l = e.get_root_layer()
         wx, wy = l.convert_pos(mx, my)
         p = e._cObj.Pick(_c.Vec2(wx, wy))
         p = ObjectManager.c2py(p)
         if self._drag and self._drag._element is p:
             continue
         if p and p in self._elements:
             idx = scene.layers.index(l.get_name())
             results.append((idx, i, p))
             i += 1
     if not results:
         under = None
     else:
         results.sort()
         under = results[-1][2]
     self._update_under(under)
     if under is not None:
         under.on_hover()
     for ev in evs:
         if ev.type == pygame.MOUSEBUTTONDOWN:
             self._clicking = under
             if under is not None:
                 under.on_press()
         elif ev.type == pygame.MOUSEBUTTONUP:
             if self._drag is not None:
                 self._drag._update_pos(mx, my)
                 self._drag._element.on_drag_end()
                 if self._under is not None and self._under is not self._drag._element:
                     self._under.on_exit()
                     self._under = self._drag._element
                 self._drag = None
                 self._clicking.on_release()
                 self._clicking = None
             elif self._clicking is not None:
                 self._clicking.on_release()
                 self._clicking.on_click()
                 self._clicking = None
         elif ev.type == pygame.MOUSEMOTION and self._clicking is under:
             if self._drag is None and under is not None and under.draggable:
                 self._drag = Drag(under, (wx, wy))
                 under.on_drag_begin()
                 self._under = None
     if self._drag is not None:
         self._drag._element.on_drag()
         self._drag._update_pos(mx, my)
예제 #11
0
 def tick(self, evs):
     mx,my = Mouse.get_position()
     scene = Director.get_scene()
     results = []
     i = 0
     for e in self._elements:
         l = e.get_root_layer()
         wx,wy = l.convert_pos(mx,my)
         p = e._cObj.Pick(_c.Vec2(wx,wy))
         p = ObjectManager.c2py(p)
         if self._drag and self._drag._element is p:
             continue
         if p and p in self._elements:
             idx = scene.layers.index(l.get_name())
             results.append((idx,i,p))
             i += 1
     if not results:
         under = None
     else:
         results.sort()
         under = results[-1][2]
     self._update_under(under)
     if under is not None:
         under.on_hover()
     for ev in evs:
         if ev.type == pygame.MOUSEBUTTONDOWN:
             self._clicking = under
             if under is not None:
                 under.on_press()
         elif ev.type == pygame.MOUSEBUTTONUP:
             if self._drag is not None:
                 self._drag._update_pos(mx,my)
                 self._drag._element.on_drag_end()                    
                 if self._under is not None and self._under is not self._drag._element:
                     self._under.on_exit()
                     self._under = self._drag._element
                 self._drag = None
                 self._clicking.on_release()
                 self._clicking = None
             elif self._clicking is not None:
                 self._clicking.on_release()
                 self._clicking.on_click()
                 self._clicking = None
         elif ev.type == pygame.MOUSEMOTION and self._clicking is under:
             if self._drag is None and under is not None and under.draggable:
                 self._drag = Drag(under,(wx,wy))
                 under.on_drag_begin()
                 self._under = None
     if self._drag is not None:
         self._drag._element.on_drag()
         self._drag._update_pos(mx,my)
예제 #12
0
 def _Cactivate(self, cls, *arg):
     self._Cprepare(cls, *arg)
     ObjectManager.register(self)
     self._cObj.Start()
예제 #13
0
파일: Light.py 프로젝트: bcorfman/opioid2d
 def __init__(self):
     self._cObj = _c.Light()
     ObjectManager.register(self)
예제 #14
0
 def __init__(self, cobj):
     self._cObj = cobj
     ObjectManager.register(self)        
예제 #15
0
 def c_pop(self, f):
     p = f.popSprite()
     from Opioid2D.internal.objectmgr import ObjectManager
     p = ObjectManager.c2py(p)
     return p
예제 #16
0
파일: types.py 프로젝트: bcorfman/opioid2d
 def c_pop(self, f):
     p = f.popSprite()
     from Opioid2D.internal.objectmgr import ObjectManager
     p = ObjectManager.c2py(p)
     return p
예제 #17
0
 def pick(self, x, y):
     sprite = self._cObj.Pick(_c.Vec2(x,y))
     return ObjectManager.c2py(sprite)
예제 #18
0
 def __iter__(self):
     v = self._cObj.ListSprites()
     l = (ObjectManager.c2py(obj) for obj in v)
     return l
예제 #19
0
    def tick(self, evs=None):
        mx, my = Mouse.get_position()
        self._pos_dict = {'root': (mx, my)}
        scene = PigDirector.get_scene()
        results = []
        i = 0
        for e in self._single_objects:
            l = e.get_root_layer()
            if not l:
                continue
            wx, wy = self.get_relative_pos(l)
            p = e._cObj.Pick(_c.Vec2(wx, wy))
            p = ObjectManager.c2py(p)
            if self._drag and self._drag._object is p:
                continue
            if p and p in self._single_objects:
                idx = scene.layers.index(l.get_name())
                results.append((idx, i, p))
                i += 1
        if results:
            results.sort()
            under = [results[-1][2]]


#            under[0].on_hover()
        else:
            under = []
            for e in self._multi_objects:
                l = e.get_root_layer()
                if not l:
                    continue
                wx, wy = self.get_relative_pos(l)
                p = e._cObj.Pick(_c.Vec2(wx, wy))
                p = ObjectManager.c2py(p)
                if self._drag and self._drag._object is p:
                    continue
                if p and p in self._multi_objects:
                    under.append(p)
        if not pygame.mouse.get_focused():
            under = []
        self._update_under(under)
        for ev in evs:
            if ev.type == pygame.MOUSEBUTTONDOWN:
                self._clicking = under
                for object in under:
                    object.on_press()
                for e in self._click_objects:
                    l = e.get_root_layer()
                    if not l:
                        continue
                    wx, wy = self.get_relative_pos(l)
                    p = e._cObj.Pick(_c.Vec2(wx, wy))
                    p = ObjectManager.c2py(p)
                    if p and p in self._click_objects:
                        self._clicking.append(p)
                        p.on_press()
            elif ev.type == pygame.MOUSEBUTTONUP:
                if self._drag is not None:
                    self._drag._update_pos(mx, my)
                    self._drag._object.on_drag_end()
                    self._drag._object.on_release()
                    self._drag = None
                    self._clicking = []
                elif self._clicking != []:
                    for object in self._clicking:
                        if object in self._under:
                            object.on_click()
                    self._clicking = []
                for object in self._under:
                    object.on_release()
            elif ev.type == pygame.MOUSEMOTION and self._clicking != []:
                dragger = None
                if len(self._clicking) > 1:
                    results = []
                    i = 0
                    for object in self._clicking:
                        if not object.draggable:
                            continue
                        idx = scene.layers.index(
                            object.get_root_layer().get_name())
                        results.append((idx, i, object))
                    results.sort()
                    dragger = results[-1][2]
                elif self._clicking[0].draggable:
                    dragger = self._clicking[0]
                if self._drag is None and dragger is not None:
                    l = dragger.get_root_layer()
                    if l:
                        wx, wy = self.get_relative_pos(l)
                        self._drag = Drag(dragger, (wx, wy))
                        dragger.on_drag_begin()
                        try:
                            self._under.remove(dragger)
                        except:
                            pass
                    self._clicking = []
        if self._drag is not None:
            self._drag._update_pos(mx, my)
            self._drag._object.on_drag()
예제 #20
0
 def __init__(self, cobj):
     self._cObj = cobj
     ObjectManager.register(self)
예제 #21
0
    def tick(self, evs=None):
        mx,my = Mouse.get_position()
        self._pos_dict = {'root':(mx,my)}
        scene = PigDirector.get_scene()
        results = []
        i = 0
        for e in self._single_objects:
            l = e.get_root_layer()
            if not l:
                continue
            wx,wy = self.get_relative_pos(l)
            p = e._cObj.Pick(_c.Vec2(wx,wy))
            p = ObjectManager.c2py(p)
            if self._drag and self._drag._object is p:
                continue
            if p and p in self._single_objects:
                idx = scene.layers.index(l.get_name())
                results.append((idx,i,p))
                i += 1
        if results:
            results.sort()
            under = [results[-1][2]]
#            under[0].on_hover()
        else:
            under = []
            for e in self._multi_objects:
                l = e.get_root_layer()
                if not l:
                    continue
                wx,wy = self.get_relative_pos(l)
                p = e._cObj.Pick(_c.Vec2(wx,wy))
                p = ObjectManager.c2py(p)
                if self._drag and self._drag._object is p:
                    continue
                if p and p in self._multi_objects:
                    under.append(p)
        if not pygame.mouse.get_focused():
            under = []
        self._update_under(under)
        for ev in evs:
            if ev.type == pygame.MOUSEBUTTONDOWN:
                self._clicking = under
                for object in under:
                    object.on_press()
                for e in self._click_objects:
                    l = e.get_root_layer()
                    if not l:
                        continue
                    wx,wy = self.get_relative_pos(l)
                    p = e._cObj.Pick(_c.Vec2(wx,wy))
                    p = ObjectManager.c2py(p)
                    if p and p in self._click_objects:
                        self._clicking.append(p)
                        p.on_press()
            elif ev.type == pygame.MOUSEBUTTONUP:
                if self._drag is not None:
                    self._drag._update_pos(mx,my)
                    self._drag._object.on_drag_end()
                    self._drag._object.on_release()                  
                    self._drag = None
                    self._clicking = []
                elif self._clicking != []:
                    for object in self._clicking:
                        if object in self._under:
                            object.on_click()
                    self._clicking = []
                for object in self._under:
                    object.on_release()
            elif ev.type == pygame.MOUSEMOTION and self._clicking != []:
                dragger = None
                if len(self._clicking) > 1:
                    results = []
                    i = 0
                    for object in self._clicking:
                        if not object.draggable:
                            continue
                        idx = scene.layers.index(
                                            object.get_root_layer().get_name())
                        results.append((idx, i, object))
                    results.sort()
                    dragger = results[-1][2]
                elif self._clicking[0].draggable:
                    dragger = self._clicking[0] 
                if self._drag is None and dragger is not None:
                    l = dragger.get_root_layer()
                    if l: 
                        wx,wy = self.get_relative_pos(l)
                        self._drag = Drag(dragger,(wx,wy))
                        dragger.on_drag_begin()
                        try:    
                            self._under.remove(dragger)
                        except:
                            pass
                    self._clicking = []
        if self._drag is not None:
            self._drag._update_pos(mx,my)
            self._drag._object.on_drag()
예제 #22
0
 def _Cactivate(self, cls, *arg):
     self._Cprepare(cls, *arg)
     ObjectManager.register(self)
     self._cObj.Start()