
[Jc           @   s  d  Z  d d l Z d d l m Z d d l m Z y d d l m Z Wn n Xd e f d     YZ d e f d	     YZ	 d
 e f d     YZ
 d e
 f d     YZ e Z e Z d e f d     YZ d e f d     YZ d e
 f d     YZ d e f d     YZ d e
 f d     YZ d   Z d f  d     YZ d   Z d e f d     YZ d   Z e d  Z e d   Z e d!  Z d S("   s	  pygame module with basic game object classes

This module contains several simple classes to be used within games. There
is the main Sprite class and several Group classes that contain Sprites.
The use of these classes is entirely optional when using Pygame. The classes
are fairly lightweight and only provide a starting place for the code
that is common to most games.

The Sprite class is intended to be used as a base class for the different
types of objects in the game. There is also a base Group class that simply
stores sprites. A game could create new types of Group classes that operate
on specially customized Sprite instances they contain.

The basic Sprite class can draw the Sprites it contains to a Surface. The
Group.draw() method requires that each Sprite have a Surface.image attribute
and a Surface.rect. The Group.clear() method requires these same attributes,
and can be used to erase all the Sprites with background. There are also
more advanced Groups: pygame.sprite.RenderUpdates() and
pygame.sprite.OrderedUpdates().

Lastly, this module contains several collision functions. These help find
sprites inside multiple groups that have intersecting bounding rectangles.
To find the collisions, the Sprites are required to have a Surface.rect
attribute assigned.

The groups are designed for high efficiency in removing and adding Sprites
to them. They also allow cheap testing to see if a Sprite already exists in
a Group. A given Sprite can exist in any number of groups. A game could use 
some groups to control object rendering, and a completely separate set of 
groups to control interaction or player movement. Instead of adding type 
attributes or bools to a derived Sprite class, consider keeping the 
Sprites inside organized Groups. This will allow for easier lookup later 
in the game.

Sprites and Groups manage their relationships with the add() and remove()
methods. These methods can accept a single or multiple targets for 
membership.  The default initializers for these classes also takes a 
single or list of targets for initial membership. It is safe to repeatedly 
add and remove the same Sprite from a Group.

While it is possible to design sprite and group classes that don't derive 
from the Sprite and AbstractGroup classes below, it is strongly recommended 
that you extend those when you add a Sprite or Group class.

Sprites are not thread safe.  So lock them yourself if using threads.
iN(   t   Rect(   t	   get_ticks(   t   from_surfacet   Spritec           B   sh   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z RS(   s  simple base class for visible game objects
    pygame.sprite.Sprite(*groups): return Sprite

    The base class for visible game objects. Derived classes will want to 
    override the Sprite.update() and assign a Sprite.image and 
    Sprite.rect attributes.  The initializer can accept any number of 
    Group instances to be added to.

    When subclassing the Sprite, be sure to call the base initializer before
    adding the Sprite to Groups.
    c         G   s#   i  |  _  | r |  j |  n  d  S(   N(   t
   _Sprite__gt   add(   t   selft   groups(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   __init__p   s    	 c         G   si   |  j  j } xV | D]N } t | d  rT | |  sa | j |   |  j |  qa q |  j |   q Wd S(   s   add the sprite to groups
        Sprite.add(*groups): return None

        Any number of Group instances can be passed as arguments. The 
        Sprite will be added to the Groups it is not already a member of.
        t   _spritegroupN(   R   t   __contains__t   hasattrt   add_internalR   (   R   R   t   hast   group(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   t   s    c         G   si   |  j  j } xV | D]N } t | d  rT | |  ra | j |   |  j |  qa q |  j |   q Wd S(   s   remove the sprite from groups
        Sprite.remove(*groups): return None

        Any number of Group instances can be passed as arguments. The Sprite will
        be removed from the Groups it is currently a member of.
        R	   N(   R   R
   R   t   remove_internalt   remove(   R   R   R   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR      s    c         C   s   d |  j  | <d  S(   Ni    (   R   (   R   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR      s    c         C   s   |  j  | =d  S(   N(   R   (   R   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR      s    c         G   s   d S(   s  method to control sprite behavior
        Sprite.update(*args):

        The default implementation of this method does nothing; it's just a
        convenient "hook" that you can override. This method is called by
        Group.update() with whatever arguments you give it.

        There is no need to use this method if not using the convenience 
        method by the same name in the Group class.
        N(    (   R   t   args(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   update   s    c         C   s8   x$ |  j  j   D] } | j |   q W|  j  j   d S(   sR  remove the Sprite from all Groups
        Sprite.kill(): return None

        The Sprite is removed from all the Groups that contain it. This won't
        change anything about the state of the Sprite. It is possible to continue
        to use the Sprite after this method has been called, including adding it
        to Groups.
        N(   R   t   keysR   t   clear(   R   t   c(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   kill   s    	c         C   s   |  j  j   S(   s   list of Groups that contain this Sprite
        Sprite.groups(): return group_list

        Return a list of all the Groups that contain this Sprite.
        (   R   R   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR      s    c         C   s   t  |  j  d k S(   s   does the sprite belong to any groups
        Sprite.alive(): return bool

        Returns True when the Sprite belongs to one or more Groups.
        i    (   t   lenR   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   alive   s    c         C   s   d |  j  j t |  j  f S(   Ns   <%s sprite(in %d groups)>(   t	   __class__t   __name__R   R   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   __repr__   s    (   R   t
   __module__t   __doc__R   R   R   R   R   R   R   R   R   R   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   c   s   									t   DirtySpritec           B   sQ   e  Z d  Z d   Z d   Z d   Z e d   d   d d d Z d	   Z RS(
   s  a more featureful subclass of Sprite with more attributes
    pygame.sprite.DirtySprite(*groups): return DirtySprite 

    Extra DirtySprite attributes with their default values:

    dirty = 1
        if set to 1, it is repainted and then set to 0 again 
        if set to 2 then it is always dirty ( repainted each frame, 
        flag is not reset)
        0 means that it is not dirty and therefor not repainted again

    blendmode = 0
        its the special_flags argument of blit, blendmodes

    source_rect = None
        source rect to use, remember that it is relative to 
        topleft (0,0) of self.image

    visible = 1
        normally 1, if set to 0 it will not be repainted 
        (you must set it dirty too to be erased from screen)

    layer = 0
        (READONLY value, it is read when adding it to the 
        LayeredUpdates, for details see doc of LayeredUpdates)
    c         G   sA   d |  _  d |  _ d |  _ d |  _ d  |  _ t j |  |  d  S(   Ni   i    (   t   dirtyt	   blendmodet   _visiblet   _layert   Nonet   source_rectR   R   (   R   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR      s    					c         C   s(   | |  _  |  j d k  r$ d |  _ n  d S(   s9   set the visible value (0 or 1) and makes the sprite dirtyi   i   N(   R!   R   (   R   t   val(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   _set_visible   s    	c         C   s   |  j  S(   s(   returns the visible value of that sprite(   R!   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   _get_visible   s    c         C   s
   |  j    S(   N(   R'   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   <lambda>   s    c         C   s   |  j  |  S(   N(   R&   (   R   t   value(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR(      s    t   docsG   you can make this sprite disappear without removing it from the group,
s(   values 0 for invisible and 1 for visiblec         C   s    d |  j  j t |  j    f S(   Ns   <%s DirtySprite(in %d groups)>(   R   R   R   R   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR      s    (	   R   R   R   R   R&   R'   t   propertyt   visibleR   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR      s   	
				
t   AbstractGroupc           B   s   e  Z d  Z e Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sQ  A base for containers for sprites. It does everything
       needed to behave as a normal group. You can easily inherit
       a new group class from this, or the other groups below,
       if you want to add more features.

       Any AbstractGroup-derived sprite groups act like sequences,
       and support iteration, len, and so on.c         C   s   i  |  _  g  |  _ d  S(   N(   t
   spritedictt   lostsprites(   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    	c         C   s   t  |  j j    S(   s3  sprites()
           get a list of sprites in the group

           Returns an object that can be looped over with a 'for' loop.
           (For now it is always a list, but newer version of Python
           could return different iterators.) You can also iterate directly
           over the sprite group.(   t   listR.   R   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   sprites  s    c         C   s   d |  j  | <d  S(   Ni    (   R.   (   R   t   sprite(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    c         C   s:   |  j  | } | d k	 r, |  j j |  n  |  j  | =d  S(   Ni    (   R.   R/   t   append(   R   R2   t   r(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    c         C   s   | |  j  k S(   N(   R.   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   has_internal"  s    c         C   s   |  j  |  j    S(   s   copy()
           copy a group with all the same sprites

           Returns a copy of the group that is the same class
           type, and has the same sprites in it.(   R   R1   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   copy%  s    c         C   s   t  |  j    S(   N(   t   iterR1   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   __iter__-  s    c         C   s   |  j  |  S(   N(   R   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR
   0  s    c         G   s  x	| D]} t  | t  rK |  j |  s|  j |  | j |   qq y" x | D] } |  j |  qU WWq t t f k
 rt | d  r xo | j   D]2 } |  j |  s |  j |  | j |   q q Wq|  j |  s|  j |  | j |   qq Xq Wd S(   s{   add(sprite, list, or group, ...)
           add sprite to group

           Add a sprite or sequence of sprites to a group.R	   N(	   t
   isinstanceR   R5   R   R   t	   TypeErrort   AttributeErrorR   R1   (   R   R1   R2   t   spr(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   3  s"    c         G   s  x	| D]} t  | t  rK |  j |  r|  j |  | j |   qq y" x | D] } |  j |  qU WWq t t f k
 rt | d  r xo | j   D]2 } |  j |  r |  j |  | j |   q q Wq|  j |  r|  j |  | j |   qq Xq Wd S(   s   remove(sprite, list, or group, ...)
           remove sprite from group

           Remove a sprite or sequence of sprites from a group.R	   N(	   R9   R   R5   R   R   R:   R;   R   R1   (   R   R1   R2   R<   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   S  s"    	 c         G   s   x | D] } t  | t  r) |  j |  Sy, x! | D] } |  j |  s3 t Sq3 Wt SWq t t f k
 r t | d  r x' | j	   D] } |  j |  s t Sq Wt S|  j |  Sq Xq Wd S(   s   has(sprite or group, ...)
           ask if group has a sprite or sprites

           Returns true if the given sprite or sprites are
           contained in the group. You can also use 'sprite in group'
           or 'subgroup in group'.R	   N(
   R9   R   R5   R   t   Falset   TrueR:   R;   R   R1   (   R   R1   R2   R<   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   n  s    	c         G   s(   x! |  j    D] } | j |   q Wd S(   s   update(*args)
           call update for all member sprites

           calls the update method for all sprites in the group.
           Passes all arguments on to the Sprite update function.N(   R1   R   (   R   R   t   s(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s     c         C   sO   |  j    } | j } x* | D]" } | | j | j  |  j | <q Wg  |  _ d S(   st   draw(surface)
           draw all sprites onto the surface

           Draws all the sprites onto the given surface.N(   R1   t   blitt   imaget   rectR.   R/   (   R   t   surfaceR1   t   surface_blitR<   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   draw  s
    	 c         C   s   y | j  Wn t k
 r n\ Xx |  j D] } | | |  q) Wx3 |  j j   D]" } | d k	 rP | | |  qP qP Wd S| j } x! |  j D] } | | | |  q Wx6 |  j j   D]% } | d k	 r | | | |  q q Wd S(   s\  clear(surface, bgd)
           erase the previous position of all sprites

           Clears the area of all drawn sprites. the bgd
           argument should be Surface which is the same
           dimensions as the surface. The bgd can also be
           a function which gets called with the passed
           surface and the area to be cleared.i    N(   t   __call__R;   R/   R.   t   valuesR@   (   R   RC   t   bgdR4   RD   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s     	 	 c         C   s5   x. |  j    D]  } |  j |  | j |   q Wd S(   sY   empty()
           remove all sprites

           Removes all the sprites from the group.N(   R1   R   (   R   R?   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   empty  s    c         C   s   t  |  j    d k S(   Ni    (   R   R1   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   __nonzero__  s    c         C   s   t  |  j    S(   sr   len(group)
           number of sprites in group

           Returns the number of sprites contained in the group.(   R   R1   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   __len__  s    c         C   s   d |  j  j t |   f S(   Ns   <%s(%d sprites)>(   R   R   R   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    (   R   R   R   R>   R	   R   R1   R   R   R5   R6   R8   R
   R   R   R   R   RE   R   RI   RJ   RK   R   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR-      s(   		
							 									t   Groupc           B   s   e  Z d  Z d   Z RS(   s  container class for many Sprites
    pygame.sprite.Group(*sprites): return Group

    A simple container for Sprite objects. This class can be inherited to
    create containers with more specific behaviors. The constructor takes any 
    number of Sprite arguments to add to the Group. The group supports the
    following standard Python operations:

        in      test if a Sprite is contained
        len     the number of Sprites contained
        bool test if any Sprites are contained
        iter    iterate through all the Sprites

    The Sprites in the Group are not ordered, so drawing and iterating the 
    Sprites is in no particular order.
    c         G   s   t  j |   |  j |   d  S(   N(   R-   R   R   (   R   R1   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    (   R   R   R   R   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRL     s   t   RenderUpdatesc           B   s   e  Z d  Z d   Z RS(   s   Group class that tracks dirty updates
    pygame.sprite.RenderUpdates(*sprites): return RenderUpdates

    This class is derived from pygame.sprite.Group(). It has an extended draw()
    method that tracks the changed areas of the screen.
    c   	      C   s   |  j  } | j } |  j } g  |  _ | j } x |  j   D] } | | } | | j | j  } | d k rx | |  n9 | j |  r | | j |   n | |  | |  | | | <q: W| S(   Ni    (	   R.   R@   R/   R3   R1   RA   RB   t   colliderectt   union(	   R   RC   R.   RD   R   t   dirty_appendR?   R4   t   newrect(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRE     s     					


(   R   R   R   RE   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRM     s   t   OrderedUpdatesc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s{  RenderUpdates class that draws Sprites in order of addition
    pygame.sprite.OrderedUpdates(*spites): return OrderedUpdates

    This class derives from pygame.sprite.RenderUpdates().  It maintains 
    the order in which the Sprites were added to the Group for rendering. 
    This makes adding and removing Sprites from the Group a little 
    slower than regular Groups.
    c         G   s   g  |  _  t j |  |  d  S(   N(   t   _spritelistRM   R   (   R   R1   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   
  s    	c         C   s   t  |  j  S(   N(   R0   RS   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR1     s    c         C   s$   t  j |  |  |  j j |  d  S(   N(   RM   R   RS   R3   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    c         C   s$   t  j |  |  |  j j |  d  S(   N(   RM   R   RS   R   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    (   R   R   R   R   R1   R   R   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRR      s
   			t   LayeredUpdatesc           B   s   e  Z d  Z d   Z d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   LayeredUpdates Group handles layers, that draws like OrderedUpdates.
    pygame.sprite.LayeredUpdates(*spites, **kwargs): return LayeredUpdates
    
    This group is fully compatible with pygame.sprite.Sprite.

    New in pygame 1.8.0
    c         O   sH   i  |  _  g  |  _ t j |   | j d d  |  _ |  j | |   d S(   s  
        You can set the default layer through kwargs using 'default_layer'
        and an integer for the layer. The default layer is 0.
        
        If the sprite you add has an attribute layer then that layer will
        be used.
        If the **kwarg contains 'layer' then the sprites passed will be 
        added to that layer (overriding the sprite.layer attribute).
        If neither sprite has attribute layer nor kwarg then the default
        layer is used to add the sprites.
        t   default_layeri    N(   t   _spritelayersRS   R-   R   t   gett   _default_layerR   (   R   R1   t   kwargs(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   #  s
    		c   	      C   sF  t  d d d d  |  j | <| d k rU y | j } WqU t k
 rQ |  j } qU Xn  | |  j | <t | d  r} | | _ n  |  j } |  j } t	 |  } d } | d } | } xM | | k r | | | d } | | | | k r | d } q | d } q Wx. | | k  r1| | | | k r1| d 7} qW| j
 | |  d S(   sn   
        Do not use this method directly. It is used by the group to add a
        sprite internally.
        i    R"   i   i   N(   R    R.   R#   R"   R;   RX   RV   R   RS   R   t   insert(	   R   R2   t   layerR1   t   sprites_layerst   lengt   lowt   hight   mid(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   6  s.    		
#c         O   sR  d } d | k r | d } n  | d k s2 | r6 d Sx| D]} t | t  r |  j |  sJ|  j | |  | j |   qJq= y% x | D] } |  j | |  q WWq= t t f k
 rIt | d  rxu | j	   D]5 } |  j |  s |  j | |  | j |   q q WqJ|  j |  sJ|  j | |  | j |   qJq= Xq= Wd S(   s  add a sprite or sequence of sprites to a group
        LayeredUpdates.add(*sprites, **kwargs): return None

        If the sprite(s) have an attribute layer then that is used 
        for the layer. If kwargs contains 'layer' then the sprite(s) 
        will be added to that argument (overriding the sprite layer 
        attribute). If neither is passed then the sprite(s) will be
        added to the default layer.
        R[   NR	   (
   R#   R9   R   R5   R   R   R:   R;   R   R1   (   R   R1   RY   R[   R2   R<   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   [  s,    
c         C   ss   |  j  j |  |  j j |  j |  t | d  rL |  j j | j  n  |  j j | d  |  j j |  d S(   sd   
        Do not use this method directly. It is used by the group to 
        add a sprite.
        RB   i    N(	   RS   R   R/   R3   R.   R   RB   t   popRV   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    c         C   s   t  |  j  S(   ss   returns a ordered list of sprites (first back, last top).
        LayeredUpdates.sprites(): return sprites
        (   R0   RS   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR1     s    c   	      C   s   |  j  } | j } |  j } g  |  _ | j } x |  j   D] } | | } | | j | j  } | d k rx | |  n9 | j |  r | | j |   n | |  | |  | | | <q: W| S(   s|   draw all sprites in the right order onto the passed surface.
        LayeredUpdates.draw(surface): return Rect_list
        i    (	   R.   R@   R/   R3   R1   RA   RB   RN   RO   (	   R   RC   R.   RD   R   RP   R<   t   recRQ   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRE     s     					


c         C   sY   |  j  } t | d  } | j |  } g  } | j } x | D] } | | |  q= W| S(   s   returns a list with all sprites at that position.
        LayeredUpdates.get_sprites_at(pos): return colliding_sprites

        Bottom sprites first, top last.
        i    (   i    i    (   RS   R    t   collidelistallR3   (   R   t   post   _spritesRB   t   colliding_idxt	   collidingt   colliding_appendt   i(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   get_sprites_at  s    		c         C   s   |  j  | S(   s   returns the sprite at the index idx from the groups sprites
        LayeredUpdates.get_sprite(idx): return sprite

        Raises IndexOutOfBounds if the idx is not within range.
        (   RS   (   R   t   idx(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt
   get_sprite  s    c         C   s    |  j  |  } |  j |  | S(   s   removes all sprites from a layer and returns them as a list
        LayeredUpdates.remove_sprites_of_layer(layer_nr): return sprites
        (   t   get_sprites_from_layerR   (   R   t   layer_nrR1   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   remove_sprites_of_layer  s    c         C   s:   t    } x$ |  j j   D] } | j |  q Wt |  S(   sy   returns a list of layers defined (unique), sorted from botton up.
        LayeredUpdates.layers(): return layers
        (   t   setRV   RG   R   R0   (   R   t   layersR[   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRq     s    	c   	      C   s  |  j  } |  j } | j |  | j |  t |  } d } | d } | } xM | | k r | | | d } | | | | k r | d } qQ | d } qQ Wx. | | k  r | | | | k r | d 7} q W| j | |  t | d  r | | _ n  | | | <d S(   s   changes the layer of the sprite
        LayeredUpdates.change_layer(sprite, new_layer): return None

        sprite must have been added to the renderer. It is not checked.
        i    i   i   R[   N(   RS   RV   R   Ra   R   RZ   R   R[   (	   R   R2   t	   new_layerR1   R\   R]   R^   R_   R`   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   change_layer  s&    		
#c         C   s   |  j  j | |  j  S(   s   
        Returns the layer that sprite is currently in. If the sprite is not 
        found then it will return the default layer.
        (   RV   RW   RX   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   get_layer_of_sprite  s    c         C   s   |  j  |  j d S(   sS   returns the top layer
        LayeredUpdates.get_top_layer(): return layer
        i(   RV   RS   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   get_top_layer  s    c         C   s   |  j  |  j d S(   sY   returns the bottom layer
        LayeredUpdates.get_bottom_layer(): return layer
        i    (   RV   RS   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   get_bottom_layer	  s    c         C   s   |  j  | |  j    d S(   s   brings the sprite to front layer
        LayeredUpdates.move_to_front(sprite): return None

        Brings the sprite to front, changing sprite layer to topmost layer
        (added at the end of that layer).
        N(   Rs   Ru   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   move_to_front  s    c         C   s   |  j  | |  j   d  d S(   s   moves the sprite to the bottom layer
        LayeredUpdates.move_to_back(sprite): return None

        Moves the sprite to the bottom layer, moving it behind
        all other layers and adding one additional layer.
        i   N(   Rs   Rv   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   move_to_back  s    c         C   s   |  j  d S(   sZ   returns the topmost sprite
        LayeredUpdates.get_top_sprite(): return Sprite
        i(   RS   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   get_top_sprite!  s    c         C   sa   g  } | j  } |  j } xB |  j D]7 } | | | k rE | |  q" | | | k r" Pq" q" W| S(   s%  returns all sprites from a layer, ordered by how they where added
        LayeredUpdates.get_sprites_from_layer(layer): return sprites

        Returns all sprites from a layer, ordered by how they where added.
        It uses linear search and the sprites are not removed from layer.
        (   R3   RV   RS   (   R   R[   R1   t   sprites_appendt   sprite_layersR<   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRm   '  s    		c         C   sP   |  j  |  } x' |  j |  D] } |  j | |  q W|  j | d | d S(   s   switches the sprites from layer1 to layer2
        LayeredUpdates.switch_layer(layer1_nr, layer2_nr): return None

        The layers number must exist, it is not checked.
        R[   N(   Ro   Rm   Rs   R   (   R   t	   layer1_nrt	   layer2_nrt   sprites1R<   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   switch_layer9  s    N(   R   R   R   R   R#   R   R   R   R1   RE   Rj   Rl   Ro   Rq   Rs   Rt   Ru   Rv   Rw   Rx   Ry   Rm   R   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRT     s(   	%	*						
			"									t   LayeredDirtyc           B   sh   e  Z d  Z d   Z d
 d  Z d
 d  Z d   Z d   Z d
 d  Z	 d   Z
 d   Z d	   Z RS(   s  LayeredDirty Group is for DirtySprites.  Subclasses LayeredUpdates.
    pygame.sprite.LayeredDirty(*spites, **kwargs): return LayeredDirty
        
    This group requires pygame.sprite.DirtySprite or any sprite that 
    has the following attributes: 
        image, rect, dirty, visible, blendmode (see doc of DirtySprite).

    It uses the dirty flag technique and is therefore faster than the 
    pygame.sprite.RenderUpdates if you have many static sprites.  It 
    also switches automatically between dirty rect update and full 
    screen drawing, so you do no have to worry what would be faster.

    Same as for the pygame.sprite.Group.
    You can specify some additional attributes through kwargs:
        _use_update: True/False   default is False
        _default_layer: default layer where sprites without a layer are added.
        _time_threshold: treshold time for switching between dirty rect mode 
            and fullscreen mode, defaults to 1000./80  == 1000./fps

    New in pygame 1.8.0
    c         O   s   t  j |  | |  d |  _ t |  _ d d |  _ d |  _ xK | j   D]= \ } } | d k rH t	 |  |  r t
 |  | |  q qH qH Wd S(   s  Same as for the pygame.sprite.Group.
        pygame.sprite.LayeredDirty(*spites, **kwargs): return LayeredDirty

        You can specify some additional attributes through kwargs:
        _use_update: True/False   default is False
        _default_layer: the default layer where the sprites without a layer are
                        added.
        _time_threshold: treshold time for switching between dirty rect mode and
                        fullscreen mode, defaults to 1000./80  == 1000./fps
        g     @@g      T@t   _use_updatet   _time_thresholdRX   N(   s   _use_updates   _time_thresholds   _default_layer(   RT   R   R#   t   _clipR=   R   R   t   _bgdt   itemsR   t   setattr(   R   R1   RY   t   keyR%   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   \  s    			c         C   s   t  | d  s t    n  t  | d  s6 t    n  t  | d  sQ t    n  t | t  sl t    n  | j d k r d | _ n  t j |  | |  d S(   se   Do not use this method directly. It is used by the group to add a
        sprite internally.
        R   R,   R    i    i   N(   R   R;   R9   R   R:   R   RT   R   (   R   R2   R[   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   u  s    c      
   C   s  | j    } |  j } | d k r* | } n  | } |  j } |  j } |  j } | j }	 d }
 | j } t } | d k	 r | |  _	 n  |  j	 } | j
 |  t   } |  j rDx0| D](} d | j k  r | j r | | j j | j j  } n | | j  } | j } | j } | |  } x1 d | k  rL| | |  | | =| |  } qW|	 | j |   | | |  } | j } | j } | |  } x1 d | k  r| | |  | | =| |  } qW|	 | j |   q q W| d k	 rx! | D] } | | | |  qWn  x&| D]} d | j k r| j r1| j } | j d k	 rgt | j j | j j  } n  | j } xo | j |  D][ } | | |  } | | j | | d | d | d | d | d | d f | j  qWq1q| j r| | j | j | j | j  | | <n  | j d k rd | _ qqWt |  }
 nm | d k	 r`| | d  n  x? | D]7 } | j rg| | j | j | j | j  | | <qgqgW| |  g }
 t   } | | |  j k rt |  _ n	 t |  _ g  | (| j
 |  |
 S(   s   draw all sprites in the right order onto the passed surface.
        LayeredDirty.draw(surface, bgd=None): return Rect_list

        You can pass the background too. If a background is already set, 
        then the bgd argument has no effect.
        i    ii   i   i   N(   i    i    (   t   get_clipR   R#   RS   R.   R/   R3   R@   R    R   t   set_clipR   R   R   R$   RB   t   topleftt   sizet   collidelistt   union_ipt   clipR!   Rc   RA   R    R0   R   R=   R>   (   R   RC   RH   t
   _orig_clipR   t   _surfRe   t	   _old_rectt   _updatet   _update_appendt   _rett
   _surf_blitt   _rectR   t
   start_timeR<   t   _union_rectt   _union_rect_collidelistt   _union_rect_union_ipRi   Rb   t	   _spr_rectt   _spr_rect_clipRk   R   t   end_time(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRE     s    																				,		c         C   s   | |  _  d S(   sN   used to set background
        Group.clear(surface, bgd): return None
        N(   R   (   R   RC   RH   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR      s    c         C   s    |  j  j | j |  j   d S(   s   repaints the given area
        LayeredDirty.repaint_rect(screen_rect): return None

        screen_rect is in screencoordinates.
        N(   R/   R3   R   R   (   R   t   screen_rect(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   repaint_rect  s    c         C   s=   | d k r' t j j   j   |  _ n	 | |  _ t |  _ d S(   s    clip the area where to draw. Just pass None (default) to reset the clip
        LayeredDirty.set_clip(screen_rect=None): return None
        N(   R#   t   pygamet   displayt   get_surfacet   get_rectR   R=   R   (   R   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    	c         C   s   |  j  S(   s}   clip the area where to draw. Just pass None (default) to reset the clip
        LayeredDirty.get_clip(): return Rect
        (   R   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    c         C   s2   t  j |  | |  | j d k r. d | _ n  d S(   s   changes the layer of the sprite
        change_layer(sprite, new_layer): return None

        sprite must have been added to the renderer. It is not checked.
        i    i   N(   RT   Rs   R   (   R   R2   Rr   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRs     s    c         C   s   | |  _  d S(   s   sets the treshold in milliseconds
        set_timing_treshold(time_ms): return None

        Default is 1000./80 where 80 is the fps I want to switch to full screen mode.
        N(   R   (   R   t   time_ms(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   set_timing_treshold)  s    N(   R   R   R   R   R#   R   RE   R   R   R   R   Rs   R   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   E  s   	w		
		t   GroupSinglec           B   s   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 e e	 e
 d d  Z d	   Z d
   Z d   Z RS(   s  A group container that holds a single most recent item.
       This class works just like a regular group, but it only
       keeps a single sprite in the group. Whatever sprite has
       been added to the group last, will be the only sprite in
       the group.

       You can access its one sprite as the .sprite attribute.
       Assigning to this attribute will properly remove the old
       sprite and then add the new one.c         C   s6   t  j |   d  |  _ | d  k	 r2 |  j |  n  d  S(   N(   R-   R   R#   t   _GroupSingle__spriteR   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   B  s    	 c         C   s   t  |  j  S(   N(   R   R   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR6   G  s    c         C   s!   |  j  d  k	 r |  j  g Sg  Sd  S(   N(   R   R#   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR1   J  s     
c         C   s/   |  j  d  k	 r" |  j  j |   n  | |  _  d  S(   N(   R   R#   R   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   N  s    c         C   s   |  j  d  k	 S(   N(   R   R#   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRJ   S  s    c         C   s   |  j  S(   N(   R   (   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   _get_spriteU  s    c         C   s   |  j  |  | j  |   | S(   N(   R   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   _set_spriteX  s    s"   The sprite contained in this groupc         C   s   | |  j  k r d  |  _  n  d  S(   N(   R   R#   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   `  s     c         C   s   |  j  | k S(   N(   R   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR5   c  s    c         C   s   |  j  | k S(   N(   R   (   R   R2   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR
   g  s    N(   R   R   R   R#   R   R6   R1   R   RJ   R   R   R+   R2   R   R5   R
   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   7  s   										c         C   s   |  j  j | j   S(   s  collision detection between two sprites, using rects.
    pygame.sprite.collide_rect(left, right): return bool

    Tests for collision between two sprites. Uses the
    pygame rect colliderect function to calculate the
    collision. Intended to be passed as a collided
    callback function to the *collide functions.
    Sprites must have a "rect" attributes.

    New in pygame 1.8.0
    (   RB   RN   (   t   leftt   right(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   collide_recto  s    t   collide_rect_ratioc           B   s    e  Z d  Z d   Z d   Z RS(   s  A callable class that checks for collisions between
    two sprites, using a scaled version of the sprites
    rects.

    Is created with a ratio, the instance is then intended
    to be passed as a collided callback function to the
    *collide functions.

    New in pygame 1.8.1
    c         C   s   | |  _  d S(   s   Creates a new collide_rect_ratio callable. ratio is
        expected to be a floating point value used to scale
        the underlying sprite rect before checking for
        collisions.
        N(   t   ratio(   R   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    c         C   s   |  j  } | j } | j } | j } | j | | | | | |  } | j } | j } | j } | j | | | | | |  } | j |  S(   sl  pygame.sprite.collide_rect_ratio(ratio)(left, right): bool
        collision detection between two sprites, using scaled rects.

        Tests for collision between two sprites. Uses the
        pygame rect colliderect function to calculate the
        collision, after scaling the rects by the stored ratio.
        Sprites must have a "rect" attributes.
        (   R   RB   t   widtht   heightt   inflateRN   (   R   R   R   R   t   leftrectR   R   t	   rightrect(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRF     s    
				"			"(   R   R   R   R   RF   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   }  s   
		c   	      C   s   |  j  j | j  j } |  j  j | j  j } | d | d } y |  j d } Wn6 t k
 r |  j  } | j d | j d d } n Xy | j d } Wn6 t k
 r | j  } | j d | j d d } n X| | | k  S(   sw  collision detection between two sprites, using circles.
    pygame.sprite.collide_circle(left, right): return bool

    Tests for collision between two sprites, by testing to
    see if two circles centered on the sprites overlap. If
    the sprites have a "radius" attribute, that is used to
    create the circle, otherwise a circle is created that
    is big enough to completely enclose the sprites rect as
    given by the "rect" attribute. Intended to be passed as
    a collided callback function to the *collide functions.
    Sprites must have a "rect" and an optional "radius"
    attribute.

    New in pygame 1.8.0
    i   i   (   RB   t   centerxt   centeryt   radiusR;   R   R   (	   R   R   t	   xdistancet	   ydistancet   distancesquaredt   leftradiussquaredR   t   rightradiussquaredR   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   collide_circle  s    	 	 t   collide_circle_ratioc           B   s    e  Z d  Z d   Z d   Z RS(   s  A callable class that checks for collisions between
    two sprites, using a scaled version of the sprites radius.

    Is created with a ratio, the instance is then intended
    to be passed as a collided callback function to the
    *collide functions.

    New in pygame 1.8.1
    c         C   s   | |  _  | d d |  _ d S(   s   Creates a new collide_circle_ratio callable. ratio is
        expected to be a floating point value used to scale
        the underlying sprite radius before checking for
        collisions.
        i   g      @N(   R   t	   halfratio(   R   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s    	c         C   s?  |  j  } | j j | j j } | j j | j j } | d | d } t | d  r | j | d } t | d  r | j | d } q1|  j }	 | j }
 |
 j d |
 j d |	 } nv |  j }	 | j } | j d | j d |	 } t | d  r| j | d } n% | j }
 |
 j d |
 j d |	 } | | | k  S(   s  pygame.sprite.collide_circle_radio(ratio)(left, right): return bool
        collision detection between two sprites, using scaled circles.

        Tests for collision between two sprites, by testing to
        see if two circles centered on the sprites overlap, after
        scaling the circles radius by the stored ratio. If
        the sprites have a "radius" attribute, that is used to
        create the circle, otherwise a circle is created that
        is big enough to completely enclose the sprites rect as
        given by the "rect" attribute. Intended to be passed as
        a collided callback function to the *collide functions.
        Sprites must have a "rect" and an optional "radius"
        attribute.
        i   R   (	   R   RB   R   R   R   R   R   R   R   (   R   R   R   R   R   R   R   R   R   R   R   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyRF     s&    						(   R   R   R   R   RF   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR     s   		c         C   s   | j  d |  j  d } | j  d |  j  d } y |  j } Wn  t k
 r_ t |  j  } n Xy | j } Wn  t k
 r t | j  } n X| j | | | f  S(   s   collision detection between two sprites, using masks.
    pygame.sprite.collide_mask(SpriteLeft, SpriteRight): bool

    Tests for collision between two sprites, by testing if
    thier bitmasks overlap. If the sprites have a "mask"
    attribute, that is used as the mask, otherwise a mask is
    created from the sprite image. Intended to be passed as
    a collided callback function to the *collide functions.
    Sprites must have a "rect" and an optional "mask"
    attribute.

    New in pygame 1.8.0
    i    i   (   RB   t   maskR;   R   RA   t   overlap(   R   R   t   xoffsett   yoffsett   leftmaskt	   rightmask(    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   collide_mask  s    c         C   s  g  } | d k r |  j j } | rg xp | j   D]/ } | | j  r1 | j   | j |  q1 q1 Wqx | D]% } | | j  rn | j |  qn qn Wny | r xp | j   D]/ } | |  |  r | j   | j |  q q Wn0 x- | D]% } | |  |  r | j |  q q W| S(   s)  find Sprites in a Group that intersect another Sprite
    pygame.sprite.spritecollide(sprite, group, dokill, collided = None): return Sprite_list

    Return a list containing all Sprites in a Group that intersect with another
    Sprite. Intersection is determined by comparing the Sprite.rect attribute
    of each Sprite.

    The dokill argument is a bool. If set to True, all Sprites that collide
    will be removed from the Group.

    The collided argument is a callback function used to calculate if two sprites 
    are colliding. it should take two sprites as values, and return a bool 
    value indicating if they are colliding. If collided is not passed, all sprites 
    must have a "rect" value, which is a rectangle of the sprite area, which will 
    be used to calculate the collision.
    N(   R#   RB   RN   R1   R   R3   (   R2   R   t   dokillt   collidedt   crashedt   spritecollideR?   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyR   %  s(    

c   	      C   s   i  } t  } | r^ x |  j   D]8 } | | | | |  } | r | | | <| j   q q Wn9 x6 |  D]. } | | | | |  } | re | | | <qe qe W| S(   s  pygame.sprite.groupcollide(groupa, groupb, dokilla, dokillb) -> dict
       collision detection between group and group

       given two groups, this will find the intersections
       between all sprites in each group. it returns a
       dictionary of all sprites in the first group that
       collide. the value for each item in the dictionary
       is a list of the sprites in the second group it
       collides with. the two dokill arguments control if
       the sprites from either group will be automatically
       removed from all groups.
       collided is a callback function used to calculate if
       two sprites are colliding. it should take two sprites
       as values, and return a bool value indicating if
       they are colliding. if collided is not passed, all
       sprites must have a "rect" value, which is a
       rectangle of the sprite area, which will be used
       to calculate the collision.(   R   R1   R   (	   t   groupat   groupbt   dokillat   dokillbR   R   t   SCR?   R   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   groupcollideO  s    
c         C   sg   | d k r? |  j j } xH | D] } | | j  r | Sq Wn$ x! | D] } | |  |  rF | SqF Wd S(   s  pygame.sprite.spritecollideany(sprite, group) -> sprite
       finds any sprites that collide

       given a sprite and a group of sprites, this will
       return return any single sprite that collides with
       with the given sprite. If there are no collisions
       this returns None.

       if you don't need all the features of the
       spritecollide function, this function will be a
       bit quicker.

       collided is a callback function used to calculate if
       two sprites are colliding. it should take two sprites
       as values, and return a bool value indicating if
       they are colliding. if collided is not passed, all
       sprites must have a "rect" value, which is a
       rectangle of the sprite area, which will be used
       to calculate the collision.N(   R#   RB   RN   (   R2   R   R   R   R?   (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   spritecollideanyq  s    (   R   R   R    t   pygame.timeR   t   pygame.maskR   t   objectR   R   R-   RL   t   RenderPlaint   RenderClearRM   RR   RT   R   R   R   R   R   R   R   R#   R   R   R   (    (    (    s:   c:\mingw\msys\1.0\newbuild\install\python\pygame\sprite.pyt   <module>B   s6   c9 ,8	-	 A	*"