Exemple #1
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()
Exemple #2
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()
Exemple #3
0
 def enter(self, font_file=None, font_size=None, unpause_keys=[]):
     from pug.all_components import Textbox
     from pig import Sprite
     from pig.util import get_display_center
     PauseState.enter( self, unpause_keys=unpause_keys)
     backSprite = Sprite()
     backSprite.set_image('art/block.png')
     backSprite.color = (0, 0, 0, 0.8)
     backSprite.set_layer('__pause__')
     gameOverSprite = Sprite()
     pressKeySprite = Sprite()
     textarg = {'text':'GAME OVER', 'hotspot':(0.5, 0.5)}
     if font_file:
         textarg['font_file']=font_file
     if font_size:
         textarg['font_size']=font_size
     text = gameOverSprite.components.add( Textbox( **textarg))
     text.do_set_text() # have to do it manually because we're paused
     textarg['text'] = 'Press Any Key'
     text = pressKeySprite.components.add( Textbox( **textarg))
     text.do_set_text()
     gameOverSprite.position = get_display_center()
     pressKeySprite.position = (gameOverSprite.position[0],
                                gameOverSprite.position[1] + \
                                gameOverSprite.image.get_height())
     backSprite.scale = (max(gameOverSprite.image.get_width(),
                             pressKeySprite.image.get_width()) / 2.0, 
                         (gameOverSprite.image.get_height() + \
                         pressKeySprite.image.get_height()) / 2.0)
     backSprite.position = (gameOverSprite.position[0],
                            (gameOverSprite.position[1] + \
                             pressKeySprite.position[1]) / 2.0 )
     gameOverSprite.set_layer('__text__')
     pressKeySprite.set_layer('__text__')
     self.gameOverSprite = gameOverSprite
     self.starttime = time.time()
     self.restart = False
Exemple #4
0
 def enter(self, font_file=None, font_size=None, unpause_keys=[]):
     from pug.all_components import Textbox
     from pig import Sprite
     from pig.util import get_display_center
     PauseState.enter(self, unpause_keys=unpause_keys)
     backSprite = Sprite()
     backSprite.set_image('art/block.png')
     backSprite.color = (0, 0, 0, 0.8)
     backSprite.set_layer('__pause__')
     gameOverSprite = Sprite()
     pressKeySprite = Sprite()
     textarg = {'text': 'GAME OVER', 'hotspot': (0.5, 0.5)}
     if font_file:
         textarg['font_file'] = font_file
     if font_size:
         textarg['font_size'] = font_size
     text = gameOverSprite.components.add(Textbox(**textarg))
     text.do_set_text()  # have to do it manually because we're paused
     textarg['text'] = 'Press Any Key'
     text = pressKeySprite.components.add(Textbox(**textarg))
     text.do_set_text()
     gameOverSprite.position = get_display_center()
     pressKeySprite.position = (gameOverSprite.position[0],
                                gameOverSprite.position[1] + \
                                gameOverSprite.image.get_height())
     backSprite.scale = (max(gameOverSprite.image.get_width(),
                             pressKeySprite.image.get_width()) / 2.0,
                         (gameOverSprite.image.get_height() + \
                         pressKeySprite.image.get_height()) / 2.0)
     backSprite.position = (gameOverSprite.position[0],
                            (gameOverSprite.position[1] + \
                             pressKeySprite.position[1]) / 2.0 )
     gameOverSprite.set_layer('__text__')
     pressKeySprite.set_layer('__text__')
     self.gameOverSprite = gameOverSprite
     self.starttime = time.time()
     self.restart = False