o
    tVg                     @   s   d Z ddlZddlZejsed ejsed ejej	e
d ZejedZdddZd	d
 ZG dd dejjZG dd dejjZdd ZedkrUe  dS dS )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data   c                 C   s   t jt| }tj|}| }| }|d | |d | f}tj	
||}|d ur<|dkr5|d}||tj || fS )Nr   r   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   size r   I/home/ubuntu/.local/lib/python3.10/site-packages/pygame/examples/chimp.py
load_image   s   
r   c                 C   sB   G dd d}t jrt j s| S tjt| }t j|}|S )Nc                   @   s   e Zd Zdd ZdS )zload_sound.<locals>.NoneSoundc                 S   s   d S )Nr   selfr   r   r   play+   s   z"load_sound.<locals>.NoneSound.playN)__name__
__module____qualname__r   r   r   r   r   	NoneSound*   s    r"   )r
   mixerget_initr   r   r   r	   Sound)r   r"   r   soundr   r   r   
load_sound)   s   r'   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )Fistz8moves a clenched fist on the screen, following the mousec                 C   s0   t jj|  tdd\| _| _d| _d| _d S )Nzfist.pngr   )iiF)	r
   spriteSprite__init__r   r   rectfist_offsetpunchingr   r   r   r   r+   ;   s   
zFist.__init__c                 C   s<   t j }|| j_| j| j | jr| jdd dS dS )z)move the fist based on the mouse position      N)r
   mouseget_posr,   topleftmove_ipr-   r.   )r   posr   r   r   updateA   s   
zFist.updatec                 C   s*   | j sd| _ | jdd}||jS dS )z1returns true if the fist collides with the targetTN)r.   r,   inflatecolliderect)r   targethitboxr   r   r   punchI   s
   z
Fist.punchc                 C   s
   d| _ dS )zcalled to pull the fist backFN)r.   r   r   r   r   unpunchP   s   
zFist.unpunchN)r   r    r!   __doc__r+   r6   r<   r=   r   r   r   r   r(   8   s    r(   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )ChimpzXmoves a monkey critter across the screen. it can spin the
    monkey when it is punched.c                 C   sN   t jj|  tddd\| _| _t j }|	 | _
d| j_d| _d| _d S )Nz	chimp.pngr      )
   Z      F)r
   r)   r*   r+   r   r   r,   displayget_surfacer   arear3   movedizzy)r   screenr   r   r   r+   Y   s   


zChimp.__init__c                 C   s   | j r	|   dS |   dS )z,walk or spin, depending on the monkeys stateN)rH   _spin_walkr   r   r   r   r6   b   s   zChimp.updatec                 C   sx   | j | jdf}| j|s7| j j| jjk s| j j| jjkr7| j | _| j | jdf}tj| j	dd| _	|| _ dS )z7move the monkey across the screen, and turn at the endsr   TFN)
r,   rG   rF   containsleftrightr
   r   flipr   )r   newposr   r   r   rK   i   s    

zChimp._walkc                 C   sZ   | j j}| jd | _| jdkrd| _| j| _ntjj}|| j| j| _| jj|d| _ dS )zspin the monkey image   ih  F)centerN)	r,   rR   rH   originalr   r
   r   rotater   )r   rR   rT   r   r   r   rJ   s   s   

zChimp._spinc                 C   s   | j sd| _ | j| _dS dS )z,this will cause the monkey to start spinningTN)rH   r   rS   r   r   r   r   punched   s   zChimp.punchedN)	r   r    r!   r>   r+   r6   rK   rJ   rU   r   r   r   r   r?   U   s    	
r?   c                  C   s  t   t jdt j} t jd t jd t | 	 }|
 }|d t jrJt jdd}|ddd	}|j| d
 dd}||| | |d t j  td}td}t }t }t j||f}	t j }
d}|r|
d t j D ]=}|jt jkrd}q~|jt jkr|j t j!krd}q~|jt j"kr|#|r|$  |%  q~|$  q~|jt j&kr|'  q~|	(  | |d |	)|  t j  |stt *  dS )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)rA   rA   rA      rA   )centerxyr   z	whiff.wavz	punch.wav<   )+r
   initrD   set_modeSCALEDset_captionr1   set_visibleSurfacer   r   fillfontFontrenderr   	get_widthblitrO   r'   r?   r(   r)   RenderPlaintimeClocktickeventgettypeQUITKEYDOWNkeyK_ESCAPEMOUSEBUTTONDOWNr<   r   rU   MOUSEBUTTONUPr=   r6   drawquit)rI   
backgroundre   texttextposwhiff_soundpunch_soundchimpfist
allspritesclockgoingrn   r   r   r   main   sT   








r   __main__)Nr   )r>   r   pygamer
   re   printr#   r   splitabspath__file__main_dirr   r	   r   r'   r)   r*   r(   r?   r   r   r   r   r   r   <module>   s"   

1D
