コード例 #1
0
 def __init__(self, Myscreen_width=500, Myscreen_height=500):
     self.__version__ = "0.0" # Version Activa
     # Inicializar valores
     self.MyPantalla_config = config_game_FJBecerra.clssconfig_game()
     
     # Activar propiedades graficas
     self.MyPantalla = self.func_Definir_Tamano_Pantalla() # Asignar tamaño
     self.MyPantalla_color = self.MyPantalla_config.func_Devolver_Color("Blanco")
     self.MyPantalla.fill(self.MyPantalla_color) # Asignar el color de fondo
     self.MyPantalla_img = self.MyPantalla_config.func_Devolver_Grafico("Fondo")
     self.MyPantalla_img = pygame.image.load(self.MyPantalla_img) # Crea un superficie con la imagen
     pygame.display.set_caption(self.MyPantalla_config.men_titulo)
     self.MyListSprites = [ ]
     self.MyVelocidad = 5
     self.MyLimiteSup = 80
     self.MyLimiteInf = 430
     self.MyObjLimx = 5      # Control de rect
     self.MyObjLimy = 495    # Control de rect
     self.MyObjLim = 20  # nº Inicial de elementos
     self.MyObjTamano = 20
 
     # Sonido
     self.MySound_Fondo = self.MyPantalla_config.func_Devolver_Sonido("Fondo")
     self.MySound_Fondo= pygame.mixer.Sound(self.MySound_Fondo)
     self.MySound_Explo = self.MyPantalla_config.func_Devolver_Sonido("Explo")
     self.MySound_Explo= pygame.mixer.Sound(self.MySound_Explo)
     self.MySound_Fondo.play(-1)
     self.MyActivarSound_Fondo = True
 
     # Crear nave azul
     self.MyNavea = clssNavea()
     # Crear un lista de nave roja
     self.MyNavebList = [ ] 
     for contador in range(10):
         self.MyNavebList.append(clssNaver())
     # Redefinir posiciones de salida
     for MyNaver in range(len(self.MyNavebList)):
         # Llega abajo de la pantalla y añadimos otro
         my_x =   random.randrange(self.MyObjLimx,self.MyObjLimy) # Posiciones aleatorias
         my_y =  random.randrange(-(self.MyObjLimy),-(self.MyObjLimx)) # Posiciones aleatorias
         self.MyNavebList[MyNaver].rect =(pygame.Rect(my_x,my_y,self.MyObjTamano,self.MyObjTamano))      
 
     # Definir fuentes de texto
     self.MyFuenteTexto = pygame.font.SysFont("Arial",30, True, False) # Para el reloj de pantalla
     self.MyFuenteTexto_txtcolor  = self.MyPantalla_config.func_Devolver_Color("Amarillo")
     self.MyFuenteTexto_bckcolor = self.MyPantalla_config.func_Devolver_Color("Negro")
コード例 #2
0
    def __init__ (self):
        pygame.sprite.Sprite.__init__(self) # Inicializar la clase base 
        self.__version__ = "0.0" # Version Activa
        # Inicializar valores
        self.navea_config = config_game_FJBecerra.clssconfig_game()
        self.navea_img = self.navea_config.func_Devolver_Grafico("Navea") 
        self.navea_img = pygame.image.load(self.navea_img) # Crea un superficie con la imagen
        self.naveaex_img = self.navea_config.func_Devolver_Grafico("Explo") 
        self.naveaex_img = pygame.image.load(self.naveaex_img) # Crea un superficie con la imagen
        
        
        self.image = self.navea_img
        self.rect   = self.image.get_rect()

        # Posicion por defecto       
        self.rect.top = 430
        self.rect.left = 225
コード例 #3
0
    def __init__ (self):
        pygame.sprite.Sprite.__init__(self) # Inicializar la clase base 
        self.__version__ = "0.0" # Version Activa
        # Inicializar valores
        self.naver_config = config_game_FJBecerra.clssconfig_game()
        self.naver_img = self.naver_config.func_Devolver_Grafico("Naver") 
        self.naver_img = pygame.image.load(self.naver_img) # Crea un superficie con la imagen
        
        self.image = self.naver_img
        self.rect   = self.image.get_rect()

        # Posicion por defecto       
        self.rect.top = 0
        self.rect.left = 0
        # Posicion aleatorio
        self.MyObjLimx = 5     # Control de rect
        self.MyObjLimy = 495    # Control de rect
        self.rect.top =   random.randrange(self.MyObjLimx,self.MyObjLimy) # Posiciones aleatorias
        self.rect.top =  random.randrange(-(self.MyObjLimy),-(self.MyObjLimx)) # Posiciones aleatorias
コード例 #4
0
def main():
    pygame.init() # Inicilizar los módulos de pygame
    salir_event = False
    marcador = 0
    segundos = 0    
    finJuego = False

    # Un reloj evita que el programa compruebe los eventos
    # recursivamente desaprovechando recursos
    time_event_1 = pygame.time.Clock()
    time_screen = pygame.time.Clock()

    # Configuracion del juego
    Myconfig = config_game_FJBecerra.clssconfig_game()
        
    # Crear la pantalla
    MyPantalla = config_render_FJBecerra.clssPantalla()
    MyTiempo = MyPantalla.MyFuenteTexto.render("Tiempo: "+str(segundos),0,MyPantalla.MyFuenteTexto_txtcolor,MyPantalla.MyFuenteTexto_bckcolor)      
        
        
    while salir_event != True:
        # Activamos el reloj 20 Frames/sg lo que detiene el while
        time_event_1.tick(10)
        segundos = pygame.time.get_ticks()/1000 # Pasar de milisegundos a segundos       

        # Cada 30 segundos ponemos una nave mas
        if segundos % 30 ==0 :
            MyPantalla.func_Aumentar_Navesr()

        MyPantalla.func_Pintar_Pantalla()
        MyPantalla.func_Pintar_Nave(MyPantalla.MyNavea) # Nave Azul
        MyPantalla.func_Pintar_Navesr() # Naves rojas
        MyPantalla.func_Pintar_Textos(MyTiempo,5,0)

        

        # Todas las operaciones de movimiento
        if finJuego == False: 
            MyPantalla.func_Mover_Navesr()
            MyPantalla.func_Refrescar_Navesr()
            MyTiempo = MyPantalla.MyFuenteTexto.render("Tiempo: "+str(segundos),0,MyPantalla.MyFuenteTexto_txtcolor,MyPantalla.MyFuenteTexto_bckcolor)      
            MyPantalla.func_Pintar_Textos(MyTiempo,5,0)   
            # Condición de fin
            if MyPantalla.func_Controlar_Colisiones() == True:
                finJuego = True
       
        for event in pygame.event.get(): # Recorrer los eventos
            if event.type == pygame.QUIT: # Cerrar ventana
                salir_event = True
                
            # Eventos de teclado
            if event.type == pygame.KEYDOWN:                
                if finJuego == False:
                    MyPantalla.func_Mover_Navea_Keys(MyPantalla.MyNavea.rect,event.key)
                # Controlar el sonio de fondo
                if  event.key== pygame.K_s:
                    if MyPantalla.MyActivarSound_Fondo == False:
                        MyPantalla.MySound_Fondo.play(-1)
                        MyPantalla.MyActivarSound_Fondo = True
                    else    :
                        MyPantalla.MySound_Fondo.stop()
                        MyPantalla.MyActivarSound_Fondo = False
       
    pygame.quit()