コード例 #1
0
ファイル: utils.py プロジェクト: ddmbr/serge-template
def addActorToWorld(world, actor, sprite_name=None, layer_name=None, center_position=None, physics=None, origin=None):
    """Create a new actor in the world
    
    If the center position is not specified then it is placed at the center of the screen.
    
    """
    #
    # If not position then put at the center
    if origin is None and center_position is None:
        renderer = serge.engine.CurrentEngine().getRenderer()
        center_position = (renderer.width/2.0, renderer.height/2.0)
    #
    # Create the new actor
    if sprite_name is not None:
        actor.setSpriteName(sprite_name)
    if layer_name is not None:
        actor.setLayerName(layer_name)
    if physics:
        actor.setPhysical(physics)
    if center_position is not None:
        actor.moveTo(*center_position)
    else:
        actor.setOrigin(*origin)
    world.addActor(actor)
    return actor
コード例 #2
0
 def _redoLocations(self):
     """Reset the locations of the objects within us"""
     self.log.debug("Resetting locations")
     if self.children:
         for i, actor in enumerate(self.children):
             actor.moveTo(*self.getCoords(i))
             self.log.debug("Set %s to %d, %d" % (actor.getNiceName(), actor.x, actor.y))
コード例 #3
0
ファイル: xutils.py プロジェクト: kalaorav/Bomberman
def addActorToWorld(world, actor, sprite_name=None, layer_name=None, center_position=None, physics=None, origin=None):
    """Create a new actor in the world
    
    If the center position is not specified then it is placed at the center of the screen.
    
    """
    #
    # If not position then put at the center
    if origin is None and center_position is None:
        renderer = serge.engine.CurrentEngine().getRenderer()
        center_position = (renderer.width/2.0, renderer.height/2.0)
    #
    # Create the new actor
    if sprite_name is not None:
        actor.setSpriteName(sprite_name)
    if layer_name is not None:
        actor.setLayerName(layer_name)
    if physics:
        actor.setPhysical(physics)
    if center_position is not None:
        actor.moveTo(*center_position)
    else:
        actor.setOrigin(*origin)
    world.addActor(actor)
    return actor
コード例 #4
0
def addVisualActorToWorld(world,
                          tag,
                          name,
                          visual,
                          layer_name,
                          center_position=None,
                          physics=None):
    """Create a new actor in the world and set the visual 
    
    If the center position is not specified then it is placed at the center of the screen.
    
    """
    #
    # If not position then put at the center
    if center_position is None:
        renderer = serge.engine.CurrentEngine().getRenderer()
        center_position = (renderer.width / 2.0, renderer.height / 2.0)
    #
    # Create the new actor
    actor = serge.actor.Actor(tag, name)
    actor.visual = visual
    actor.setLayerName(layer_name)
    if physics:
        actor.setPhysical(physics)
    actor.moveTo(*center_position)
    world.addActor(actor)
    return actor
コード例 #5
0
ファイル: layout.py プロジェクト: gregpuzzles1/Sandbox
 def _redoLocations(self):
     """Reset the locations of the objects within us"""
     self.log.info('Resetting locations')
     width = float(self.width) / len(self._actors)
     left, top, _, _ = self.getSpatial()
     for i, actor in enumerate(self._actors):
         actor.moveTo(left + width*(i+0.5), top + self.height*0.5)
         self.log.debug('Set %s to %d, %d' % (actor.getNiceName(), actor.x, actor.y))
コード例 #6
0
ファイル: layout.py プロジェクト: kalaorav/Bomberman
 def _redoLocations(self):
     """Reset the locations of the objects within us"""
     self.log.debug('Resetting locations')
     if self.children:
         for i, actor in enumerate(self.children):
             actor.moveTo(*self.getCoords(i))
             self.log.debug('Set %s to %d, %d' %
                            (actor.getNiceName(), actor.x, actor.y))
コード例 #7
0
ファイル: layout.py プロジェクト: ddmbr/Roaring-Engine
 def _redoLocations(self):
     """Reset the locations of the objects within us"""
     self.log.debug('Resetting locations')
     if self.children:
         height = float(self.height) / len(self.children)
         left, top, _, _ = self.getSpatial()
         for i, actor in enumerate(self.children):
             actor.moveTo(left + self.width*0.5, top + height*(i+0.5))
             self.log.debug('Set %s to %d, %d' % (actor.getNiceName(), actor.x, actor.y))
コード例 #8
0
ファイル: layout.py プロジェクト: gregpuzzles1/Sandbox
 def _redoLocations(self):
     """Reset the locations of the objects within us"""
     self.log.info('Resetting locations')
     width = float(self.width) / len(self._actors)
     left, top, _, _ = self.getSpatial()
     for i, actor in enumerate(self._actors):
         actor.moveTo(left + width * (i + 0.5), top + self.height * 0.5)
         self.log.debug('Set %s to %d, %d' %
                        (actor.getNiceName(), actor.x, actor.y))
コード例 #9
0
 def _redoLocations(self):
     """Reset the locations of the objects within us"""
     self.log.debug("Resetting locations")
     if self.children:
         height = self.item_height if self.item_height else float(self.height) / len(self.children)
         left = self.getSpatial()[0]
         top = self.y if self.item_height else self.getSpatial()[1]
         for i, actor in enumerate(self.children):
             actor.moveTo(left + self.width * 0.5, top + height * (i + 0.5))
             self.log.debug("Set %s to %d, %d" % (actor.getNiceName(), actor.x, actor.y))
コード例 #10
0
ファイル: layout.py プロジェクト: kalaorav/Bomberman
 def _redoLocations(self):
     """Reset the locations of the objects within us"""
     self.log.debug('Resetting locations')
     if self.children:
         height = float(self.height) / len(self.children)
         left, top, _, _ = self.getSpatial()
         for i, actor in enumerate(self.children):
             actor.moveTo(left + self.width * 0.5, top + height * (i + 0.5))
             self.log.debug('Set %s to %d, %d' %
                            (actor.getNiceName(), actor.x, actor.y))
コード例 #11
0
 def linkActorTo(self, actor, move=False, link_length=False):
     """Link an actor to ourself"""
     #
     # Move the other actor if needed
     if move:
         actor.moveTo(self.x, self.y)
     #
     # Don't link too close
     length = 0 if not link_length else self.getDistanceFrom(actor)
     j = pymunk.SlideJoint(self.getPhysical().body, actor.getPhysical().body, (0,0), (0,0), 0, 
         max(length, link_length+self.width/2))
     self.getPhysical().space.add(j)
     actor.point_link = j        
     self.log.debug('Linked %s (%s) and %s (%s) with length %s (%s)' % (
         self.getNiceName(), (self.x, self.y), actor, (actor.x, actor.y), link_length+self.width/2,
         self.getDistanceFrom(actor)))
     #
     # Wake up the rope if needed
     if self.parent is not None:
         self.parent.wakeUp()
コード例 #12
0
ファイル: utils.py プロジェクト: gregpuzzles1/Sandbox
def addVisualActorToWorld(world, tag, name, visual, layer_name, center_position=None, physics=None):
    """Create a new actor in the world and set the visual 
    
    If the center position is not specified then it is placed at the center of the screen.
    
    """
    #
    # If not position then put at the center
    if center_position is None:
        renderer = serge.engine.CurrentEngine().getRenderer()
        center_position = (renderer.width/2.0, renderer.height/2.0)
    #
    # Create the new actor
    actor = serge.actor.Actor(tag, name)
    actor.visual = visual
    actor.setLayerName(layer_name)
    if physics:
        actor.setPhysical(physics)
    actor.moveTo(*center_position)
    world.addActor(actor)
    return actor
コード例 #13
0
        else:
            raise CellOccupied(
                "The cell %s is already occupied by %s in grid %s"
                % ((x, y), occupant.getNiceName(), self.getNiceName())
            )
        #
        # Add to the grid
        try:
            self._grid[x][y] = actor
        except IndexError:
            raise OutOfRange("%s is out of the range of this grid (%s)" % ((x, y), self.getNiceName()))
        #
        # Now make sure that we update everything
        self.addChild(actor)
        actor.setLayerName(self.getLayerName() if layer_name is None else layer_name)
        actor.moveTo(*self.getCoords((x, y)))
        self.log.debug("Set coords for %s to %d, %d" % (actor.getNiceName(), actor.x, actor.y))
        return actor

    def autoAddActor(self, actor):
        """Automatically add an actor to the next cell in the grid
        
        This fills horizontally and then vertically
        
        """
        self.addActor((self._added % len(self._grid), self._added // len(self._grid)), actor)
        self._added += 1
        return actor

    def moveActor(self, (x, y), actor):
        """Move an actor from wherever it is to the new location"""
コード例 #14
0
ファイル: layout.py プロジェクト: kalaorav/Bomberman
            raise CellOccupied(
                'The cell %s is already occupied by %s in grid %s' %
                ((x, y), occupant.getNiceName(), self.getNiceName()))
        #
        # Add to the grid
        try:
            self._grid[x][y] = actor
        except IndexError:
            raise OutOfRange('%s is out of the range of this grid (%s)' %
                             ((x, y), self.getNiceName()))
        #
        # Now make sure that we update everything
        self.addChild(actor)
        actor.setLayerName(
            self.getLayerName() if layer_name is None else layer_name)
        actor.moveTo(*self.getCoords((x, y)))
        self.log.debug('Set coords for %s to %d, %d' %
                       (actor.getNiceName(), actor.x, actor.y))
        return actor

    def autoAddActor(self, actor):
        """Automatically add an actor to the next cell in the grid
        
        This fills horizontally and then vertically
        
        """
        self.addActor(
            (self._added % len(self._grid), self._added // len(self._grid)),
            actor)
        self._added += 1
        return actor