
ZTc           @   s  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z y d  d l	 Z	 e
 Z Wn$ e k
 r e j j   e Z n Xd  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z d   Z d	 e f d
     YZ d S(   i(   t   divisionN(   t   chain(   t
   _LayerTree(   t   defaultdict(   t   ref(   t   WeakMethodBoundc         C   si   xb | D]Z } |  | k r t  St | t  rB |  | j   k rB t  St | t  r |  | k r t  Sq Wt S(   N(   t   Truet
   isinstancet   dictt   valuest   tuplet   False(   t   objt   collectt   item(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt
   _has_value   s    !t   Scenec           B   sN  e  Z d  Z d4 d4 d4 d  Z d   Z d   Z d   Z d4 d  Z d   Z	 d   Z
 d   Z d4 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 d   Z e e  Z  e e  Z! e e  Z" e e  Z# e e  Z$ e e  Z% d   Z& d   Z' e e' e&  Z( d   Z) d   Z* d    Z+ d!   Z, d"   Z- d#   Z. d$   Z/ d%   Z0 d&   Z1 d'   Z2 d(   Z3 d)   Z4 d*   Z5 d+   Z6 d,   Z7 e e7 e6  Z8 d-   Z9 d.   Z: d/   Z; d0   Z< d1   Z= d2   Z> d3   Z? RS(5   s  
    Creates a new Scene. When a scene is not active, no events will be processed
    for it. Scenes are the basic units that are executed by spyral for your game,
    and should be subclassed and filled in with code which is relevant to your
    game. The :class:`Director <spyral.director>`, is a manager for Scenes,
    which maintains a stacks and actually executes the code.


    :param size: The `size` of the scene internally (or "virtually"). This is
                 the coordinate space that you place Sprites in, but it does
                 not have to match up 1:1 to the window (which could be scaled).
    :type size: width, height
    :param int max_ups: Maximum updates to process per second. By default,
                        `max_ups` is pulled from the director.
    :param int max_fps: Maximum frames to draw per second. By default,
                        `max_fps` is pulled from the director.
    c         C   s  t  j  } t j d | d | p' t j j d | p9 t j j  |  _ t |  j _ t	 d    |  _
 t   |  _ t j j   |  _ t |  _ g  |  _ g  |  _ i  |  _ i  |  _ g  |  _ t	 d    |  _ i  |  _ t j |  j d <d  |  _ t j d d  |  _ t j j    |  _! | d  k	 r+|  j" |  n  |  j! j#   } t j$ j% |  |  _& |  j& j' d  d	 |  _( |  j! j) |  j& d  g  |  _* g  |  _+ g  |  _, g  |  _- g  |  _. i  |  _/ i  |  _0 i  |  _1 |  j! j2   |  _3 g  |  _4 g  |  _5 t6 |   |  _7 t   |  _8 t j j9 d
 |  j: d |  t j j9 d |  j; d |  t< ret j j9 d |  j= d d |  n  t j j9 d |  j> d |  t? |   |  _@ g  |  _A d  S(   Nt   time_sourcet   max_fpst   max_upsc           S   s   g  S(   N(    (    (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   <lambda>:   s    c           S   s   i  S(   N(    (    (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyR   D   s    t   _get_spyral_pathg      ?i   i    s   director.scene.entert   scenes   director.updatet   deltas   spyral.internal.view.changed(   i   i   i   (   i    i    (   s   delta(B   t   timet   spyralt	   GameClockt   directort   _max_fpst   _max_upst   clockR   t   use_waitR   t	   _handlerst   sett   _namespacest   eventt   LiveEventHandlert   _event_sourceR   t   _handling_eventst   _eventst   _pendingt
   _greenletst   _style_symbolst   _style_classest   _style_propertiest   _style_functionsR   t   Nonet   _sizet   Vec2Dt   _scalet   pygamet   displayt   get_surfacet   _surfacet	   _set_sizet   get_sizet   imaget   _new_spyral_surfacet   _backgroundt   fillt   _background_versiont   blitt   _blitst   _dirty_rectst   _clear_this_framet   _clear_next_framet   _soft_cleart   _static_blitst   _invalidating_viewst   _collision_boxest   get_rectt   _rectt   _layerst   _child_viewsR   t   _layer_treet   _spritest   registert   redrawt   _handle_eventst   _GREENLETS_AVAILABLEt   _run_actorst   _invalidate_viewst   _wreft   _scenet   _views(   t   selft   sizeR   R   R   t   display_size(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   __init__2   sh    																					c         C   s   | |  j  | <d S(   s  
        Internal method to add a new :class:`Actor <spyral.Actor>` to this
        scene.

        :param actor: The name of the actor object.
        :type actor: :class:`Actor <spyral.Actor>`
        :param greenlet greenlet: The greenlet context for this actor.
        N(   R)   (   RU   t   actort   greenlet(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _register_actorq   s    	c         C   s[   xT |  j  j   D]C \ } } | j |  \ } } x | rR | j |  \ } } q4 Wq Wt S(   ss   
        Helper method for running the actors.

        :param float delta: The amount of time progressed.
        (   R)   t	   iteritemst   switchR   (   RU   R   t   _RY   RZ   t   rerun(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _run_actors_greenlet|   s
    	c         C   sg   t  j  |  j  } xN t rb | j | t  } | t k r? q n  | t k rO Pn  | j | t  q Wd S(   s   
        Main loop for running actors, switching between their different
        contexts.

        :param float delta: The amount of time progressed.
        N(   RZ   R`   R   R]   R   (   RU   R   t   gt   d(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyRP      s    	c         C   s<   |  j  r" |  j j | | f  n |  j j | | f  d S(   s   
        Internal method to add a new `event` to be handled by this scene.

        :param str type: The name of the event to queue
        :param event: Metadata about this event.
        :type event: :class:`Event <spyral.Event>`
        N(   R&   R(   t   appendR'   (   RU   t   typeR#   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _queue_event   s    	c         C   s   | j  d  r | d  } n  |  j j |  x1 | D]) } |  j | j | | | | | f  q3 W|  j | j d t j d   d S(   s   
        Convenience method for registering a new event; other variations
        exist to keep the signature convenient and easy.
        s   .*it   keyi   N(   t   endswithR"   t   addR    Rc   t   sortt   operatort
   itemgetter(   RU   t	   namespacet   handlerst   argst   kwargst   priorityt   dynamict   handler(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _reg_internal   s    c         C   s)   g  |  j  D] } | j |  r
 | ^ q
 S(   sv   
        Internal method for returning all the registered namespaces that are in
        the given namespace.
        (   R"   t
   startswith(   RU   Rl   t   n(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _get_namespaces   s    c            ss  d       f d  } | t  k ru | }	 |  } x< |	 j d  D]( }
 t | |
 d  } | d k rF d SqF Wn  | t j k r | d k r | d k r g  } i  } n| d k r| d k ry | j } Wn t k
 r } | } n Xy t j	 |  } Wn) t
 k
 r*} t
 d t |    n X| j } | j pCt   } t |  d k rxd | d k rx| j d  n  t |  t |  } | d k r g | t |   } n  g  t | |  D] \ } } | | |  ^ q} i  } ne | d k r.g  } t g  | D] } | | |  f ^ q
 } n% g  | D] } | |  ^ q5} i  } | d k	 ro| | |   n  d S(   sG   
        Internal method to dispatch events to their handlers.
        t   __spyral_itertools_fillvalue__c            s\   |  d k r   St    |   r, t   |   S|  k r< | St d |  t   f   d  S(   NR#   s<   Handler expects an argument named %s, %s does not have that.(   t   hasattrt   getattrt	   TypeErrort   str(   t   argt   default(   R#   t   fillvalRd   (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _get_arg_val   s    t   .NsP   Unfortunate Python Problem! %s isn't supported by Python's inspect module! Oops.i    RU   (   R   t   splitRy   R.   t   syst   exitt   funct   AttributeErrort   inspectt
   getargspect	   ExceptionR{   Rn   t   defaultsR
   t   lent   popt   listt   zipR   (   RU   R#   Rd   Rr   Rn   Ro   Rp   Rq   R   t   ht   piecet   functt   et	   h_argspect   h_argst
   h_defaultsRb   R|   R}   (    (   R#   R~   Rd   sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _send_event_to_handler   sN    '	
	".	.c            sV   t  j   f d     j |  D  } x' | D] }   j | | |  r/ Pq/ q/ Wd S(   sZ   
        For a given event, send the event information to all registered handlers
        c         3   s   |  ] }   j  | Vq d  S(   N(   R    (   t   .0Rl   (   RU   (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pys	   <genexpr>   s   N(   R   t   from_iterableRv   R   (   RU   Rd   R#   Rm   t   handler_info(    (   RU   sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _handle_event   s
    c         C   sz   t  |  _ t  } xd | s- t |  j  d k ru t } x' |  j D] \ } } |  j | |  q= W|  j |  _ g  |  _ q Wd S(   s=   
        Run through all the events and handle them.
        i    N(   R   R&   R   R(   R   R'   R   (   RU   t   doRd   R#   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyRN     s    	c         C   s   x |  j  j   D]p \ } } g  | D]6 } t | d t  sS | d j   | k	 r# | ^ q# |  j  | <|  j  | s |  j  | =q q Wd  S(   Ni    (   R    t   itemsR   R   t   weak_object_ref(   RU   t   spritet   nameRm   R   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _unregister_sprite_events  s    )c         C   s   | j  d  r | d  } n  g  |  j | D]r } t | d t  rT | | d k s t | d t  r* | d j | j k	 s | d j   | j k	 r* | ^ q* |  j | <|  j | s |  j | =n  d S(   sL  
        Unregisters a registered handler for that namespace. Dynamic handler
        strings are supported as well. For more information, see
        `Event Namespaces`_.

        :param str event_namespace: An event namespace
        :param handler: The handler to unregister.
        :type handler: a function or string.
        s   .*ii    N(   Rg   R    R   R   R   t   im_funcR   t   im_self(   RU   t   event_namespaceRr   R   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _unregister  s    
$,c         C   sf   | j  d  r | d  } n  g  |  j D] } | j |  r& | ^ q& } x | D] } |  j | =qN Wd S(   s   
        Clears all handlers from namespaces that are at least as specific as the
        provided `namespace`. For more information, see `Event Namespaces`_.

        :param str namespace: The complete namespace.
        s   .*iN(   Rg   R"   Rt   R    (   RU   Rl   Ru   t   ns(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _clear_namespace+  s
    +c         C   s   |  j  j   d S(   s   
        Completely clear all registered events for this scene. This is a very
        dangerous function, and should almost never be used.
        N(   R    t   clear(   RU   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _clear_all_events8  s    c         C   s   |  j  S(   s  
        The event source can be used to control event playback. Although
        normally events are given through the operating system, you can enforce
        events being played from a file; there is also a mechanism for recording
        events to a file.
        (   R%   (   RU   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _get_event_source?  s    c         C   s   | |  _  d  S(   N(   R%   (   RU   t   source(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _set_event_sourceH  s    c         C   s   d | k r+ | j  d  } |  j |  n  d | k r | j  d  } t | t t f  r t j d |  j  } | j |  n t j |  } |  j	 |  n  d | k r | j  d  } |  j
 |  n  t |  d k r t j j |  | j    n  d S(   s   
        Applies the *properties* to this scene. This is called when a style
        is applied.

        :param properties: a mapping of property names (strings) to values.
        :type properties: dict
        RV   t
   backgroundt   layersi    N(   R   R6   R   R
   R   R   t   ImageRV   R;   t   _set_backgroundt   _set_layersR   t
   exceptionst   unused_style_warningt   iterkeys(   RU   t
   propertiesRV   R   t   bgR   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   __stylize__M  s    c         C   s3   t  j j t | d  j   |   |  j |   d S(   s-  
        Loads the style file in *path* and applies it to this Scene and any
        Sprites and Views that it contains. Most properties are stylable.

        :param path: The location of the style file to load. Should have the
                     extension ".spys".
        :type path: str
        t   rN(   R   t   _stylet   parset   opent   readt   _apply_style(   RU   t   path(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt
   load_stylef  s    	"c         C   s   t  | d  s% t j d |   n  i  } xP t | j j d   D]8 } | j } | |  j k rf qB n  | j |  j |  qB Wt  | d  r t	 | d  } | |  j k r | j |  j |  q n  | i  k r | j
 |  n  d S(   sq   
        Applies any loaded styles from this scene to the object.

        :param object obj: Any object
        R   s'   %r is not an objectwhich can be styled.it	   __style__N(   Rx   R   t   NotStylableErrort   reversedt	   __class__t   __mro__t   __name__R,   t   updateRy   R   (   RU   R   R   t   clsR   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyR   r  s    		c         C   s   | |  j  | <d S(   s  
        Adds a new function that will then be available to be used in a
        stylesheet file.

        Example::

            import random
            class MyScene(spyral.Scene):
                def __init__(self):
                    ...
                    self.load_style("my_style.spys")
                    self.add_style_function("randint", random.randint)
                    # inside of style file you can now use the randint function!
                    ...


        :param name: The name the function will go by in the style file.
        :type name: string
        :param function: The actual function to add to the style file.
        :type function: function
        N(   R-   (   RU   R   t   function(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   add_style_function  s    c         C   s(   |  j  d k r! t j d   n  |  j  S(   s?  
        Read-only property that returns a :class:`Vec2D <spyral.Vec2D>` of the
        width and height of the Scene's size.  This is the coordinate space that
        you place Sprites in, but it does not have to match up 1:1 to the window
        (which could be scaled). This property can only be set once.
        sX   You should specify a size in the constructor or in a style file before other operations.N(   R/   R.   R   t   SceneHasNoSizeException(   RU   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt	   _get_size  s    c         C   sC   |  j  j   } | |  _ | d | d | d | d f |  _ d  S(   Ni    i   (   R5   R7   R/   R1   (   RU   RV   t   rsize(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyR6     s    	c         C   s   |  j    d S(   s<   
        The width of this scene. Read-only number.
        i    (   R   (   RU   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt
   _get_width  s    c         C   s   |  j    d S(   s=   
        The height of this scene. Read-only number.
        i   (   R   (   RU   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _get_height  s    c         C   s   t  j d |  j  S(   sx   
        Returns a :class:`Rect <spyral.Rect>` representing the position (0, 0)
        and size of this Scene.
        i    (   i    i    (   R   t   RectRV   (   RU   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt	   _get_rect  s    c         C   s
   |  j    S(   s0   
        Returns this scene. Read-only.
        (   RS   (   RU   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt
   _get_scene  s    c         C   s
   |  j    S(   s0   
        Returns this scene. Read-only.
        (   RS   (   RU   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _get_parent  s    c         C   s   | |  _  | j |  _ | j } t j   } | j   |  j k rQ t j d   n  |  j	 j   } t
 j j | |  |  _ |  j j |  j j    d  S(   Ns,   Background size must match the scene's size.(   t   _background_imaget   _versionR<   t   _surfR   t   _get_executing_sceneR7   RV   t   BackgroundSizeErrorR5   R2   t	   transformt   smoothscaleR:   R@   Rc   RF   (   RU   R8   t   surfaceR   RV   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyR     s    		c         C   s   |  j  S(   s  
        The background of this scene. The given :class:`Image <spyral.Image>`
        must be the same size as the Scene. A background will be handled
        intelligently by Spyral; it knows to only redraw portions of it rather
        than the whole thing, unlike a Sprite.
        (   R   (   RU   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _get_background  s    c         C   sr   |  j  j |  | j   } xO | |  k rm | |  j k rM t   |  j | <n  |  j | j |  | j } q Wd S(   sA   
        Internal method to add this sprite to the scene
        N(   RK   Rh   t   _parentRD   R!   t   parent(   RU   R   t   parent_view(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _register_sprite  s    c         C   s}   | |  j  k r" |  j  j |  n  | |  j k r> |  j | =n  x+ |  j j   D] } |  j | j |  qN W|  j |  d S(   sF   
        Internal method to remove this sprite from the scene
        N(   RK   t   removeRE   RD   t   keyst   discardR   (   RU   R   t   view(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _unregister_sprite  s    c         C   sL   | |  j  k r |  j  | =n  | |  j k r8 |  j | =n  |  j j |  d S(   sK   
        Remove all references to the view from within this Scene.
        N(   RD   RE   RJ   t   remove_view(   RU   R   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt
   _kill_view  s
    c         C   s.   | j  |  j  | j   |  j j |  d S(   s   
        Apply any scaling associated with the Scene to the Blit, then finalize
        it. Note that Scene's don't apply cropping.
        N(   t   apply_scaleR1   t   finalizeR>   Rc   (   RU   R=   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _blit  s    
c         C   s>   | j  |  j  | j   | |  j | <|  j j | j  d S(   s   
        Identifies that this sprite will be statically blit from now, and
        applies scaling and finalization to the blit.
        N(   R   R1   R   RC   R@   Rc   t   rect(   RU   Rf   R=   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _static_blit!  s    
c         C   s8   | |  j  k r4 x" |  j  | D] } | j   q Wn  d S(   sO   
        Expire any sprites that belong to the view being invalidated.
        N(   RD   t   _expire_static(   RU   R   R   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyRQ   +  s    c         C   s7   y) |  j  j |  } |  j j | j  Wn n Xd S(   s?   
        Removes this sprite from the static blit list
        N(   RC   R   R@   Rc   R   (   RU   Rf   t   x(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _remove_static_blit3  s
    c         C   sI  |  j  } |  j |  j j k r1 |  j |  j  n  |  j j   } xI |  j |  j D]7 } | j	 |  } |  j j
 |  } | j | |  qQ Wt |  j  } t |  j  } |  j t |  j j    } | j d t j d   |  j } |  j }	 |  j }
 g  |  _ | j   } d } t j j d k  } x| D]} | j } | rL| j n d } | j |  rx| j |  rxq.n  | j rWt } xg | D]_ } | j |  r| j | j | d |  t  } | j! |  |  j j! |  | d 7} PqqW| rq.n  x	|
 D]L } | j |  r| j | j | d |  |
 j! | j  | d 7} PqqWq.| j |  r| j | j | d |  } |	 j! |  q.| j |  r.| j j	 |  } | j" | j# | j$  } | j j
 |  } | j | j | d |  } |	 j! |  q.q.Wt j% j& |  j |  j  |  j |  _ g  |  _ g  |  _ d S(   s   
        Internal method that is called by the
        :class:`Director <spyral.Director>` at the end of every .render() call
        to do the actual drawing.
        Rf   t   layeri    i   i   N(   i   i   ('   R5   R<   R   R   R   R:   RF   R@   RB   t   clipt
   subsurfaceR=   R   RC   R>   R   R	   Ri   Rj   t
   attrgetterRA   R2   t   versiont   vernumR   t   flagst   containst   colliderectt   staticR   R   R.   R   Rc   t   movet   leftt   topR3   R   (   RU   t   screenR   t   it   bt   static_blitst   dynamic_blitst   blitst
   clear_thist
   clear_nextt
   soft_cleart   screen_rectt   drawn_statict   blit_flags_availableR=   t	   blit_rectt
   blit_flagst   skip_soft_clearR   R   t   y(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _draw=  sn    							 	

	c         C   s    |  j  j t j |  j   d S(   s   
        Force the entire visible window to be completely redrawn.

        This is particularly useful for Sugar, which loves to put artifacts over
        our window.
        N(   R@   Rc   R2   R   RG   (   RU   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyRM     s    c         C   s   |  j  j | |  S(   sZ   
        For the given view and layer, calculate its position in the depth order.
        (   RJ   t   get_layer_position(   RU   R   R   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _get_layer_position  s    c         C   s   |  j  j | |  d S(   sF   
        Set the layer that the view is on within layer tree.
        N(   RJ   t   set_view_layer(   RU   R   R   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _set_view_layer  s    c         C   s   |  j  j | |  d S(   s>   
        Set the view's layers within the layer tree.
        N(   RJ   t   set_view_layers(   RU   R   R   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _set_view_layers  s    c         C   s   |  j  j |  d S(   s<   
        Register the given view within this scene.
        N(   RJ   t   add_view(   RU   R   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt	   _add_view  s    c         C   sS   |  j  g  k r. |  j j |  |  | |  _  n! |  j  | k r@ n t j d   d S(   s   
        Potential caveat: If you change layers after blitting, previous blits
        may be wrong for a frame, static ones wrong until they expire
        s0   You can only define the layers for a scene once.N(   RH   RJ   R  R   t   LayersAlreadySetError(   RU   R   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyR     s    c         C   s   |  j  S(   s   
        A list of strings representing the layers that are available for this
        scene. The first layer is at the bottom, and the last is at the top.

        Note that the layers can only be set once.
        (   RH   (   RU   (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _get_layers  s    c         C   s   d S(   s~   
        Add this child to the Scene; since only Views care about their children,
        this function does nothing.
        N(    (   RU   t   entity(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt
   _add_child  s    c         C   s   d S(   s   
        Remove this child to the Scene; since only Views care about their
        children, this function does nothing.
        N(    (   RU   R  (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _remove_child  s    c         C   s   | j    | S(   s   
        Finalize the collision box. Don't apply scaling, because that's only
        for external rendering purposes.
        (   R   (   RU   t   box(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _warp_collision_box  s    
c         C   s   | |  j  | <d S(   sd   
        Registers the given entity (a View or Sprite) with the given
        CollisionBox.
        N(   RE   (   RU   R  R  (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   _set_collision_box  s    c         C   sI   | |  j  k s | |  j  k r" t S|  j  | } |  j  | } | j |  S(   s  
        Returns whether the first sprite is colliding with the second.

        :param first: A sprite or view
        :type first: :class:`Sprite <spyral.Sprite>` or a
                     :class:`View <spyral.View>`
        :param second: Another sprite or view
        :type second: :class:`Sprite <spyral.Sprite>` or a
                      :class:`View <spyral.View>`
        :returns: A ``bool``
        (   RE   R   t   collide_rect(   RU   t   firstt   secondt	   first_boxt
   second_box(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   collide_sprites  s
    c         C   s-   | |  j  k r t S|  j  | } | j |  S(   s  
        Returns whether the sprite is colliding with the point.

        :param sprite: A sprite
        :type sprite: :class:`Sprite <spyral.Sprite>`
        :param point: A point
        :type point: :class:`Vec2D <spyral.Vec2D>`
        :returns: A ``bool``
        (   RE   R   t   collide_point(   RU   R   t   pointt
   sprite_box(    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyR!    s    
c         C   s-   | |  j  k r t S|  j  | } | j |  S(   s  
        Returns whether the sprite is colliding with the rect.

        :param sprite: A sprite
        :type sprite: :class:`Sprite <spyral.Sprite>`
        :param rect: A rect
        :type rect: :class:`Rect <spyral.Rect>`
        :returns: A ``bool``
        (   RE   R   R  (   RU   R   R   R#  (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyR    s    
N(@   R   t
   __module__t   __doc__R.   RX   R[   R`   RP   Re   Rs   Rv   R   R   RN   R   R   R   R   R   R   R   R   R   R   R   R6   R   R   R   R   R   t   propertyRV   t   widtht   heightR   R   R   R   R   R   R   R   R   R   R   RQ   R   R
  RM   R  R  R  R  R   R  R   R  R  R  R  R   R!  R  (    (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyR       sx   ?						;																									
			
		
	_															(   t
   __future__R    R   R2   R   Rj   R   R   t   typesRZ   R   RO   t   ImportErrorR   t   actors_not_available_warningR   t	   itertoolsR   t	   layertreeR   t   collectionsR   t   weakrefR   RR   t
   weakmethodR   R   t   objectR   (    (    (    sO   /home/icarito/Proyectos/peru-learns-english/Games/ug3/../../Lib/spyral/scene.pyt   <module>   s(   

	
