Beispiel #1
0
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
 def addedToWorld(self, world):
     """Added to the world"""
     super(MusicGrid, self).addedToWorld(world)
     #
     # Set up the grid to show the state
     self.layout = serge.blocks.utils.addActorToWorld(
         world,
         serge.blocks.layout.Grid(
             'grid', 'grid', self.size, G('grid-width'), G('grid-height'),
             background_colour=G('grid-background-colour'), background_layer='background',
         ),
         layer_name='main',
         center_position=G('grid-position'),
     )
     #
     # Add actors
     for ix in range(self.size[0]):
         for iy in range(self.size[1]):
             actor = serge.actor.Actor('cell', 'cell-%d-%d' % (ix, iy))
             actor.setSpriteName('null')
             actor.setLayerName('main')
             actor.linkEvent(serge.events.E_LEFT_CLICK, self.cellClick, (ix, iy))
             self.layout.addActor((ix, iy), actor)
     #
     world.addActor(self.automaton)
Beispiel #3
0
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
Beispiel #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
Beispiel #5
0
 def addActor(self, actor, layer_name=None):
     """Add an actor to the bar"""
     self.addChild(actor)
     self._redoLocations()
     actor.setLayerName(
         self.getLayerName() if layer_name is None else layer_name)
     return actor
Beispiel #6
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
            pass
        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):
Beispiel #8
0
 def setLayerName(self, name):
     """Set the layer name"""
     super(Container, self).setLayerName(name)
     for actor in self.iterActors():
         actor.setLayerName(name)
Beispiel #9
0
 def setLayerName(self, name):
     """Set the layer name"""
     super(Container, self).setLayerName(name)
     for actor in self.iterActors():
         actor.setLayerName(name)    
Beispiel #10
0
        try:
            occupant = self.getActorAt((x, y))
        except CellEmpty:
            pass
        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._changes.append(('add', actor))
        actor.setLayerName(self.getLayerName())
        actor.moveTo(*self._getCoords((x, y)))
        self.log.debug('Set coords for %s to %d, %d' % (actor.getNiceName(), actor.x, actor.y))

    def getActorAt(self, (x, y)):
        """Return the actor at a certain location"""
        try:
            occupant = self._grid[x][y]
        except IndexError:
            raise OutOfRange('%s is out of the range of this grid (%s)' % ((x, y), self.getNiceName()))
        else:
            if occupant is None:
                raise CellEmpty('The cell %s in grid %s is empty' % ((x, y), self.getNiceName()))
            else:
                return occupant
Beispiel #11
0
 def setLayerName(self, name):
     """Set the layer name"""
     super(Container, self).setLayerName(
         self.background_layer if self.background_layer else name)
     for actor in self.getChildren():
         actor.setLayerName(name)
Beispiel #12
0
            pass
        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
Beispiel #13
0
 def addActor(self, actor):
     """Add an actor to the bar"""
     self._actors.append(actor)
     self._changes.append(('add', actor))
     self._redoLocations()
     actor.setLayerName(self.getLayerName())
 def addActor(self, actor, layer_name=None):
     """Add an actor to the bar"""
     self.addChild(actor)
     self._redoLocations()
     actor.setLayerName(self.getLayerName() if layer_name is None else layer_name)
     return actor
Beispiel #15
0
 def addActor(self, actor):
     """Add an actor to the bar"""
     self._actors.append(actor)
     self._changes.append(('add', actor))
     self._redoLocations()
     actor.setLayerName(self.getLayerName())
 def setLayerName(self, name):
     """Set the layer name"""
     super(Container, self).setLayerName(self.background_layer if self.background_layer else name)
     for actor in self.getChildren():
         actor.setLayerName(name)
Beispiel #17
0
            pass
        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._changes.append(('add', actor))
        actor.setLayerName(self.getLayerName())
        actor.moveTo(*self._getCoords((x, y)))
        self.log.debug('Set coords for %s to %d, %d' %
                       (actor.getNiceName(), actor.x, actor.y))

    def getActorAt(self, (x, y)):
        """Return the actor at a certain location"""
        try:
            occupant = self._grid[x][y]
        except IndexError:
            raise OutOfRange('%s is out of the range of this grid (%s)' %
                             ((x, y), self.getNiceName()))
        else:
            if occupant is None:
                raise CellEmpty('The cell %s in grid %s is empty' %
                                ((x, y), self.getNiceName()))