Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/05/2010, 12:55
Avatar de pato12
pato12
 
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 6 meses
Puntos: 101
Sonrisa [APORTE] Un juego

Hola,
Hace unos meses programe un juego en python cuando estaba aburrido y quería aprender python xD... (no se porque siempre hago este juego )..
Código Python:
Ver original
  1. # Por Pato12
  2. # Este script es libre de usar siempre
  3. # cuando no borren estas lineas y respeten la
  4. # licencia GNU:
  5. # http://creativecommons.org/licenses/GPL/2.0/deed.es_AR  
  6. # GNU General Public License
  7. import os, pygame, sqlite3
  8. from pygame.locals import *
  9.  
  10. ######################################################################
  11. pygame.init()
  12. screen = pygame.display.set_mode((800, 600)) # creamos la ventana
  13. pygame.display.set_caption( "Juego de Rompe Ladrillos - By pato12" )
  14. ######################################################################
  15.  
  16. coneccion = sqlite3.connect('puntajes.db')
  17. cursor = coneccion.cursor()
  18.  
  19. cursor.execute('CREATE TABLE IF NOT EXISTS puntaje (id INTEGER PRIMARY KEY, nombre TEXT, puntos NUMERIC)')
  20.  
  21.  
  22. #cursor.execute('insert into puntaje (nombre,puntos) values ("pato",520)')
  23.  
  24. coneccion.commit()
  25. cursor.close()
  26.  
  27.  
  28. ######################################################################
  29.  
  30. def imgcolorkey(image, colorkey):
  31.     if colorkey is not None:
  32.         if colorkey is -1:
  33.             colorkey = image.get_at((0, 0))
  34.         image.set_colorkey(colorkey, RLEACCEL)
  35.     return image
  36.  
  37. def load_image(filename, colorkey = None):
  38.     image = pygame.image.load(filename).convert()
  39.     return imgcolorkey(image, colorkey)
  40.  
  41. class SpriteSheet:
  42.     def __init__(self, filename):
  43.         self.sheet = load_image(filename)
  44.     def imgat(self, rect, colorkey = None):
  45.         rect = Rect(rect)
  46.         image = pygame.Surface(rect.size).convert()
  47.         image.blit(self.sheet, (0, 0), rect)
  48.         return imgcolorkey(image, colorkey)
  49.     def imgsat(self, rects, colorkey = None):
  50.         imgs = []
  51.         for rect in rects:
  52.             imgs.append(self.imgat(rect, colorkey))
  53.         return imgs
  54.  
  55. ######################################################################
  56.  
  57.  
  58. def escribir_game(texto,tam,color,x,y):
  59.     texto = unicode(texto, "UTF-8")
  60.     fuente = pygame.font.Font('img/arial.ttf', tam)
  61.     texto = fuente.render(texto, 1, color)
  62.     screen.blit(texto, (x,y))
  63.      
  64. def pintar_fondo_default(fondo = 'img/fondo.png'):
  65.     screen.blit(load_image(fondo), (0,0))
  66.  
  67.  
  68. ###################################################
  69.  
  70.  
  71.  
  72.  
  73. def game_goo():
  74.     mapas=[
  75.                                  
  76.     [0,0,0,0,0,0,0,0,0,0,
  77.     0,0,0,0,0,0,0,0,0,0,
  78.     0,0,0,1,1,1,1,0,0,0,
  79.     0,0,1,5,0,0,5,1,0,0,
  80.     0,0,1,0,0,0,0,1,0,0,
  81.     0,0,1,0,0,0,0,1,0,0,
  82.     0,0,1,5,0,0,5,1,0,0,
  83.     0,0,0,1,1,1,1,0,0,0,
  84.     0,0,0,0,0,0,0,0,0,0,
  85.     0,0,0,0,0,0,0,0,0,0]]
  86.    
  87.  
  88.     _game=1
  89.     _vidas=3
  90.     _nivel_game=1
  91.     _puntos_game=0
  92.     __x=352
  93.     _bola_sube=True
  94.     _y_b=485
  95.     _x_b=450
  96.     __angulo=0
  97.     _key_move=''
  98.     _empezo_game_mover=False
  99.     _pausa=False
  100.    
  101.     SpriteSheet_cosas = SpriteSheet('img/barra.png')
  102.    
  103.     barra_srf = SpriteSheet_cosas.imgat((0,0,180,12),-1)
  104.          
  105.     bola_srf = SpriteSheet_cosas.imgat((0,20,10,10),-1)
  106.     vida_srf = SpriteSheet_cosas.imgat((170,20,10,10),-1)
  107.    
  108.     SpriteSheet_ladrillos = SpriteSheet('img/ladrillos.png')
  109.    
  110.     _ladrillo1 = SpriteSheet_ladrillos.imgat((0,0,80,20),-1)
  111.     _ladrillo2 = SpriteSheet_ladrillos.imgat((0,20,80,20),-1)
  112.     _ladrillo3 = SpriteSheet_ladrillos.imgat((0,40,80,20),-1)
  113.     _ladrillo4 = SpriteSheet_ladrillos.imgat((0,50,80,20),-1)
  114.     _ladrillo5 = SpriteSheet_ladrillos.imgat((0,60,80,20),-1)
  115.    
  116.     mascaras_ladrrillos={1:_ladrillo1,2:_ladrillo2,3:_ladrillo3,4:_ladrillo4,5:_ladrillo5}
  117.    
  118.  
  119.    
  120.     SpriteSheet_puntaje = SpriteSheet('img/formas.png')          
  121.     barra_datos = SpriteSheet_puntaje.imgat((0,66,800,200))          
  122.                
  123.     all = pygame.sprite.RenderPlain()
  124.     while _game:
  125.         #####################################
  126.           for event in pygame.event.get():
  127.               if event.type == QUIT:
  128.                   _game=0
  129.                   salir_confirmar()
  130.          #####################################
  131.           if pygame.key.get_pressed()[K_p]:
  132.              _pausa= not _pausa
  133.              
  134.           if pygame.key.get_pressed()[K_m]:
  135.              _game=0
  136.              main_menu_game()
  137.           if not _pausa:  
  138.                  if pygame.key.get_pressed()[K_a] or pygame.key.get_pressed()[K_LEFT]:
  139.                    if __x>0:
  140.                       __x=__x-5
  141.                       if not _empezo_game_mover:
  142.                           _x_b=_x_b-5
  143.                    _key_move='a'
  144.                            
  145.                  if pygame.key.get_pressed()[K_d] or pygame.key.get_pressed()[K_RIGHT]:
  146.                     if __x<(800-180):
  147.                        __x=__x+5
  148.                        if not _empezo_game_mover:
  149.                           _x_b=_x_b+5
  150.                     _key_move='d'
  151.                
  152.                  if pygame.key.get_pressed()[K_w] or pygame.key.get_pressed()[K_SPACE]:
  153.                     if not _empezo_game_mover:
  154.                         _empezo_game_mover=True
  155.            
  156.              
  157.           ##################################
  158.           if not _pausa:
  159.                  if _empezo_game_mover:
  160.                     if _bola_sube:
  161.                         if _y_b>0:
  162.                            _y_b=_y_b-9
  163.                         else:
  164.                           _bola_sube=False
  165.                     else:
  166.                         if _y_b<(500-5):
  167.                             _y_b=_y_b+9
  168.                         else:
  169.                           if __x<_x_b and (__x+180)>_x_b:
  170.                              _bola_sube=True
  171.                              if _key_move == 'd':
  172.                                 __angulo=3
  173.                              if _key_move == 'a':
  174.                                 __angulo=-3
  175.                           else:
  176.                             _game=0
  177.                             if _vidas>1:
  178.                                _vidas=_vidas-1
  179.                                _game=1
  180.                                _empezo_game_mover=False
  181.                                _y_b=485
  182.                                _x_b=450
  183.                                __x=352
  184.                                __angulo=0
  185.                                _bola_sube=True
  186.                             else:
  187.                                main_game_over(_puntos_game)
  188.                                            
  189.                     if _x_b<=0:
  190.                        __angulo=3
  191.                     if _x_b>=(800-10):
  192.                        __angulo=-3
  193.                          
  194.                     _x_b+=__angulo
Continua....
__________________
Half Music - www.halfmusic.com