Пример #1
0
def main():
    """The mainloop which is specified in the activity.py file
    
    "main" is the assumed function name
    """
    size = (800,600)
    if olpcgames.ACTIVITY:
        size = olpcgames.ACTIVITY.game_size
    screen = pygame.display.set_mode(size)
    
    clock = pygame.time.Clock()

    running = True
    while running:
        screen.fill( (0,0,128))
        milliseconds = clock.tick(25) # maximum number of frames per second
        
        # Event-management loop with support for pausing after X seconds (20 here)
        events = pausescreen.get_events()
        # Now the main event-processing loop
        if events:
            for event in events:
                log.debug( "Event: %s", event )
                if event.type == pygame.QUIT:
                    running = False
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        running = False
            pygame.display.flip()
Пример #2
0
 def process_events(self):
     #events = pygame.event.get()
     events = pausescreen.get_events()
     if events:
         for event in events:
             if event.type == pygame.QUIT:
                 self.running = False
             elif event.type == pygame.KEYDOWN:
                 if event.key == pygame.K_ESCAPE:
                     self.running = False
             elif event.type == pygame.MOUSEBUTTONUP:
                 if event.button == 1:
                     if self.btn_jugar.is_over():
                         self.starting_game = True
                     elif self.btn_jugar_mac.is_over():
                         self.starting_mac_game = True
                     elif self.btn_jugar_red.is_over():
                         self.starting_net_game = True
                     elif self.btn_salir.is_over():
                         self.running = False
                     elif self.btn_creditos.is_over():
                         self.starting_creditos = True
                     elif self.btn_ayuda.is_over():
                         self.starting_ayuda = True
             elif self.conn.process_event(event):
                 self.update_conn_dependents()
Пример #3
0
def main():
    """The mainloop which is specified in the activity.py file
    
    "main" is the assumed function name
    """
    size = (800, 600)
    if olpcgames.ACTIVITY:
        size = olpcgames.ACTIVITY.game_size
    screen = pygame.display.set_mode(size)

    clock = pygame.time.Clock()

    running = True
    while running:
        screen.fill((0, 0, 128))
        milliseconds = clock.tick(25)  # maximum number of frames per second

        # Event-management loop with support for pausing after X seconds (20 here)
        events = pausescreen.get_events()
        # Now the main event-processing loop
        if events:
            for event in events:
                log.debug("Event: %s", event)
                if event.type == pygame.QUIT:
                    running = False
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        running = False
            pygame.display.flip()
Пример #4
0
 def runloop(self):
     "main game loop"
     clock = pygame.time.Clock()
     imgcnt = 0
     self.music_player.playLoop(now())
     while self.running:
         events = (pausescreen.get_events(sleep_timeout=43200)
                   if platform == 'Sugar' else pygame.event.get())
         for event in events:
             self.eventAction(event)
         for act in self.keyActions:
             self.interfaceAction(act)
         if self.feedbackgroundImage:
             self.setbackgroundImage(self.feedbackgroundImage)
             self.feedbackgroundImage = None
         self.updateInspos()
         self.updatePanel()
         if platform == 'Sugar': currentcnt = len(self.snap_store)
         else: currentcnt = 0
         if imgcnt == currentcnt:
             pass
         else:
             self.music_player.picture_cycle = [self, True]
             imgcnt = currentcnt
         pygame.display.flip()
         clock.tick(25)
Пример #5
0
    def run(self):
        clock = pygame.time.Clock()
        while True:
            milliseconds = clock.tick(25) # maximum number of frames per second
            # Event-management loop with support for pausing after X seconds (20 here)
            events = pausescreen.get_events(sleep_timeout=60)
		    # Now the main event-processing loop
            if events:
                for event in events:
                    self.__warn(event)
            pygame.display.update()
Пример #6
0
 def run(self):
     clock = pygame.time.Clock()
     while True:
         milliseconds = clock.tick(
             25)  # maximum number of frames per second
         # Event-management loop with support for pausing after X seconds (20 here)
         events = pausescreen.get_events(sleep_timeout=60)
         # Now the main event-processing loop
         if events:
             for event in events:
                 self.__warn(event)
         pygame.display.update()
Пример #7
0
def mostrarImagen(imagen, duracion):
    screen.blit(imagen, imagen.get_rect(center=screen.get_rect().center))
    ticks_final = pygame.time.get_ticks() + duracion * 1000

    while pygame.time.get_ticks() < ticks_final:
        for e in pausescreen.get_events(config.DEMORA_PAUSA):
            if e.type == KEYDOWN:
                if e.key in [K_ESCAPE, K_SPACE, K_RETURN]:
                    sonido_menu.play()
                    return
        pygame.display.flip()
        clock.tick(10)
Пример #8
0
 def run(self):
     self.salir = False
     while not self.salir:
         for e in pausescreen.get_events(config.DEMORA_PAUSA):
             if e.type == QUIT:
                 salir = True
             if e.type == KEYDOWN:
                 if e.key in [K_UP, K_KP8]:
                     self.moverSeleccion(-1)
                 elif e.key in [K_DOWN, K_KP2]:
                     self.moverSeleccion(1)
                 elif e.key in [K_RETURN, K_KP7, K_KP1, K_KP3, K_KP9]:
                     sonido_menu.play()
                     titulo, funcion = self.opciones[self.seleccionado]
                     funcion()
                     self.actualizar()
                     break
         pygame.display.flip()
         clock.tick(10)
Пример #9
0
    def process_events(self):
        #events = pygame.event.get()
        events = pausescreen.get_events()
        for event in events:
            #log.debug("Event: %s", event)
            if event.type == pygame.QUIT:
                self.stop()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    self.stop()
            elif event.type == pygame.MOUSEBUTTONUP:
                if event.button == 1:
                    self.mouse_button_up()
            elif event.type == self.TIMER_SHOW_CARDS_MIN_EVENT:
                pygame.time.set_timer(self.TIMER_SHOW_CARDS_MIN_EVENT, 0)
                self._showing_cards_min = True
            elif event.type == self.TIMER_SHOW_CARDS_EVENT:
                pygame.time.set_timer(self.TIMER_SHOW_CARDS_EVENT, 0)
                self.finish_show_cards()
            elif event.type == self.TIMER_MACHINE_OPEN_CARDS_EVENT:
                pygame.time.set_timer(self.TIMER_MACHINE_OPEN_CARDS_EVENT, 0)

                ## Machine open cards
                self.open_cards()
                #Timer callback for computer player to choose attribute
                pygame.time.set_timer(
                    self.TIMER_MACHINE_SELECT_ATTRIBUTE_EVENT,
                    self.TIME_MACHINE_SELECT_ATTRIBUTE)
            elif event.type == self.TIMER_MACHINE_SELECT_ATTRIBUTE_EVENT:
                pygame.time.set_timer(
                    self.TIMER_MACHINE_SELECT_ATTRIBUTE_EVENT, 0)

                ## Machine select attribute
                self.op_card.choose_attribute(
                    random.randint(0,
                                   len(self.op_card.btn_atrs) - 1))
                self.attribute_selected(self.op_card.chosen_attribute)
            elif event.type == self.TIMER_SHOW_WINNER_EVENT:
                pygame.time.set_timer(self.TIMER_SHOW_WINNER_EVENT, 0)
                self.end()
            elif self.conn.process_event(event):
                self.update_conn_dependents()
Пример #10
0
def main(language="bra"):
    import paladict
    dic = paladict.PalaDict(language)

    global display
    display = Display(
        area_barra.subsurface((50, 50), (screen_width - 100, 100)))
    global estado
    estado = Estado(dic)
    #Comienza el juego
    playing = True
    clock = pygame.time.Clock()

    #musica.play(-1)

    while playing:
        clock.tick(20)
        for event in pausescreen.get_events(DEMORA_PAUSA):
            if event.type == QUIT:
                playing = False
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    playing = False
                elif event.key in [K_UP, K_KP8, K_KP9]:
                    estado.grossini.mirar("arriba")
                elif event.key in [K_DOWN, K_KP2, K_KP3]:
                    estado.grossini.mirar("abajo")
                elif event.key in [K_LEFT, K_KP4, K_KP7]:
                    estado.grossini.mirar("izquierda")
                elif event.key in [K_RIGHT, K_KP6, K_KP1]:
                    estado.grossini.mirar("derecha")
        try:
            estado.step()
        except EndOfGame, e:
            e.accion()
            break

        estado.dibujar(playing_area)
        pygame.display.flip()
Пример #11
0
    def run(self):
        """Run the main loop of the game."""
        # lets draw once before we enter the event loop
        self.draw()
        pygame.display.flip()
        clock = pygame.time.Clock()

        while self.running:
            a, b, c, d = pygame.cursors.load_xbm('my_cursor.xbm',
                                                 'my_cursor_mask.xbm')
            pygame.mouse.set_cursor(a, b, c, d)
            self.frame += 1
            # process all queued events
            for event in pausescreen.get_events(sleep_timeout=30):
                self.processEvent(event)

            self.animate()
            self.draw()

            pygame.display.flip()
            # don't animate faster than about 20 frames per second
            # this keeps the speed reasonable and limits cpu usage
            clock.tick(20)
Пример #12
0
    def run(self):
        """Run the main loop of the game."""
        # lets draw once before we enter the event loop

        clock = pygame.time.Clock()
        pygame.display.flip()

        while self.running:
            clock.tick(25)

            a, b, c, d = pygame.cursors.load_xbm("my_cursor.xbm", "my_cursor_mask.xbm")
            pygame.mouse.set_cursor(a, b, c, d)
            self.frame += 1
            # process all queued events
            for event in pausescreen.get_events(sleep_timeout=30):
                self.processEvent(event)

            self.animate()
            self.draw()

            pygame.display.update()
            # don't animate faster than about 20 frames per second
            # this keeps the speed reasonable and limits cpu usage
            clock.tick(25)
Пример #13
0
def main():
    """The mainlook which is specified in the activity.py file
    
    "main" is the assumed function name"""
    bullets = []
    enemys = []
    sp = 10 # The speed of the player
    
    pygame.mixer.init(frequency=44100, size=-16, channels=2, buffer=4096)
    size = (800,600)
    if olpcgames.ACTIVITY:
        size = olpcgames.ACTIVITY.game_size
    screen = pygame.display.set_mode(size)
    background = pygame.image.load(os.path.join('data', 'spacesmall.png'))
    # Create an 800x600 sized screen
    
#    text = Player(
#        text = "Hello Children of the World",
#        color = (255,255,255),
#        size = 20,
#    )
    lasercannon = LaserCannon(bullets, offset = (-20, 0))
        
    group = pygame.sprite.OrderedUpdates()
    player = FlyingSaucer(lasercannon)
    opponent = TheOpponent(enemys, group, lasercannon.bulletgroup, player)
    player.opponent_bulletgroup = opponent.opponent_bulletgroup
    group.add(player)
    group.add(lasercannon)

    clock = pygame.time.Clock()

    running = True
    while running:
        screen.blit(background, (0, 0))
#        milliseconds = clock.tick(100) # maximum number of frames per second
        #MESS WITH THIS^^^^^^^^^^^^^^^
        # Event-management loop with support for pausing after X seconds (20 here)
        events = pausescreen.get_events()
        clock.tick(25)
        # Now the main event-processing loop
        if events:
            for event in events:
                log.debug( "Event: %s", event )
                if event.type == pygame.QUIT:
                    running = False

                elif event.type == pygame.KEYDOWN:
                    if keys(event, 'escape'):
                        running = False
                    if keys(event, 'left'):
                        player.changespeed(-sp,0)
                    if keys(event, 'right'):
                        player.changespeed(sp,0)
                    if keys(event, 'up'):
                        player.changespeed(0,-sp)
                    if keys(event, 'down'):
                        player.changespeed(0,sp)
                    if keys(event, 'space'):
                        player.shoot()
                    if event.key == pygame.K_KP3 or event.key == pygame.K_s:
                        opponent.spawn_badguys((400, 400), 9, 800, 100)

                elif event.type == pygame.KEYUP:
                    if keys(event, 'left'):
                        player.changespeed(sp,0)
                    if keys(event, 'right'):
                        player.changespeed(-sp,0)
                    if keys(event, 'up'):
                        player.changespeed(0,sp)
                    if keys(event, 'down'):
                        player.changespeed(0,-sp)
        group.update()
        lasercannon.update()
        lasercannon.bulletgroup.draw(screen)
        group.draw( screen )
        opponent.update()
        opponent.opponent_bulletgroup.draw(screen)
        pygame.display.flip()
#        clock.tick(500)

    pygame.quit()
Пример #14
0
 def run(self):
     running = True
     while running:
         milliseconds = self.clock.tick(25) # maximum number of frames per second
         
         # Event-management loop with support for pausing after X seconds (20 here)
         events = pausescreen.get_events()
         # Now the main event-processing loop
         if events:
             for event in events:
                 log.debug( "Event: %s", event )
                 if event.type == pygame.QUIT:
                     running = False
                 elif event.type == pygame.KEYDOWN:
                     if event.key == pygame.K_ESCAPE:
                         running = False
                 elif event.type == pygame.MOUSEBUTTONDOWN:
                     if event.button == 1:
                         # Si no estaba jugando, conecto y comienzo
                         if self.estoyConectado and self.hayAmigo and not self.jugando:
                              # inicio juego
                             self.iniciarJuego(True, None)
                 elif event.type==mesh.CONNECT :
                     log.debug("CONNECT")
                     self.estoyConectado = True
                     if mesh.is_initiating():
                         self.miJugador = 1 # Cruz
                     else:
                         self.miJugador = -1 # Circulo
                 elif event.type==mesh.PARTICIPANT_ADD:
                     log.debug("PARTICIPANT_ADD")
                     # Si no soy yo
                     if event.handle <> mesh.my_handle():
                         self.hayAmigo = True
                         self.handleAmigo = event.handle
                         
                         # Si soy el servidor comienzo el primer juego
                         if mesh.is_initiating():
                             self.iniciarJuego(True, None)
                 elif event.type==mesh.PARTICIPANT_REMOVE:
                     log.debug("PARTICIPANT_REMOVE")
                 elif event.type==mesh.MESSAGE_MULTI:
                     log.debug("MESSAGE_MULTI")
                 elif event.type==mesh.MESSAGE_UNI:
                     log.debug("MESSAGE_UNI: " + event.content)
                     toks = event.content.split(':')
                     if toks[0] == 'configJugadores':
                          # inicio juego
                         self.iniciarJuego(False, toks[1] == 'True')
                     elif toks[0] == 'registroJugada':
                         jugada = int(toks[1])
                         self.juego.registroJugada(jugada, self.miJugador)
                         self.miTurno = True
                         self.jugadas += 1
                         self.evaluarJuego()
             			#juego.printResult("Empate")
             			#Fin chequeo de ganador
 
             pygame.display.flip()
             
         # Tomamos acciones
         
         if self.jugando and self.miTurno:
             jugada = self.juego.playMe(self.miJugador)
             self.miTurno = False
             self.jugadas += 1
             mesh.send_to(self.handleAmigo, "registroJugada:" + str(jugada))
             self.evaluarJuego()