예제 #1
0
파일: GameTile.py 프로젝트: cadryden/cad-e
 def __init__(self, loaderTile, surface, xIndex, yIndex, layer):
     """
     Create a new GameTile form the U{tiledtmxloader's<http://pygame.org/project-map+loader+for+'tiled'-1158-.html>}
     tile.
     
     @type  loaderTile:    L{Tile<tiledtmxloader.Tile>}
     @param loaderTile:    The the loader's tile object, which is converted to our own class.
     
     @type  surface:       C{U{pygame.Surface<http://www.pygame.org/docs/ref/surface.html>}}
     @param surface:       This GameTile's graphic.
     
     @type  xIndex:        C{int}
     @param xIndex:        X coordinate in the Tiled editor.
     
     @type  yIndex:        C{int}
     @param yIndex:        Y coordinate in the Tiled editor. 
     
     @type  layer:         L{GameLayer<Map.GameLayer.GameLayer>}
     @param layer:         The GameLayer this tile is on.
     """
     rect = surface.get_rect()
     rect.topleft = (xIndex * rect.width, yIndex * rect.height)
     name = 'Game Tile'
     GameObject.__init__(self, rect.topleft, rect.width, rect.height, layer, name, surface)
     
     # When creating tiles from a large image, loader does not associate Tile objects with the surfaces.
     # Handling that.
     if loaderTile == None:
         self.properties = {}
     else:
         self.properties = loaderTile.properties
예제 #2
0
파일: Actor.py 프로젝트: cadryden/cad-e
    def __init__(self, position, width, height, name, collisionGroupNames, transferName, stateMappings, startStateName, image=None, animationMappings=None, soundMappings=None, stateTransitionRestrictions=None):
        """
        Creates a new Actor.  Initializes all Actor variables, but should be extended by derived classes.
        
        @type  position:             C{(int, int)} | L{Vector<Utilities.vector.Vector>}
        @param position:             World coordinates of the top left corner of the object's bounding box.
        
        @type  width:                C{int}
        @param width:                Width of the object's bounding box in pixels.
        
        @type  height:               C{int}
        @param height:               Height of the object's bounding box in pixels.
        
        @type  name:                 C{str}
        @param name:                 Name for this Actor.
        
        @type  collisionGroupNames:  C{list}
        @param collisionGroupNames:  List of names (C{str}) of L{CollisionGroup<CollisionGroup.CollisionGroup>}s that
                                     this Actor should be part of.
                                     
        @type  transferName:         C{str}
        @param transferName:         Name of the Actor to transfer attributes from when switching between maps. 
        
        @type  stateMappings:        C{list}
        @param stateMappings:        List of pairs in the form C{str, L{State<State.State>}} which are the States available to
                                     this Actor.  In detail they are:
                                         - C{str} - Name to use to refer to this State.
                                         - C{State} - The State object.
        
        @type  startStateName:       C{str}
        @param startStateName:       Name of the L{State<State.State>} the Actor will start in.
        
        @type  image:                U{C{pygame.Surface}<http://www.pygame.org/docs/ref/surface.html>}
        @param image:                Static image that should be drawn at the object's L{Position}.
        
        @type  animationMappings:    C{list}
        @param animationMappings:    List of tuples in the form C{(str, L{Animation<Animation.Animation>}, (int, int))}.
                                     In detail they are:
                                         - C{str} - Name to use to refer to this Animation.
                                         - C{Animation} - Animation object itself.
                                         - C{(int, int)} - Offset from the GameObject's L{Position} where the top-left of the Animation's frames
                                         should be drawn.

        @type  soundMappings:        C{list}
        @param soundMappings:        List of tuples in the form C{(str, L{Sound<Sound.Sound>})}.
                                     In detail they are:
                                         - C{str} - Name to use to refer to this Sound.
                                         - C{Sound} - Sound object itself.
                                         
                                         
        @type  stateTransitionRestrictions:    C{list}
        @param stateTransitionRestrictions:    List of tuples in the form C{(str, str)}.  The first string is the originating state name
                                               and the second is the target state name.  If the first state is trying to transition into
                                               the second it will be ignored.
        """
        GameObject.__init__(self, position, width, height, None, name, image, animationMappings, soundMappings)
        
        # collision groups
        self.cgroupNames = collisionGroupNames
        self._collisionGroups = []
        self._collisions = set()
        
        # states
        self._stateMappings = {}
        for name, state in stateMappings:
            self._stateMappings[name] = state
        
        # state restrictions
        self._restrictedStateTrans = []
        if self._restrictedStateTrans:
            for statePair in stateTransitionRestrictions:
                self._restrictedStateTrans.append(statePair)
        
        # velocities are in pixels/second
        self._velocity = Vector((0, 0))
        self._prevPosition = Vector(self.Position)
        
        # some maximum values
        self._maxXVel = Constants.ActorConstants.MAX_X_VELOCITY
        self._maxYVel = Constants.ActorConstants.MAX_Y_VELOCITY
        
        # make sure the state is setup correctly
        self._currentState = self._stateMappings[startStateName]
        self._currentState.OnEnter()
        
        # effects
        self._effects = []
        
        # map transition
        self._transferFromName = transferName