o
    OZŽh  ã                   @   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ÚscaleZget_atZset_colorkeyZRLEACCELÚget_rect)ÚnameZcolorkeyr   Úfullnamer   Úsize© r   úD/var/www/auris/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
   ÚmixerZget_initr   r   r   r	   Z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ÿÿÿi°ÿÿÿF)	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
   ÚmouseZget_posr&   ÚtopleftZ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 targetTéûÿÿÿN)r(   r&   ZinflateZcolliderect)r   ÚtargetZ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%   r.   r1   r2   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&   ÚdisplayZget_surfacer   Úarear,   Ú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)r<   Ú_spinÚ_walkr   r   r   r   r.   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&   r;   r:   ÚcontainsÚleftÚrightr
   r   Úflipr   )r   Znewposr   r   r   r?   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&   rE   r<   Úoriginalr   r
   r   Úrotater   )r   rE   rG   r   r   r   r>   s   s   

zChimp._spinc                 C   s   | j sd| _ | j| _dS dS )z,this will cause the monkey to start spinningTN)r<   r   rF   r   r   r   r   Úpunched   s   þzChimp.punchedN)	r   r   r   r3   r%   r.   r?   r>   rH   r   r   r   r   r4   U   s    	
r4   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r‰d}q~|jt jkr˜|j t j!kr˜d}q~|jt j"kr±| #|¡r¬| $¡  | %¡  q~| $¡  q~|jt j&kr»| '¡  q~|	 (¡  |  |d¡ |	 )| ¡ t j ¡  |stt  *¡  dS )zŒthis 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)r6   r6   r6   é   r6   )ZcenterxÚyr   z	whiff.wavz	punch.wavé<   )+r
   Úinitr9   Úset_modeZSCALEDZset_captionr+   Zset_visibleZSurfacer   r   ÚfillÚfontZFontÚrenderr   Z	get_widthZblitrC   r!   r4   r"   r#   ZRenderPlainÚtimeZClockZtickÚeventÚgetÚtypeZQUITZKEYDOWNÚkeyZK_ESCAPEZMOUSEBUTTONDOWNr1   r   rH   ZMOUSEBUTTONUPr2   r.   ZdrawÚquit)r=   Ú
backgroundrS   ÚtextZtextposZwhiff_soundZpunch_soundZchimpÚfistZ
allspritesÚclockZgoingrV   r   r   r   Úmain†   sT   






€

ér_   Ú__main__)Nr   )r3   r   Zpygamer
   rS   Úprintr   r   ÚsplitÚabspathÚ__file__Zmain_dirr   r	   r   r!   r#   r$   r"   r4   r_   r   r   r   r   r   Ú<module>   s"   

1D
ÿ