示例#1
0
 def __exit__(self, extype, exception, traceback):
     # Check exception type
     if extype is SystemExit:
         safe_exit()
     # Compute delta
     delta = self.enter_time + self.arg_ms - time.get_ticks()
     # Handle case delta == 0
     delta += not delta
     # Validate delta with sign of the argument
     delta *= self.arg_ms >= 0
     # Return if no need to wait
     if delta < 0:
         return
     # Prepare timer event
     custom_event = pyg.USEREVENT + 1
     clock = time.Clock()
     pyg.event.get()
     time.set_timer(custom_event, delta)
     # Game loop
     while True:
         for ev in pyg.event.get():
             if ev.type == pyg.QUIT or \
               (ev.type == pyg.KEYDOWN and ev.key == pyg.K_ESCAPE):
                 safe_exit()
             if ev.type in [custom_event, pyg.JOYBUTTONDOWN, pyg.KEYDOWN]:
                 time.set_timer(custom_event, 0)
                 return pyg.event.post(ev)
         clock.tick(FPS)
示例#2
0
def Inicio():
    aux = 1

    Initialize()

    LoadContent()

    while True:
        #Creacion de una variable tiempo que se utiliza get_ticks
        #que nos da el tiempo en mili segundos
        Tiempo = pygame.time.get_ticks() / 1000
        #Controla el numero de impreciones del tiempo
        if Tiempo == aux:
            aux += 1
            print(Tiempo)
        #Se crea el texto sobre el tiempo lo cual se lo combierte en str
        contador = Fuente.render('Tiempo : ' + str(Tiempo), 0, (30, 40, 0))
        #Indicamos la posicion del cronometro
        ventana.blit(contador, (120, 30))

        pygame.display.update()
        time = clock.tick(60)

        Updates()

        Draw()

        #if gameOver==True
        #UnLoadContent()

    return
示例#3
0
def main():
   
    Initialize()
   
    LoadContent()
   
    global time
    
    pygame.mixer.music.load("audio/fondo.mp3")
    pygame.mixer.music.play(-1)
     
    
    
    
    while True:
       
        time = clock.tick(60)
       
        
     
        Updates()
       
        Draw()
       
       
       
        #if gameOver==True
        #    pygame.mixer.music.stop()
         
     
       
   
   
    return
示例#4
0
def main():
   
    Initialize()
   
    LoadContent()
   
       
    while True:
       
        time = clock.tick(60)
       
       
     
        Updates()
       
        Draw()
       
       
       
        #if gameOver==True
            #UnLoadContent()
         
     
       
   
   
    return
示例#5
0
def main():

    Initialize()
    LoadContent()

    while True:

        time = clock.tick(60)  #cada 60 milisegundos pausa

        Updates()
        Draw()

    return
示例#6
0
def run():
    pygame.init()    
    screen = pygame.display.set_mode(SCREEN_SIZE, 0,32)
    clock=pygame.time.Clock()
    round=0
    if len(sys.argv)!=1:
        filename= sys.argv[1]
        try:
            with open(filename, 'rb') as in_s:
                try:
                    #char = pickle.load(in_s)
                    #mon = pickle.load(in_s)
                    print "Read data from file"
                    combat=pickle.load(in_s)
                    combat.total=0
                    combat.win=0
                except EOFError:
                    pass
                else:
                    pass#print 'READ: %s (%s)' % (o.name, o.name_backwards)
        except IOError:
            char=Character("Dingziran")
            mon=M1(1)
            combat=CombatSys(char,mon)
    else:
        char=Character("Dingziran")
        mon=M1(1)
        combat=CombatSys(char,mon)
    while True:
        for event in pygame.event.get():
            if event.type ==QUIT:
                with open(filename,'wb') as out_s:
                    pickle.dump(combat,out_s)
                return
        time_passed=clock.tick(30)
        screen.fill((255, 255, 255))
        if round==3:
            round=0
            combat.combat()
        
        combat.render(screen)
        chooseMons(combat,screen)
        pygame.display.update()
        #combat.mons.spawn()
        round+=1
示例#7
0
        gameDisplay.fill(white)
        pygame.draw.line(gameDisplay, black, [650, 650], [display_width, 650])
        pygame.draw.line(gameDisplay, black, [650, 650], [650, display_height])
        printMsg("SAFE ZONE", 660, 660)

        bb.update()

        for enemy in platform.enemies_alive:

            info_str = "Health : " + str(enemy.health)
            printMsg(info_str, enemy.x - 35, enemy.y + 20)
            enemy.render()

        for stockpile in platform.ammo_stockpiles:
            info_str = "Ammo in Stockpile : " + str(stockpile.ammo)
            printMsg(info_str, stockpile.x - 45, stockpile.y - 35)
            stockpile.render()

        player_info = "Ammo : " + str(platform.player.ammo)
        printMsg(player_info, platform.player.x - 20, platform.player.y + 20)
        printMsg("Mode : " + bb.mode, platform.player.x - 20,
                 platform.player.y + 34)
        platform.player.render()

        pygame.display.update()
        clock.tick(60)

    pygame.quit()
    quit()
示例#8
0
def run_game():
    """Main function to run game"""

    # Initialize game and create a screen object
    pygame.init()
    ai_settings = Settings()

    # Set screen width and height
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height),
        pygame.RESIZABLE)
    pygame.display.set_caption("CharLee MacDennis 2: Electric Bugaloo")

    # Make the Play button
    play_button = Button(ai_settings, screen, "Play")

    # Make the Puase button
    pause_button = Button(ai_settings, screen, "Paused")

    # Create an instance to store game statistics
    stats = GameStats(ai_settings)

    # Set stats.high_score to be equal to universal high score
    stats.high_score = gf.read_high_score()

    # Create a scoreboard
    sb = Scoreboard(ai_settings, screen, stats)

    # Make a ship, a group of ship bullets
    ship = Ship(ai_settings, screen)
    ship_bullets = Group()

    # Create alien and group of alien bullets
    aliens = Group()
    alien_bullets = Group()

    # Create the fleet of aliens
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # Create clock for FPS limit
    clock = pygame.time.Clock()

    # Start the main game loop
    while True:
        # 60 fps
        clock.tick(120)

        # Watch for keyboard and mouse events
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, ship_bullets, alien_bullets)

        if stats.game_active:

            # Update ship status
            ship.update()

            # Update all bullets on screen
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              ship_bullets, alien_bullets)

            # Update aliens status
            gf.update_aliens(ai_settings, stats, screen, sb, ship, aliens,
                             ship_bullets, alien_bullets)

        # Draw and refresh the screen
        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens,
                         ship_bullets, alien_bullets, play_button)
示例#9
0
def main():

    ### Initialisation ###
    Logger.info(__name__, "Initialising.... ")
    pygame.init()
    gameDisplay = pygame.display.set_mode((disp_w, disp_h), pygame.FULLSCREEN)
    pygame.mouse.set_visible(False)
    pygame.display.set_caption('Photobooth')
    clock = pygame.time.Clock()

    pictures = PictureList(cfg, picture_basename)

    #pkill -USR1 python
    signal.signal(signal.SIGUSR1, sig_green_handler)
    #pkill -USR2 python
    signal.signal(signal.SIGUSR2, sig_red_handler)

    camera = CameraModule(image_size)
    printer = PrinterModule(cfg)

    intro_ani = IntroAnimation(cfg, gameDisplay, disp_w, disp_h, fps, gpio,
                               pictures)
    capture = Capture(cfg, gameDisplay, disp_w, disp_h, 15, gpio, camera)
    process = Process(cfg, gameDisplay, disp_w, disp_h, fps, gpio, pictures)
    upload = Upload(cfg, gameDisplay, disp_w, disp_h, fps, gpio)
    prin = Prin(cfg, gameDisplay, disp_w, disp_h, fps, gpio, printer)

    #Clean entire tmp_directory
    for f in os.listdir(cfg.get("tmp_dir")):
        f_pth = os.path.join(cfg.get("tmp_dir"), f)
        try:
            if os.path.isfile(f_pth):
                os.unlink(f_pth)
        except:
            pass

    Logger.success(__name__, "Initialisation Complete! ")
    state = "INTRO_S"
    retake = False
    while not state == "END":

        event_list = pygame.event.get()

        if reset_combo(event_list):
            Logger.warning(__name__, "Restarting...")
            intro_ani.stop()
            capture.stop()
            process.stop()
            upload.stop()
            os.execv(sys.executable, ['python'] + sys.argv)

        ### INTRO ANIMATION STATES ###
        if state == "INTRO_S":
            retake = False
            final_photos = {}
            final_link = ""
            final_uploaded = False
            final_printed = False

            intro_ani.start()
            pygame.display.update()
            state = "INTRO"

        if state == "INTRO":
            for event in event_list:
                if event.type == pygame.QUIT:
                    state = "END"
                elif green_press(event):
                    state = "CAPTURE_S"

            intro_ani.next()
            pygame.display.update()

        ### CAPTURE STATES ###
        if state == "CAPTURE_S":
            capture.start(retake)
            pygame.display.update()
            state = "CAPTURE"

        if state == "CAPTURE":
            for event in event_list:
                if event.type == pygame.QUIT:
                    state = "END"

            capture.next()
            pygame.display.update()

            if capture.is_done():
                capture.reset()
                photo_set = capture.cap_path
                photo_set_thumbs = capture.cap_thumbs
                state = "PROCESS_S"

        ### PROCESS STATES ###
        if state == "PROCESS_S":
            process.start(photo_set, photo_set_thumbs)
            pygame.display.update()
            state = "PROCESS"

        if state == "PROCESS":
            for event in event_list:
                if event.type == pygame.QUIT:
                    state = "END"
                elif process.is_done():
                    if green_press(event):
                        final_photos = process.get_result()
                        process.reset()

                        if cfg.get("upload__enabled"):
                            state = "UPLOAD_S"
                        elif cfg.get("printer__enabled"):
                            final_link = cfg.get("event_url")
                            state = "PRINT_S"
                        else:
                            state = "DONE"

                    elif red_press(event):  #Retake
                        process.reset()
                        retake = True
                        state = "CAPTURE_S"
            process.next()
            pygame.display.update()

        ### PRINTER UPLOAD STATES ###
        if state == "UPLOAD_S":
            #Update Photo Upload/ Printer Enable Switch State
            # TODO

            upload.start(final_photos)
            pygame.display.update()
            state = "UPLOAD"

        if state == "UPLOAD":
            for event in event_list:
                if event.type == pygame.QUIT:
                    state = "END"
                elif upload.is_done():
                    final_link = upload.upload_link
                    #TODO upload success
                    if green_press(event):
                        upload.reset()
                        final_uploaded = True

                        if cfg.get("printer__enabled"):
                            state = "PRINT_S"
                        else:
                            state = "DONE"

            upload.next()
            pygame.display.update()

        ### PRINTER UPLOAD STATES ###
        if state == "PRINT_S":
            #Update Photo Upload/ Printer Enable Switch State
            # TODO

            prin.start(final_photos, final_link)
            pygame.display.update()
            state = "PRINT"

        if state == "PRINT":
            for event in event_list:
                if event.type == pygame.QUIT:
                    state = "END"

            if prin.is_done():
                #TODO Get print success value
                prin.reset()
                state = "DONE"
                final_printed = True

            prin.next()
            pygame.display.update()

        if state == "DONE":
            pictures.log_add(final_photos['primary'], final_link,
                             final_uploaded, final_printed)
            state = "INTRO_S"

        if "CAPTURE" in state:
            clock.tick(15)
        else:
            clock.tick(fps)

    pygame.quit()
    quit()
示例#10
0
def main():
    clock = pygame.time.Clock()
    tiempo = 0
    tiempo2 = 0
    pygame.init()  # inicializo el modulo
    fuente1 = pygame.font.SysFont("Arial", 18, True, False)  #crea la fuente
    terminar = False
    tiempo = 0
    tiempo1 = 0
    # fijo las dimensiones de la pantalla a 300,300 y creo una superficie que va ser la principal
    pantalla = pygame.display.set_mode((700, 350))

    pygame.display.set_caption("Mi Ventana")  # Titulo de la Ventana
    # creo un reloj para controlar los fps
    reloj1 = pygame.time.Clock()

    inicio1 = pygame.image.load("inicio1.png")
    inicio2 = pygame.image.load("inicio2.png")
    salir1 = pygame.image.load("salir1.png")
    salir2 = pygame.image.load("salir2.png")
    #DETENER SONIDO

    fondo = pygame.image.load("fondo.jpg")
    #SONIDO

    pygame.mixer.music.load('musica.mp3')
    pygame.mixer.music.play(3)

    # Ubicacion del boton
    boton1 = Boton(inicio1, inicio2, 150, 290)
    boton3 = Boton(salir1, salir2, 350, 290)

    cursor1 = Cursor()

    salir = False
    # LOOP PRINCIPAL
    while salir != True:
        tiempo += 1
        if tiempo == 60:
            tiempo1 += 1
            tiempo = 0
        time = clock.tick(60)
        # recorro todos los eventos producidos
        # en realidad es una lista
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:

                if cursor1.colliderect(boton1.rect):

                    Inicio()

                if cursor1.colliderect(boton3.rect):
                    salir = True
        # pygame.QUIT( cruz de la ventana)
        if event.type == pygame.QUIT:
            salir = True

        if terminar == False:
            segundosint = tiempo2  #toma el tiempo que se esta ejecutando el juego
            segundos = str(segundosint)  #los combierte de numero a string
            transcurre = fuente1.render(
                "TIEMPO: " + segundos, 0,
                pygame.Color('orange'))  #pone el tiempo en un texto
        else:
            transcurre = fuente1.render("TIEMPO: " + segundos, 0,
                                        pygame.Color('orange'))

        reloj1.tick(20)  # operacion para que todo corra a 20fps
        pantalla.blit(fondo, (0, 0))
        cursor1.update()
        boton1.update(pantalla, cursor1)

        boton3.update(pantalla, cursor1)

        pygame.display.update()  # actualizo el display

    pygame.quit()
示例#11
0
def main():

    pygame.init()
    pantalla = pygame.display.set_mode((constantes.ANCHO, constantes.ALTO))
    pygame.display.set_caption("Super-Tortus")
    ico = pygame.image.load("recursos2d/tortu1.png")
    pygame.display.set_icon(ico)
    fondo = cargar_imagen("recursos2d/fondo1.jpg")

    global salto, MposX, MposY, bajada, direc, cont, bajada
    MposX = 700
    MposY = 185
    xixf = {}
    Rxixf = {}
    direc = None
    salto = None
    cont = 6
    direc = True
    i = 0
    bajada = False
    salto = False
    xixf[0] = (0, 0, 60, 123)
    xixf[1] = (66, 0, 75, 123)
    xixf[2] = (141, 0, 75, 123)
    xixf[3] = (219, 0, 60, 123)
    xixf[4] = (279, 0, 81, 123)
    xixf[5] = (360, 0, 81, 123)

    Rxixf[0] = (366, 0, 66, 123)
    Rxixf[1] = (288, 0, 75, 123)
    Rxixf[2] = (222, 0, 66, 123)
    Rxixf[3] = (150, 0, 69, 123)
    Rxixf[4] = (72, 0, 78, 123)
    Rxixf[5] = (0, 0, 75, 123)
    tortuga1 = tortuga.Tortuga()
    tortuga2 = tortuga.Tortuga()
    tortuga3 = tortuga.Tortuga()
    bob1 = bob.Bob()
    bob1.redimensionar(90, 90)
    nume2 = []
    nume2.append(tortuga1.gene())
    nume2.append(tortuga2.gene())
    nume2.append(tortuga3.gene())
    salir = False
    clock = pygame.time.Clock()
    pygame.time.set_timer(USEREVENT + 1, 1000)
    patricio1 = patricio.Patricio()

    while salir != True:
        time = clock.tick(60)
        for event in pygame.event.get():
            if event.type == pygame.QUIT or event.type == pygame.K_ESCAPE:
                salir = True
            if event.type == USEREVENT + 1:

                for number in range(1, 4):
                    if nume2[number - 1] > 0:
                        if number == 1:
                            nume2[number - 1] -= 1
                        if number == 2:
                            nume2[number - 1] -= 1
                        if number == 3:
                            nume2[number - 1] -= 1
        global tortuga1a, tortuga2a, tortuga3a
        tortuga1a = ''
        tortuga2a = ''
        tortuga3a = ''
        for number in range(1, 4):
            if nume2[number - 1] == 1:
                if number == 1:
                    tortuga1.bajar(time)
                    tortuga1a = '1'
                if number == 2:
                    tortuga2.bajar(time)
                    tortuga2a = '1'
                if number == 3:
                    tortuga3.bajar(time)
                    tortuga3a = '1'

            if nume2[number - 1] == 0:
                if number == 1:
                    tortuga1.__init__()
                    nume2[0] = tortuga1.gene()
                    tortuga1a = '0'

                if number == 2:
                    tortuga2.__init__()
                    nume2[1] = tortuga2.gene()
                    tortuga2a = '0'

                if number == 3:
                    tortuga3.__init__()
                    nume2[2] = tortuga3.gene()
                    tortuga3a = '0'

        pantalla.blit(fondo, (0, 0))

        bob1.colocar(pantalla, 170, 210)
        tortuga1.redimensionar(95, 95)
        tortuga2.redimensionar(95, 95)
        tortuga3.redimensionar(95, 95)
        tortuga1.colocar(pantalla, 260, tortuga1.rect.centery)
        tortuga2.colocar(pantalla, 385, tortuga2.rect.centery)
        tortuga3.colocar(pantalla, 510, tortuga3.rect.centery)

        teclado = pygame.key.get_pressed()

        if teclado[K_UP]:
            salto = True

        if teclado[K_RIGHT]:
            MposX += 3
            cont += 1
            direc = True
        elif teclado[K_LEFT]:
            MposX -= 3
            cont += 1
            direc = False
        else:
            cont = 6

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

        global salto_Par, bajada_Par

        if direc == True and salto == False:
            pantalla.blit(patricio1.ImagenPatricio, (MposX, MposY), (xixf[i]))

        if direc == False and salto == False:
            pantalla.blit(patricio1.ImagenPatricio_inv, (MposX, MposY),
                          (Rxixf[i]))

        if salto == True:

            if direc == True:
                pantalla.blit(patricio1.ImagenPatricio, (MposX, MposY),
                              (xixf[4]))
            if direc == False:
                pantalla.blit(patricio1.ImagenPatricio_inv, (MposX, MposY),
                              (Rxixf[4]))

            if bajada == False:
                MposY -= 4

            if bajada == True:
                MposY += 4

            if MposY <= 110:
                bajada = True

            if MposY >= 185:
                bajada = False
                salto = False

        if 150 <= MposX <= 190:
            Ganar('')
        if 205 <= MposX <= 305:
            if MposY == 185:
                if tortuga1a == '1':
                    gameover('')

        if 305 <= MposX <= 330:
            if MposY == 185:
                gameover('')

        if 330 <= MposX <= 430:
            if MposY == 185:
                if tortuga2a == '1':
                    gameover('')

        if 430 <= MposX <= 465:
            if MposY == 185:
                gameover('')

        if 465 <= MposX <= 555:
            if MposY == 185:
                if tortuga3a == '1':
                    gameover('')

        pygame.display.flip()

    pygame.quit()