
    i                        d Z ddlZddlZej                  s ed       ej                  s ed       ej                  j                  ej                  j                  e
            d   Zej                  j                  ed      ZddZd Z G d d	ej                   j"                        Z G d
 dej                   j"                        Zd Zedk(  r e        yy)z pygame.examples.chimp

This simple example is used for the line-by-line tutorial
that comes with pygame. It is based on a 'popular' web banner.
Note there are comments here, but for the full explanation,
follow along in the tutorial.
    NzWarning, fonts disabledzWarning, sound disableddatac                    t         j                  j                  t        |       }t        j
                  j                  |      }|j                         }|j                         }|d   |z  |d   |z  f}t        j                  j                  ||      }|6|dk(  r|j                  d      }|j                  |t        j                         ||j                         fS )Nr      r   r   )ospathjoindata_dirpgimageloadconvertget_size	transformscaleget_atset_colorkeyRLEACCELget_rect)namecolorkeyr   fullnamer   sizes         _/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/pygame/examples/chimp.py
load_imager      s    ww||Hd+HHHMM(#EMMOE>>DGeOT!Wu_-DLLud+Er>||F+H8R[[1%.."""    c                 
    G d d      }t         j                  rt         j                  j                         s |       S t        j                  j                  t        |       }t         j                  j                  |      }|S )Nc                       e Zd Zd Zy)load_sound.<locals>.NoneSoundc                      y )N selfs    r   playz"load_sound.<locals>.NoneSound.play+   s    r   N)__name__
__module____qualname__r%   r"   r   r   	NoneSoundr    *   s    	r   r)   )r   mixerget_initr   r	   r
   r   Sound)r   r)   r   sounds       r   
load_soundr.   )   sW      88288,,.{ww||Hd+HHHNN8$ELr   c                   (    e Zd ZdZd Zd Zd Zd Zy)Fistz8moves a clenched fist on the screen, following the mousec                     t         j                  j                  j                  |        t	        dd      \  | _        | _        d| _        d| _        y )Nzfist.pngr   )iiF)	r   spriteSprite__init__r   r   rectfist_offsetpunchingr#   s    r   r4   zFist.__init__;   s>    
		!!$' *:r :
DI&r   c                     t         j                  j                         }|| j                  _        | j                  j                  | j                         | j                  r| j                  j                  dd       yy)z)move the fist based on the mouse position      N)r   mouseget_posr5   topleftmove_ipr6   r7   )r$   poss     r   updatezFist.updateA   sX    hh 				$**+==IIb"% r   c                     | j                   s>d| _         | j                  j                  dd      }|j                  |j                        S y)z1returns true if the fist collides with the targetTN)r7   r5   inflatecolliderect)r$   targethitboxs      r   punchz
Fist.punchI   s@    }} DMYY&&r2.F%%fkk22 r   c                     d| _         y)zcalled to pull the fist backFN)r7   r#   s    r   unpunchzFist.unpunchP   s	    r   N)r&   r'   r(   __doc__r4   r@   rG   rI   r"   r   r   r0   r0   8   s    B&3r   r0   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)ChimpzXmoves a monkey critter across the screen. it can spin the
    monkey when it is punched.c                 .   t         j                  j                  j                  |        t	        ddd      \  | _        | _        t         j                  j                         }|j                         | _
        d| j                  _        d| _        d| _        y )Nz	chimp.pngr      )
   Z      F)r   r2   r3   r4   r   r   r5   displayget_surfacer   arear=   movedizzy)r$   screens     r   r4   zChimp.__init__Y   sk    
		!!$' *;A >
DI'')OO%	"			
r   c                 ^    | j                   r| j                          y| j                          y)z,walk or spin, depending on the monkeys stateN)rV   _spin_walkr#   s    r   r@   zChimp.updateb   s    ::JJLJJLr   c                    | j                   j                  | j                  df      }| j                  j                  |      s| j                   j                  | j                  j                  k  s-| j                   j
                  | j                  j
                  kD  ri| j                   | _        | j                   j                  | j                  df      }t        j                  j                  | j                  dd      | _	        || _         y)z7move the monkey across the screen, and turn at the endsr   TFN)
r5   rU   rT   containsleftrightr   r   flipr   )r$   newposs     r   rZ   zChimp._walki   s    A/yy!!&)yy~~		.$))//DIIOO2S!YYJ	A7\\..tzz4G
	r   c                 b   | j                   j                  }| j                  dz   | _        | j                  dk\  rd| _        | j                  | _        n<t
        j                  j                  } || j                  | j                        | _        | j                  j                  |      | _         y)zspin the monkey image   ih  F)centerN)	r5   rc   rV   originalr   r   r   rotater   )r$   rc   re   s      r   rY   zChimp._spins   s|    !!ZZ"_
::DJDJ\\((Ftzz:DJJJ''v'6	r   c                 N    | j                   sd| _         | j                  | _        yy)z,this will cause the monkey to start spinningTN)rV   r   rd   r#   s    r   punchedzChimp.punched   s     zzDJ JJDM r   N)	r&   r'   r(   rJ   r4   r@   rZ   rY   rg   r"   r   r   rL   rL   U   s     "
7'r   rL   c                     t        j                          t         j                  j                  dt         j                        } t         j                  j                  d       t         j                  j                  d       t        j                  | j                               }|j                         }|j                  d       t         j                  rit         j                  j                  dd      }|j                  ddd	      }|j                  |j!                         d
z  d      }|j#                  ||       | j#                  |d       t         j                  j%                          t'        d      }t'        d      }t)               }t+               }t         j,                  j/                  ||f      }	t         j0                  j3                         }
d}|rt|
j5                  d       t         j6                  j9                         D ]  }|j:                  t         j<                  k(  rd}#|j:                  t         j>                  k(  r |j@                  t         jB                  k(  rd}`|j:                  t         jD                  k(  rC|jG                  |      r!|jI                          |jK                          |jI                          |j:                  t         jL                  k(  s|jO                           |	jQ                          | j#                  |d       |	jS                  |        t         j                  j%                          |rtt        jT                          y)zthis function is called when the program starts.
    it initializes everything it needs, then runs in
    a loop until the function returns.)i   i  zMonkey FeverF)         N@   zPummel The Chimp, And Win $$$T)rO   rO   rO      rO   )centerxyr   z	whiff.wavz	punch.wav<   )+r   initrR   set_modeSCALEDset_captionr;   set_visibleSurfacer   r   fillfontFontrenderr   	get_widthblitr_   r.   rL   r0   r2   RenderPlaintimeClocktickeventgettypeQUITKEYDOWNkeyK_ESCAPEMOUSEBUTTONDOWNrG   r%   rg   MOUSEBUTTONUPrI   r@   drawquit)rW   
backgroundrx   texttextposwhiff_soundpunch_soundchimpfist
allspritesclockgoingr   s                r   mainr      sN   
 GGIZZ  bii8FJJ>*HH FOO-.J##%JOOO$ 
wwww||D"%{{:D,O--
(<(<(>(Bb-Ig& KK
F#JJOO [)K[)KGE6D&&t}5JGGMMOE E


2 XX\\^ 	EzzRWW$rzz)eii2;;.Fr111::e$$$&MMO$$&r///	 	 	J'


/ 2 GGIr   __main__)Nr   )rJ   r   pygamer   rx   printr*   r	   splitabspath__file__main_dirr
   r   r   r.   r2   r3   r0   rL   r   r&   r"   r   r   <module>r      s    
 	ww	
#$	xx	
#$77==23A677<<&)# 299 :.'BII .'b=H zF r   