Cargando

  • 1 Min To Read
  • 01 Jan, 0001
    Índice de contenido

    romper resultado devuelto def _display_message(yo, mensaje): """ Muestra un mensaje al usuario en la pantalla """ fuente_texto = pygame.font.Font(‘freesansbold.ttf’, 48) text_surface = text_font.render(mensaje, Verdadero, AZUL, BLANCO) rectángulo_texto = superficie_texto.get_rect() text_rectangle.center = (DISPLAY_WIDTH / 2, PANTALLA_ALTURA / 2) self.display_surface.fill(BLANCO) self.display_surface.blit(text_surface, text_rectangle) def _pause(auto): en pausa = Verdadero mientras está en pausa: para evento en pygame.event.get(): if event.type == pygame.KEYDOWN: si evento.clave == pygame.K_p: en pausa = Falso romper def jugar (uno mismo): is_running = Verdadero starship_collided = Falso cuenta_de_ciclos = 0

    Juego principal jugando Loop

    while is_running and not starship_collided:

    Indica cuántas veces se ha repetido el bucle principal del juego.

    ha sido ejecutado cuenta_de_ciclos += 1

    Ver si el jugador ha ganado

    if ciclo_recuento == MAX_NUMBER_OF_CYCLES: self._display_message(’¡GANADOR!’) romper

    Averiguar lo que el usuario quiere hacer

    para evento en pygame.event.get(): if event.type == pygame.QUIT: is_running = Falso elif event.type == pygame.KEYDOWN:

    Comprobar para ver qué tecla se presiona

    si evento.key == pygame.K_RIGHT:

    Se ha presionado la tecla de flecha derecha

    mover al jugador a la derecha

    self.nave estelar.mover_derecha() elif evento.key == pygame.K_LEFT:

    Se ha presionado la flecha izquierda

    160 13 Pygame StarshipMeteors

    comments powered by Disqus