예제 #1
0
 def paste_clipboard(self):
     for obj, code in self.clipboard.iteritems():
         exec code
         exec "obj = " + obj
         self.set_selection([obj])
         (Opioid2D.Delay(1) +
          Opioid2D.CallFunc(self.avoid_node_overlap, obj)).do()
예제 #2
0
    def play_scene(self, doSave=True):
        """play_scene(doSave=True)
        
start the current scene playing. 
doSave: save working copy first
"""
        if _DEBUG: print "play_scene"
        if self.Director.project_started:
            # don't do anything if game started
            return False
        if doSave:
            saved = self.save_using_working_scene()
            if not saved:
                dlg = wx.MessageDialog(
                    self.frame,
                    "The scene failed to save properly.\nPlay anyway?",
                    'Save Failed',
                    wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
                continue_shutdown = dlg.ShowModal()
                if continue_shutdown == wx.ID_NO:
                    return False
                else:
                    self.edit_info = None
            else:
                self.play_working_scene()
        else:
            self.edit_info = None
        #self.reload_scene()
        pug.set_default_pugview("Component", _dataMethodPugview)
        #        app = wx.GetApp()
        #        app.set_selection([])
        (Opioid2D.Delay(0) + Opioid2D.CallFunc(start_scene)).do()
        return True
예제 #3
0
파일: Textbox.py 프로젝트: bcorfman/pug
 def do_set_text(self, image=None, tint=(255, 255, 255)):
     self.action = None
     if image == None:
         if self.cache_images:
             fontdata = (self.font, self.text, self.max_width, self.hotspot)
             try:
                 # look for cached image with same fontdata
                 image = Opioid2D.ResourceManager.images[fontdata]
             except KeyError:
                 # cache the image with the name fontdata as index
                 image = Opioid2D.ResourceManager._set_image(
                     fontdata, Opioid2D.Bitmap(textbox(*fontdata[0:3])),
                     fontdata[3])
         else:
             image = Opioid2D.ResourceManager._create_image(
                 Opioid2D.Bitmap(
                     textbox(self.font, self._text, self.max_width)),
                 self.hotspot)
     if self.owner:
         try:
             self.owner.set_image(image)
         except:
             self.restore_old_image()
         else:
             self.owner.image_file = None
         if getattr(Opioid2D.Director, "viewing_in_editor", False):
             import wx
             wx.CallAfter(wx.GetApp().refresh)
예제 #4
0
    def do_add_object(self, objectclass, position=None):
        """do_add_object( objectclass, position)
        
Add an object of class objectclass to the scene. Because of timing issues with 
Opioid2D, it is safer to call this via add_object. 
objectclass: class of object to add
position: move object to this position
"""
        Director.paused = True
        try:
            if not issubclass(objectclass, Node):
                if _DEBUG: print objectclass, Node
                raise TypeError(
                    "add_object(): arg 1 must be a subclass of Node")
        except:
            if _DEBUG: print objectclass, Node
            raise
        node = objectclass()
        if objectclass == Sprite and type(self.scene.state) == EditorState:
            # set a default image for basic sprite
            try:
                node.set_image("art/pug.png")
            except:
                pass
            node.position = get_display_center()
            node.layer = "Background"
        if position is not None:
            node.position = position
        Director.paused = False
        # let components do image alterations, then check for node overlap
        (Opioid2D.Delay(0.1) +
         Opioid2D.CallFunc(self.avoid_node_overlap, node)).do()
예제 #5
0
 def on_added_to_scene(self):
     """Animate when object is added to scene"""
     if self.frames:
         action = Opioid2D.Animate(self.frames, fps=self.fps, 
                                  mode=self.modes[self.mode])
         if self.destroy:
             action += Opioid2D.CallFunc(self.owner.destroy)
         self.owner.do(action)
예제 #6
0
파일: Textbox.py 프로젝트: bcorfman/pug
 def set_text(self, text=None):
     "Set the text to display"
     if text is None:
         text = self._text
     else:
         self._text = text
     if not self.action:
         self.action = (Opioid2D.Delay(0) +
                        Opioid2D.CallFunc(self.do_set_text)).do()
예제 #7
0
 def set_anim_attr(self, attr, val):
     setattr(self, attr, val)
     if not getattr(Opioid2D.Director,"start_project", False):
         if self.set_action:
             return
         self.set_action = (Opioid2D.Delay(0)+ Opioid2D.CallFunc(
                                             self.do_set_animation)).do()
     else:
         self.do_set_animation()
예제 #8
0
 def on_added_to_object(self):
     try:
         self.old_image = standardize_path(self.owner.image_file)
     except:
         pass
     try:
         (Opioid2D.Delay(0)+ Opioid2D.CallFunc( self.do_set_animation)).do()
     except:
         pass
예제 #9
0
 def on_scale(self, handle):
     node = self.node
     mouse_pos = Mouse.get_position()
     delta = Opioid2D.Vector(mouse_pos[0] - self.drag_from[0],
                             mouse_pos[1] - self.drag_from[1])
     movedir = Opioid2D.Vector()  # adjust sprite hotspot
     delta.direction -= node.rotation
     location = handle.id
     # calculate scale changes
     if 'left' in location:
         xchange = -delta[0]
         movedir[0] = -1 + (self.hotspot[0] - 0.5) * 2
     elif 'right' in location:
         xchange = delta[0]
         movedir[0] = 1 + (self.hotspot[0] - 0.5) * 2
     else:
         handle.position[0] = xchange = 0
     if 'top' in location:
         ychange = -delta[1]
         movedir[1] = -1 + (self.hotspot[1] - 0.5) * 2
     elif 'bottom' in location:
         ychange = delta[1]
         movedir[1] = 1 + (self.hotspot[1] - 0.5) * 2
     else:
         handle.position[1] = ychange = 0
     xscale = self.orig_scale[0] * (self.orig_rect[0] + xchange)\
                                         / self.orig_rect[0]
     yscale = self.orig_scale[1] * (self.orig_rect[1] + ychange)\
                                         / self.orig_rect[1]
     # check proportional scale
     if is_shift_down():
         if location in ['top', 'bottom'] or \
                     (xscale/self.orig_scale[0] > yscale/self.orig_scale[1]\
                         and not location in ['left','right']):
             xscale = self.orig_scale[0] * abs(yscale) / self.orig_scale[1]
         else:
             yscale = self.orig_scale[1] * abs(xscale) / self.orig_scale[0]
     xscale = round(xscale, 3)
     yscale = round(yscale, 3)
     node.scale = (xscale, yscale)
     # reposition sprite
     movevector = Opioid2D.Vector()
     movevector[0] = movedir[0] * (node.rect.width - self.orig_rect[0]) \
                      / 2.0
     movevector[1] = movedir[1] * (node.rect.height - self.orig_rect[1]) \
                     / 2.0
     movevector.direction += node.rotation
     node.position = self.orig_position + movevector
     # set lines and handles
     self.surround_node(force=True)
예제 #10
0
파일: sound_file.py 프로젝트: bcorfman/pug
 def test_button(self):
     "test to see if button is being held down"
     if self.sound is None:
         return
     from pygame import mixer
     if self.play_button_down:
         if mixer.get_busy():
             wx.CallLater(0.1, self.test_button)
         else:
             self.looping = True
             (Opioid2D.Delay(0) + \
                         Opioid2D.CallFunc(self.sound.play,loops=-1)).do()
             wx.CallLater(0.1, self.test_button)
     elif self.looping:
         self.sound.stop()
예제 #11
0
    def add_object(self, nodeclass=None, position=None):
        """add_object( nodeclass=None)
        
If nodeclass is None, addObjectClass will be used.
position: object will be moved to this position
"""
        if wx.GetApp().busyState:
            return
        wx.GetApp().set_busy_state()
        self.adding_object = True
        # delay hack necessary to solve Opioid2D thread problem with images
        if nodeclass is None:
            nodeclass = self.addObjectClass
        (Opioid2D.Delay(0) +
         Opioid2D.CallFunc(self.do_add_object, nodeclass, position)).do()
        wx.CallAfter(self.set_selection, [])
예제 #12
0
 def on_scale_begin(self, handle):
     node = self.node
     self.drag_from = Mouse.get_position()
     self.orig_rect = node.rect.size
     self.orig_scale = tuple(node.scale)
     self.orig_position = Opioid2D.Vector(self.node.position[0],
                                          self.node.position[1])
예제 #13
0
 def change_velocity(self, x_change, y_change):
     Key_Direction_Controls.change_velocity(self, x_change, y_change)
     vx, vy = self.owner.velocity
     dir =  None
     if vx > 0:
         if vy > 0:
             dir = "downright_frames"
         elif vy < 0:
             dir = "upright_frames"
         else:
             dir = "right_frames"
     elif vx < 0:
         if vy > 0:
             dir = "downleft_frames"
         elif vy < 0:
             dir = "upleft_frames"
         else:
             dir = "left_frames"
     elif vy > 0:
         dir = "down_frames"
     elif vy < 0:
         dir = "up_frames"
     if self.dir == dir or dir == None:
         return
     self.dir = dir
     self.frames = self.framedict[dir]
     try:
         self.anim_action.abort()
     except:
         pass
     action = Opioid2D.Animate(self.frames, fps=self.fps, 
                      mode=self.modes["Repeat"])
     if self.rotate:
         if self.image_sprite is None:
             self.image_sprite = Opioid2D.Sprite()
             self.image_sprite.attach_to(self.owner)
             self.owner.image = self.frames[0]
             self.owner.alpha = 0
         image_sprite = self.image_sprite
         image_sprite.rotation = -self.owner.rotation
     else:
         image_sprite = self.owner
     self.anim_action = action.do(image_sprite)
예제 #14
0
    def set_zone(self):
        owner = self.owner
        if self.set_to_screen:
            if owner.image:
                radius = math.hypot(owner.rect.height, owner.rect.width) * 0.5
            else:
                radius = 0
            self.x = 0 + radius
            self.y = 0 + radius
            view = Opioid2D.Display.get_view_size()
            self.xx = view[0] - radius
            self.yy = view[1] - radius
            self.width = self.height = self.radius = self.direction = self.arc\
                                                                         = None
            if self.xx is None:
                self.xx = self.x + self.width
            if self.yy is None:
                self.yy = self.y + self.height

        if not self.tick_action:
            self.tick_action = Opioid2D.TickFunc(self.check_motion_zone)
            self.tick_action.do()
예제 #15
0
 def on_added_to_scene(self):
     Key_Direction_Controls.on_added_to_scene(self)
     (Opioid2D.Delay(0) + Opioid2D.CallFunc(self.do_load_frames)).do()
예제 #16
0
파일: Life_Zone.py 프로젝트: bcorfman/pug
 def on_added_to_scene(self):
     """Start timer when object is added to scene"""
     self.owner.do(Opioid2D.CallFunc(self.set_zone))
예제 #17
0
def get_display_center():
    """get_display_center() -> coordinates of center of display"""
    return Opioid2D.Vector(*Opioid2D.Display.get_view_size()) * 0.5
예제 #18
0
 def start_pulse(self):
     pulse = Opioid2D.ColorFade((0.15, 0.2, 0.25, 1), 1.2,
                                Opioid2D.PingPongMode)
     #        pulse = Opioid2D.AlphaFade(0.2, 1.2, Opioid2D.PingPongMode)
     for sprite in self.lines.itervalues():
         sprite.do(pulse)
예제 #19
0
 def on_enter(self):
     if not Director.scene.state.mouse_locked_by and \
                 pygame.key.get_focused():
         self.tick_action = Opioid2D.TickFunc(self.test_cursor).do()
예제 #20
0
 def on_collision(self, toSprite, fromSprite, toGroup, fromGroup):
     "Call owner's destroy method on collision"
     # Setting it to delay(0) waits until all collision callbacks run
     self.owner.do(Opioid2D.Delay(0)+Opioid2D.CallFunc(self.owner.destroy))