
    i0                        d Z ddlZddlZddlmZ ddlZej                  j                         s e	d      dZ
dZdZdZ ej                  ddd	d
      Zdaej"                  j%                  ej"                  j'                  e            d   Zd Zd Z G d dej0                  j2                        Z G d dej0                  j2                        Z G d dej0                  j2                        Z G d dej0                  j2                        Z G d dej0                  j2                        Z G d dej0                  j2                        ZddZ e!dk(  r e          ejD                          yy)a7   pygame.examples.aliens

Shows a mini game where you have to defend against aliens.

What does it show you about pygame?

* pg.sprite, the difference between Sprite and Group.
* dirty rectangle optimization for processing for speed.
* music with pg.mixer.music, including fadeout
* sound effects with pg.Sound
* event processing, keyboard handling, QUIT handling.
* a main loop frame limited with a game clock from pg.time.Clock
* fullscreen switching.


Controls
--------

* Left and right arrows to move.
* Space bar to shoot
* f key to toggle between fullscreen.

    N)Listz%Sorry, extended image module required      <      i  i  c                     t         j                  j                  t        d|       } 	 t        j
                  j                  |       }|j                         S # t        j                  $ r$ t        d|  dt	        j                                w xY w)z$loads an image, prepares it for playdatazCould not load image "z" )ospathjoinmain_dirpgimageloaderror
SystemExit	get_errorconvert)filesurfaces     `/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/pygame/examples/aliens.py
load_imager   1   sv    77<<&$/DL((--% ?? 88 L1$r",,.9IJKKLs   A 7Bc                     t         j                  syt        j                  j	                  t
        d|       } 	 t         j                  j                  |       }|S # t         j                  $ r t        d|         Y yw xY w)z-because pygame can be compiled without mixer.Nr	   zWarning, unable to load, )	r   mixerr
   r   r   r   Soundr   print)r   sounds     r   
load_soundr   ;   sd    8877<<&$/D2t$88 2)$012s    A !A=<A=c                   X    e Zd ZU dZdZdZdZg Zee	j                     ed<   d Zd Zd Zy	)
Playerz1Representing the player as a moon buggy type car.
      imagesc                 0   t        j                  j                  j                  | g|  | j                  d   | _        | j
                  j                  t        j                        | _	        d| _
        | j                  j                  | _        d| _        y )Nr   	midbottom)r   spriteSprite__init__r$   r   get_rect
SCREENRECTr'   rect	reloadingtoporigtopfacingselfgroupss     r   r+   zPlayer.__init__X   sj    
		!!$00[[^
JJ''*2F2F'G	yy}}    c                    |r|| _         | j                  j                  || j                  z  d       | j                  j	                  t
              | _        |dk  r| j                  d   | _        n|dkD  r| j                  d   | _        | j                  | j                  j                  | j                  z  dz  z
  | j                  _        y )Nr      r   )r2   r.   move_ipspeedclampr-   r$   r   r1   leftbouncer0   )r4   	directions     r   movezPlayer.move`   s    #DK		)djj0!4IIOOJ/	q=QDJ]QDJ		$++(E(IJ		r6   c                     | j                   | j                  z  | j                  j                  z   }|| j                  j                  fS )N)r2   
gun_offsetr.   centerxr0   )r4   poss     r   gunposzPlayer.gunposk   s6    kkDOO+dii.?.??DIIMM!!r6   N)__name__
__module____qualname____doc__r:   r=   rA   r$   r   r   Surface__annotations__r+   r?   rD    r6   r   r    r    P   s7    ;EFJ!FD!	K"r6   r    c                   N    e Zd ZU dZdZdZg Zeej                     e
d<   d Zd Zy)Alienz7An alien space ship. That slowly moves down the screen.   r   r$   c                    t        j                  j                  j                  | g|  | j                  d   | _        | j
                  j                         | _        t        j                  d      t        j                  z  | _        d| _        | j                  dk  r t        j                  | j                  _        y y )Nr   )r(   r8   )r   r)   r*   r+   r$   r   r,   r.   randomchoicerM   r:   r2   framer-   rightr3   s     r   r+   zAlien.__init__w   s    
		!!$00[[^
JJ'')	mmG,u{{:
;;?(..DIIO r6   c                    | j                   j                  | j                  d       t        j	                  | j                         s^| j                   | _        | j                   j
                  dz   | j                   _        | j                   j                  t              | _         | j                  dz   | _        | j                  | j                  | j                  z  dz     | _        y )Nr   r8      )r.   r9   r2   r-   containsbottomr0   r;   rR   r$   	animcycler   r4   argskwargss      r   updatezAlien.update   s    		$++q)""499-;;,DK II,,q0DIIM		
3DIZZ!^
[[t~~!=!AB
r6   N)rE   rF   rG   rH   r:   rX   r$   r   r   rI   rJ   r+   r\   rK   r6   r   rM   rM   p   s-    AEI!FD!/Cr6   rM   c                   N    e Zd ZU dZdZdZg Zeej                     e
d<   d Zd Zy)	Explosionz5An explosion. Hopefully the Alien and not the player!r   rU   r$   c                    t        j                  j                  j                  | g|  | j                  d   | _        | j
                  j                  |j                  j                        | _        | j                  | _
        y )Nr   )center)r   r)   r*   r+   r$   r   r,   r.   r`   defaultlifelife)r4   actorr5   s      r   r+   zExplosion.__init__   s^    
		!!$00[[^
JJ''uzz/@/@'A	$$	r6   c                     | j                   dz
  | _         | j                  | j                   | j                  z  dz     | _        | j                   dk  r| j	                          yy)zcalled every time around the game loop.

        Show the explosion surface for 'defaultlife'.
        Every game tick(update), we decrease the 'life'.

        Also we animate the explosion.
        r8   r   r   N)rb   r$   rX   r   killrY   s      r   r\   zExplosion.update   sN     IIM	[[dnn!<q!@A
99>IIK r6   N)rE   rF   rG   rH   ra   rX   r$   r   r   rI   rJ   r+   r\   rK   r6   r   r^   r^      s,    ?KI!FD!%r6   r^   c                   J    e Zd ZU dZdZg Zeej                     e	d<   d Z
d Zy)Shotz!a bullet the Player sprite fires.r#   r$   c                     t        j                  j                  j                  | g|  | j                  d   | _        | j
                  j                  |      | _        y )Nr   r&   )r   r)   r*   r+   r$   r   r,   r.   )r4   rC   r5   s      r   r+   zShot.__init__   sG    
		!!$00[[^
JJ''#'6	r6   c                     | j                   j                  d| j                         | j                   j                  dk  r| j	                          yy)z^called every time around the game loop.

        Every tick we move the shot upwards.
        r   N)r.   r9   r:   r0   re   rY   s      r   r\   zShot.update   s:    
 			!TZZ(99==AIIK r6   NrE   rF   rG   rH   r:   r$   r   r   rI   rJ   r+   r\   rK   r6   r   rg   rg      s'    +E!FD!7
r6   rg   c                   J    e Zd ZU dZdZg Zeej                     e	d<   d Z
d Zy)BombzA bomb the aliens drop.	   r$   c                    t        j                  j                  j                  | g|  | j                  d   | _        | j
                  j                  |j                  j                  dd      j                        | _        || _
        y )Nr      r&   )r   r)   r*   r+   r$   r   r,   r.   r?   r'   explosion_group)r4   alienrp   r5   s       r   r+   zBomb.__init__   sd    
		!!$00[[^
JJ''%**//!Q2G2Q2Q'R	.r6   c                     | j                   j                  d| j                         | j                   j                  dk\  r't	        | | j
                         | j                          yy)zcalled every time around the game loop.

        Every frame we move the sprite 'rect' down.
        When it reaches the bottom we:

        - make an explosion.
        - remove the Bomb.
        r   i  N)r.   r9   r:   rW   r^   rp   re   rY   s      r   r\   zBomb.update   sL     			!TZZ(99s"dD001IIK #r6   Nrj   rK   r6   r   rl   rl      s'    !E!FD!/r6   rl   c                       e Zd ZdZd Zd Zy)Scorezto keep track of the score.c                 r   t        j                  j                  j                  | g|  t         j                  j                  d d      | _        | j                  j                  d       d| _        d| _        | j                          | j                  j                         j                  dd      | _        y )N   r8   whiter(   r!   i  )r   r)   r*   r+   fontFont
set_italiccolor	lastscorer\   r   r,   r?   r.   r3   s     r   r+   zScore.__init__   s    
		!!$00GGLLr*			Q
JJ'')..r37	r6   c                     t         | j                  k7  rAt         | _        dt          }| j                  j                  |d| j                        | _        yy)z9We only update the score in update() when it has changed.zScore: r   N)SCOREr|   rx   renderr{   r   )r4   rZ   r[   msgs       r   r\   zScore.update   sD    DNN""DNE7#C))#q$**=DJ #r6   N)rE   rF   rG   rH   r+   r\   rK   r6   r   rt   rt      s    %8>r6   rt   c                 H   t        j                         d   dk(  r"t         j                  j                  dddd       t        j                          t         j                  r4t         j                  j                         st        d       d t         _        d}d} t         j                  j                  t        j                  | d      }t         j                  j                  t        j                  | |      }t        d      }|t         j                  j                  |d	d      gt        _        t        d
      }|t         j                  j                  |d	d	      gt"        _        dD cg c]  }t        |       c}t$        _        t        d      gt&        _        t        d      gt(        _        t         j                  j+                  t$        j                   d   d      }t         j                  j-                  |       t         j                  j/                  d       t         j0                  j3                  d       t        d      }t        j4                  t        j                        }t7        dt        j8                  |j;                               D ]  }	|j=                  ||	df        |j=                  |d       t         j                  j                          t?        d      }
t?        d      }t         j                  rwt@        jB                  jE                  tF        dd      }t         j                  jH                  jK                  |       t         j                  jH                  jM                  d       t         jN                  jQ                         }t         jN                  jQ                         }t         jN                  jQ                         }t         jN                  jS                         }t         jN                  jU                         }tV        }t         jX                  j[                         }t        |      }t%        |||       t         j\                  r|j_                  ta        |             |jc                         rt         jd                  jg                         D ]  }|jh                  t         jj                  k(  r y |jh                  t         jl                  k(  r|jn                  t         jp                  k(  r y |jh                  t         jl                  k(  s}|jn                  t         jr                  k(  s|snt        d       |ju                         }t         j                  j                  t        j                  | t         jv                  z  |      }|j=                  |d       n\t        d       |ju                         }t         j                  j                  t        j                  | |      }|j=                  |d       t         j                  j                          | } t         jn                  jy                         }|j{                  ||       |j}                          |t         j~                     |t         j                     z
  }|j                  |       |t         j                     }|j                  sQ|rOt        |      t        k  r=t)        |j                         ||       t         j                  r||jM                          ||_C        |r|d	z
  }n7t        t        j                         t        z        st%        |||       tV        }|r<t        t        j                         t        z        st'        |jN                  |||       t         jN                  j                  ||d	      D ]U  }t         j                  r|
|
jM                          t#        ||       t#        ||       t        d	z   aL|j                          W t         jN                  j                  ||d	d	      j                         D ]9  }t         j                  r|
|
jM                          t#        ||       t        d	z   aL; t         jN                  j                  ||d	      D ]L  }t         j                  r|
|
jM                          t#        ||       t#        ||       |j                          N |j                  |      }t         j                  j}                  |       |j                  d       |jc                         rt         j                  r)t         j                  jH                  j                  d       t         jX                  j                  d       y c c}w )Nr   r   iD      i   zWarning, no soundFzplayer1.gifr8   zexplosion1.gif)z
alien1.gifz
alien2.gifz
alien3.gifzbomb.gifzshot.gif)r   r   zPygame Alienszbackground.gif)r   r   zboom.wavzcar_door.wavr	   zhouse_lo.wavr(   zChanging to FULLSCREENzChanging to windowed mode(   i  )Tr   get_sdl_versionr   pre_initinitget_initr   displaymode_okr-   sizeset_moder   	transformflipr    r$   r^   rM   rl   rg   scaleset_iconset_captionmouseset_visiblerI   rangewidth	get_widthblitr   r
   r   r   r   musicr   playr)   GroupRenderUpdatesGroupSingleALIEN_RELOADtimeClockrx   addrt   aliveeventgettypeQUITKEYDOWNkeyK_ESCAPEK_fcopy
FULLSCREENget_pressedclearr\   K_RIGHTK_LEFTr?   K_SPACEr/   len	MAX_SHOTSrD   intrP   
ALIEN_ODDS	BOMB_ODDSspritecollider~   re   groupcollidekeysdrawtickfadeoutwait)winstyle
fullscreen	bestdepthscreenimgimiconbgdtile
backgroundx
boom_soundshoot_soundr   aliensshotsbombsall	lastalienalienreloadclockplayerr   screen_backupkeystater>   firingrq   bombdirtys                                r   mainr      s   	A!#
%Q-GGI	xx))+!"JH

"":??HbAIZZ  (IFF ]
#C",,++CA67FM
%
&CR\\..sAq9:I-WXrJrNXELj)*DKj)*DK <<ell1ox8DJJJJ?+HH )*GJOO,J1j&&(9(9(;< )!Q()
KK
F#JJOO J'J^,K	xxXv~>
E"
B YY__FIIOOEIIOOE
))
!
!
#C		%%'I KGGMMOE C[F	Y 
wwc
 ,,.XX\\^ 	0EzzRWW$zzRZZ'EII,DzzRZZ'99&%67(.!#!4!4&OOX-Ey" M6:9:(.!#!4!4&OOXy" M6:JJOO%%/J-	00 66%%' 			&*% 	

 RZZ(8BII+>>	I"**%Fs5zI/E%-xxK3  "! %/KV]]_z12&#y)&K S9!<=!!3s3 YY,,VVQ? 	ExxJ2!eS!fc"AIEKKM	 YY++FE1a@EEG 	ExxJ2!eS!AIE		 II++FE1= 	DxxJ2!fc"dC KKM	  


%  	

2i ,,.l 
xx
t$GGLLO Ys   )f__main__)r   )#rH   r
   rP   typingr   pygamer   r   get_extendedr   r   r   r   r   Rectr-   r~   r   splitabspath__file__r   r   r   r)   r*   r    rM   r^   rg   rl   rt   r   rE   quitrK   r6   r   <module>r      sD  0 
    
xx
<
== 	
	RWWQ3$
	77==23A6
*"RYY "@CBII C4		   6299 *299 6>BII >(\@ zFBGGI r6   