o
    OZh]                     @   s   d Z ddlZddlZddlZddlZG dd dZdd ZedkrZe	ej
dk rKed	 ed
 ed ejejed Zeejedd n	eej
dd   e  dS dS )a  
pygame.examples.mask

A pygame.mask collision detection production.




Brought

       to
             you
                     by

    the

pixels
               0000000000000
      and
         111111


This is 32 bits:
    11111111111111111111111111111111

There are 32 or 64 bits in a computer 'word'.
Rather than using one word for a pixel,
the mask module represents 32 or 64 pixels in one word.
As you can imagine, this makes things fast, and saves memory.

Compute intensive things like collision detection,
and computer vision benefit greatly from this.


This module can also be run as a stand-alone program, excepting
one or more image file names as command line arguments.
    Nc                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
Spritez[
    Moving Sprite demonstrating pixel-perfect collisions between pg.mask.Mask objects
    Nc                 C   sT   || _ | j  \| _| _|dur|| _ntj| j | _t|| _t|| _	dS )a  
        Positional arguments:
            pos: Position of the sprite (sequence of 2 integers)
            vel: Movement velocity of the sprite (sequence of 2 integers)
            surface: Image (as a pg.Surface) of the sprite
            mask: pg.mask.Mask object (optional)
        N)
surfaceget_sizewidthheightmaskpgfrom_surfaceVector2posvel)selfr   r   r   r    r   C/var/www/auris/lib/python3.10/site-packages/pygame/examples/mask.py__init__4   s   zSprite.__init__c              
   C   sF  dd |j | j  D }| j|j|}|dkrdS t| j|j|d d |d f| j|j|d d |d f | j|j|d |d d f| j|j|d |d d f }|jdkrg|jdkrgdS |j| j }|| d| |  }|dkr|d9 }|  j|j| |j| g7  _| j| |j | |j g7  _dS dS )z
        Test if the sprites are colliding and
        resolve the collision in this case.

        Positional arguments:
            sprite: other sprite to test for collisions
        c                 S   s   g | ]}t |qS r   )int).0xr   r   r   
<listcomp>N   s    z"Sprite.collide.<locals>.<listcomp>r   N      gffffff?)r   r   Zoverlap_arear   r
   r   yr   )r   spriteoffsetoverlapZn_collisionsZ	delta_veljr   r   r   collideF   s*   &zSprite.collidec                 C   s   |  j | j7  _ dS )z!
        Move the sprite
        N)r   r   )r   r   r   r   updateo   s   zSprite.update)N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   /   s
    
)r   c                  G   s  t | dkr
tdt  d}tj|}tj }g }g }| D ]}|tj	
|  |tj|d  q!g }tdD ]1}|t | }	ttd|d td|d ftddtddf||	 ||	 d	}
||
 q@	 tj D ]}|jtjtjfv r dS qx|d t|D ]Z\}}
||d d D ]}|
| q|
  |
jj|
j k r|d |
j_n|
jj|d kr|
j |
j_|
jj|
j k r|d |
j_n|
jj|d kr|
j |
j_| |
j!|
j q|"d tj#  qs)a  
    Display multiple images bounce off each other using collision detection

    Positional arguments:
      one or more image file names.

    This pg.masks demo will display multiple moving sprites bouncing
    off each other. More than one sprite image can be provided.
    r   z/Require at least one image file name: non given)i  i     r      )r   r   r   r   TN)      d      )$len
ValueErrorr   initdisplayset_modetimeZClockappendimageloadZconvert_alphar   r	   ranger   randomuniformeventgettypeZQUITZKEYDOWNfill	enumerater   r   r   r   r   r   r   Zblitr   Ztickflip)argsZscreen_sizescreenclockZimagesmasksZ
image_pathZspritesir   r   r6   Zsprite_indexZother_spriter   r   r   mainv   s^   





rA   __main__r   z$Usage: mask.py <IMAGE> [<IMAGE> ...]z5Let many copies of IMAGE(s) bounce against each otherzPress any key to quitdataz
alien1.pngr   )r!   osr4   sysZpygamer   r   rA   r   r*   argvprintpathsplitabspath__file__Zmain_dirjoinquitr   r   r   r   <module>   s"   &GJ