Exemplo n.º 1
0
def update():
    global running
    global window
    global clock

    mouseup = False

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        if event.type == pygame.MOUSEBUTTONDOWN:
            mouseup = True
            mouse.down = True

        if not mouseup:
            mouse.down = False

        if event.type == pygame.MOUSEMOTION:
            mouse.x = pygame.mouse.get_pos()[0]
            mouse.y = pygame.mouse.get_pos()[1]

    clock.tick(60)

    drawer.draw(assets.background_image, 0, 0)
    keyboard.update()

    board.update()

    pygame.display.flip()

    if turnmanager.won:
        os.system("say 'Closing the window in 5 seconds'")
        time.sleep(5)
        exit(0)
Exemplo n.º 2
0
 def run(self):
     '''
     Función que contiene el bucle principal del juego.
     Actualiza y dibuja el estado actual.
     '''
     while not keyboard.quit():
         
         self.clock.tick(self.fps)
         
         keyboard.update()
         
         self.button.update()
         self.button2.update()
         self.button3.update()
         
         self.screen.fill(THECOLORS['white'])
         
         self.button.draw(self.screen)
         self.button2.draw(self.screen)
         self.button3.draw(self.screen)
         
         #self.__actual_state.update()
         #self.__actual_state.draw(screen)
         
         pygame.display.flip()
Exemplo n.º 3
0
    def run(self):
        '''
        @brief Función que contiene el bucle principal del juego. Actualiza y dibuja el estado actual.
        '''

        #Mientras no cerremos la pantalla
        while not keyboard.quit():

            self.clock.tick(self.fps)

            #Actualizamos el teclado
            keyboard.update()
            mouse.update()

            #Ponemos la pantalla a negro completamente
            self.screen.fill(pygame.color.THECOLORS['black'])

            #Actualizamos y dibujamos el estado actual
            self.__actual_state.update()
            self.__actual_state.draw(self.screen)

            fps = self.clock.get_fps()

            render_fps = self.font.render(str(round(fps, 2)), True, (0, 0, 0))

            self.screen.blit(render_fps, (730, 565))

            #Actualizamos la pantalla
            pygame.display.flip()
Exemplo n.º 4
0
 def run(self):
     '''
     Función que contiene el bucle principal del juego.
     Actualiza y dibuja el estado actual.
     '''
     while not keyboard.quit():
         
         self.clock.tick(self.fps)
         
         keyboard.update()
         
         self.screen.fill((0,0,0))
         
         #self.__actual_state.update()
         #self.__actual_state.draw(screen)
         
         if keyboard.pressed(K_DOWN):
             self.circuit.move(0, self.circuit.get_y() + 50)
         elif keyboard.pressed(K_UP):
             self.circuit.move(0, self.circuit.get_y() - 50)
         
         self.circuit.draw(self.screen, 0)
         self.circuit.draw(self.screen, 1)
         self.circuit.draw(self.screen, 2)
         
         
         pygame.display.flip()
Exemplo n.º 5
0
 def run(self):
     '''
     Función que contiene el bucle principal del juego.
     Actualiza y dibuja el estado actual.
     '''
     while not keyboard.quit():
         
         self.clock.tick(self.fps)
         
         keyboard.update()
         
         self.screen.fill((0,0,0))
         
         #self.__actual_state.update()
         #self.__actual_state.draw(screen)
         
         if keyboard.pressed(K_DOWN):
             if self.circuit.get_y() < self.circuit.get_tile_height() * self.circuit.get_height() - self.screen.get_height():
                 self.circuit.move(self.circuit.get_x(), self.circuit.get_y() + 25)
         elif keyboard.pressed(K_UP):
             if self.circuit.get_y() > 0:
                 self.circuit.move(self.circuit.get_x(), self.circuit.get_y() - 25)
         if keyboard.pressed(K_LEFT):
             if self.circuit.get_x() > 0:
                 self.circuit.move(self.circuit.get_x() - 25, self.circuit.get_y())
         elif keyboard.pressed(K_RIGHT):
             if self.circuit.get_x() < self.circuit.get_tile_width() * self.circuit.get_width() - self.screen.get_width():
                 self.circuit.move(self.circuit.get_x() + 25, self.circuit.get_y())
         
         self.circuit.draw(self.screen, 0)
         self.circuit.draw(self.screen, 1)
         self.circuit.draw(self.screen, 2)
         
         
         pygame.display.flip()
Exemplo n.º 6
0
    def run(self):
        '''
        @brief Función que contiene el bucle principal del juego. Actualiza y dibuja el estado actual.
        '''
        
        #Mientras no cerremos la pantalla
        while not keyboard.quit():
            
            self.clock.tick(self.fps)
            
            #Actualizamos el teclado
            keyboard.update()
            mouse.update()
            
            #Ponemos la pantalla a negro completamente
            self.screen.fill(pygame.color.THECOLORS['black'])
            
            #Actualizamos y dibujamos el estado actual
            self.__actual_state.update()
            self.__actual_state.draw(self.screen)
            
            fps = self.clock.get_fps()
            
            render_fps = self.font.render(str(round(fps, 2)), True, (0, 0, 0))

            self.screen.blit(render_fps, (730, 565))
            
            #Actualizamos la pantalla
            pygame.display.flip()
Exemplo n.º 7
0
    def run(self):
        '''
        Función que contiene el bucle principal del juego.
        Actualiza y dibuja el estado actual.
        '''
        while not keyboard.quit():
            
            self.clock.tick(self.fps)
            
            keyboard.update()
            
            self.screen.fill((0,0,0))
            
            ######PRUEBA MODULO GAME CONTROL##########
            
            self.__actual_state.update()
            self.__actual_state.draw(self.screen)
            
            fps = self.clock.get_fps()
            
            render_fps = self.font.render(str(round(fps, 2)), True, (0,0,0))

            self.screen.blit(render_fps, (730, 565))
            
            pygame.display.flip()
Exemplo n.º 8
0
 def __init__(self):
     '''
     Carga e inicializa la configuración principal y las variables principales de la clase
     '''
     os.environ["SDL_VIDEO_CENTERED"] = "1"
     
     parser = xml.dom.minidom.parse(data.get_path_xml('configuration.xml'))
     
     for element in parser.getElementsByTagName('screen'):
         self.__screen_width = int(element.getAttribute('width'))
         self.__screen_height = int(element.getAttribute('height'))
         self.caption = element.getAttribute('caption')
     
     for element in parser.getElementsByTagName('fps'):
         self.fps = int(element.getAttribute('value'))
     
     pygame.init()
     self.screen = pygame.display.set_mode((self.__screen_width, self.__screen_height))
     
     for element in parser.getElementsByTagName('icon'):
         icon_code = str(element.getAttribute('code'))
         self.icon = resource.get_image(icon_code)
         
     pygame.mouse.set_visible(False)
     pygame.display.set_icon(self.icon)
     
     self.clock = pygame.time.Clock()
     self.font = resource.get_font('cheesebu', 30)
     keyboard.update()
     
     ######PRUEBA MODULO GAME CONTROL##########
     self.__actual_state = gamecontrol.GameControl(self, 'circuits/circuit1-beach.tmx')
Exemplo n.º 9
0
 def run(self):
     '''
     Función que contiene el bucle principal del juego.
     Actualiza y dibuja el estado actual.
     '''
     while not keyboard.quit():
         
         self.clock.tick(self.fps)
         
         keyboard.update()
         
         self.screen.fill((255,255,255))
         
         if not self.__actual_state.complete():
             self.__actual_state.update()
             self.__actual_state.draw(self.screen)
         
         pygame.display.flip()
Exemplo n.º 10
0
    def run(self):
        """
        Función que contiene el bucle principal del juego.
        Actualiza y dibuja el estado actual.
        """
        while not keyboard.quit():

            self.clock.tick(self.fps)

            keyboard.update()
            mouse.update()

            self.screen.fill((0, 0, 0))

            if mouse.newpressed(mouse.LEFT):
                print "Presiona nuevo izquierda"
            elif mouse.pressed(mouse.LEFT):
                print "Aun presionando izquierdaaaa"
            elif mouse.release(mouse.LEFT):
                print "Soltando izquierda"

            if mouse.newpressed(mouse.CENTER):
                print "Presiona nuevo centro"
            elif mouse.pressed(mouse.CENTER):
                print "Aun presionando centro"
            elif mouse.release(mouse.CENTER):
                print "Soltando centro"

            if mouse.newpressed(mouse.RIGHT):
                print "Presiona nuevo derecha"
            elif mouse.pressed(mouse.RIGHT):
                print "Aun presionando derecha"
            elif mouse.release(mouse.RIGHT):
                print "Soltando derecha"

            print mouse.position()

            # self.__actual_state.update()
            # self.__actual_state.draw(screen)

            pygame.display.flip()
Exemplo n.º 11
0
 def run(self):
     '''
     Función que contiene el bucle principal del juego.
     Actualiza y dibuja el estado actual.
     '''
     while not keyboard.quit():
         
         self.clock.tick(self.fps)
         
         keyboard.update()
         
         if keyboard.pressed(K_UP) or self.__actual_state.get_status() == 'done':
             print "pulsandooo"
             #self.__actual_state = particle.SystemParticle(400, 300, ['particle', 'particle2'], 100, 1, 10, 300, 1)
             self.__actual_state.restart()
                 
         self.screen.fill((255,255,255))
         
         self.__actual_state.update()
         self.__actual_state.draw(self.screen)
         
         pygame.display.flip()
Exemplo n.º 12
0
 def run(self):
     '''
     Función que contiene el bucle principal del juego.
     Actualiza y dibuja el estado actual.
     '''
     while not keyboard.quit():
         
         self.clock.tick(self.fps)
         
         keyboard.update()
         
         for button in self.buttons:
             button.update()
             if button.get_selected() and pygame.mouse.get_pressed()[0]:
                 self.treat_option(button.get_option())
         
         self.timer.update()
         self.timer2.update()
         self.timer3.update()
         
         self.screen.fill(THECOLORS['white'])
         
         for button in self.buttons:
             button.draw(self.screen)
             
         self.timer.draw(self.screen)
         self.timer2.draw(self.screen)
         self.timer3.draw(self.screen)
         #self.__actual_state.update()
         #self.__actual_state.draw(screen)
         
         if self.__start and time.time() - self.__start >= 5:
             self.__start = time.time()
             if self.timer2.less_than(self.timer):
                 self.timer2.assign(self.timer)
             elif self.timer2.more_than(self.timer):
                 print "Es mayoooor"
         
         pygame.display.flip()
Exemplo n.º 13
0
    def run(self):
        """
        @brief Función que contiene el bucle principal del juego. Actualiza y dibuja el estado actual.
        """

        # Mientras no cerremos la pantalla
        while not keyboard.quit():

            self.clock.tick(self.fps)

            # Actualizamos el teclado
            keyboard.update()
            mouse.update()

            # Ponemos la pantalla a negro completamente
            self.screen.fill(THECOLORS["black"])

            # Actualizamos y dibujamos el estado actual
            self.__actual_state.update()
            self.__actual_state.draw(self.screen)

            # Actualizamos la pantalla
            pygame.display.flip()
Exemplo n.º 14
0
    def run(self):
        '''
        Función que contiene el bucle principal del juego.
        Actualiza y dibuja el estado actual.
        '''
        while not keyboard.quit():
            
            self.clock.tick(self.fps)
            
            keyboard.update()
            
            self.screen.fill((0,0,0))
            
            ######PRUEBA MODULO PLAYER CAR##########

            self.car.update()
            #self.car2.update()
            self.car.draw(self.screen)
            #self.car2.draw(self.screen)
            
            #self.__actual_state.update()
            #self.__actual_state.draw(screen)
            
            pygame.display.flip()
Exemplo n.º 15
0
def update():
    global running
    global window
    global p
    global small_text
    global score_text
    global health_text
    global lost
    global in_store
    global potential_purchases
    global count
    global purchase_count

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.USEREVENT + 1:
            sound_player.music()

    clock.tick(config.FPS)

    keyboard.update()

    count += 1
    if keyboard.is_key_down(pygame.K_s) and count > 30 and not lost:
        count = 0
        in_store = not in_store

    if in_store:
        alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]
        key_linker = {
            "a": pygame.K_a,
            "b": pygame.K_b,
            "c": pygame.K_c,
            "d": pygame.K_d,
            "e": pygame.K_e,
            "f": pygame.K_f,
            "g": pygame.K_g,
            "h": pygame.K_h,
            "i": pygame.K_i,
            "j": pygame.K_j,
            "k": pygame.K_k
        }
        potential_purchases = [w for w in weapon.weapons if w not in p.weapons]

        purchase_count += 1
        if keyboard.is_key_down(
                pygame.K_z
        ) and p.health < 42 and scorekeeper.points >= 10 and purchase_count > 30:
            # purchase health
            p.health += 3
            scorekeeper.points -= 10
            if p.health > 42:
                p.health = 42
            purchase_count = 0

        cthing = 0
        window.blit(assets.background_image, (0, 0))
        tiny_text = pygame.font.Font("freesansbold.ttf", 24)

        for purchase in potential_purchases:
            if keyboard.is_key_down(key_linker[alphabet[cthing]]) \
                    and scorekeeper.points >= purchase.cost and purchase_count > 30:
                p.weapons.append(purchase)
                scorekeeper.points -= purchase.cost
                purchase_count = 0

            img = tiny_text.render(
                "Press " + alphabet[cthing] + " to purchase " + purchase.name +
                " for " + str(purchase.cost) + " points", False,
                (0, 255, 0) if purchase.cost <= scorekeeper.points else
                (255, 0, 0))
            window.blit(img, (0, cthing * 40))
            cthing += 1
        img = tiny_text.render("Press z to repair by 3 health for 10 points",
                               False,
                               ((0, 255, 0) if scorekeeper.points > 10 else
                                (255, 0, 0)))
        window.blit(img, (0, cthing * 40))
        pygame.display.flip()
        return

    entitymanager.update(window)

    enemy.update()

    if lost and keyboard.is_key_down(pygame.K_r):
        entitymanager.entities = []
        lost = False
        init()
        scorekeeper.points = 0

    if enemy.Enemy.bullet_type_change > 60 and random.randint(0, 300) == 0:
        enemy.Enemy.bullet_type_change -= 1

    image2 = small_text.render("Points: " + str(scorekeeper.points), False,
                               (255, 0, 0))
    if score_text is not None:
        score_text.kill()
    score_text = entity.ConcreteEntity(image2, 0, 0, float("inf"))

    image3 = small_text.render(
        "Health: " + (str(p.health) if p is not None else "0"), False,
        (255, 0, 0))
    if health_text is not None:
        health_text.kill()
    health_text = entity.ConcreteEntity(image3, 0, 38, float("inf"))

    pygame.display.flip()

    if p not in entitymanager.entities and not lost:  # you lose
        large_text = pygame.font.Font('freesansbold.ttf', 115)
        image = large_text.render("YOU LOSE", False, (255, 0, 0))
        entity.ConcreteEntity(image, config.WIDTH / 2 - image.get_width() / 2,
                              config.HEIGHT / 2 - image.get_height() / 2,
                              float("inf"))
        otherthing = small_text.render("Press R to retry", False, (0, 0, 255))
        entity.ConcreteEntity(
            otherthing, config.WIDTH / 2 - otherthing.get_width() / 2,
            config.HEIGHT / 2 - otherthing.get_height() / 2 + 70, float("inf"))

        highscores = open(os.path.join(__location__, "scores.dat"))
        scores = highscores.read().split(";")
        biggest = 0
        for sc in scores:
            if int(sc) > biggest:
                biggest = int(sc)

        last_thing = small_text.render(
            "You got a HIGHSCORE of: " + str(scorekeeper.cumulated) +
            "." if scorekeeper.cumulated > biggest else "Highscore is " +
            str(biggest) + "; you did not beat it.", False, (0, 0, 255))
        entity.ConcreteEntity(
            last_thing, config.WIDTH / 2 - last_thing.get_width() / 2,
            config.HEIGHT / 2 - last_thing.get_height() / 2 + 110,
            float("inf"))

        highscores.close()

        new_file = open(os.path.join(__location__, "scores.dat"), "a")
        new_file.write(";" + str(scorekeeper.cumulated))

        p = None
        lost = True

    if keyboard.is_key_down(pygame.K_ESCAPE):
        running = False