예제 #1
0
 def update(self, path, target_pos, bullets_group):
     if self.alive:
         generated_AI = None
         if not self.spawned:
             if self.time_counter >= self.time_trigger:
                 self.time_counter = 0
                 self.init_trigger()
                 self.spawned = True
                 pos = self.rect.center
                 generated_AI = SpawnedAI(pos, target_pos, self)
             else:
                 self.time_counter += 1
         collided = pygame.sprite.spritecollide(self, bullets_group, False)
         if collided:
             self.destroyedSound.play()
             for bullet in collided:
                 bullet.kill()
             self.n_shots += 1
             if self.n_shots == self.max_shots:
                 self.alive = False
             else:
                 self.image = load.image("spawner_dmg{}.png".format(
                     self.n_shots))
     screen = pygame.display.get_surface()
     screen.blit(self.image, self.rect)
     return generated_AI
예제 #2
0
 def update(self,
            path,
            target_pos,
            walls_group,
            pits_group,
            bullets_group,
            in_menu=False):
     if not in_menu:
         # deal with the path the AI must follow
         self.basic_move(path, target_pos)
         # test collisions with other bullets
         collided = pygame.sprite.spritecollide(self.body, bullets_group,
                                                False)
         if collided:  # the AI was shot by a bullet
             for bullet in collided:
                 bullet.kill()
             self.destroyedSound.play()
             self.n_shots += 1
             if self.n_shots == self.max_shots:
                 self.alive = False
             else:
                 self.body.image = load.image(
                     "tank_corps_purple_dmg{}.png".format(self.n_shots))
                 self.body.base_image = self.body.image
     return self.updater_class.update(self, path, target_pos, walls_group,
                                      pits_group, bullets_group, in_menu)
예제 #3
0
 def __init__(self, nlevel=-1, custom=False):
     # nlevel : the identifier of the loaded level. -1 for menus.
     if nlevel == -1 or (nlevel >= 20 and not custom):
         self.image = load.image('background_menu.png')
     else:
         self.image = load.image('background.png')
예제 #4
0
 def __init__(self, path, name, i, j):
     pygame.sprite.Sprite.__init__(self)
     self.rect = pygame.Rect(32 * j, 32 * i, 32, 32)
     self.pos = (j, i)
     self.image = load.image(name)
예제 #5
0
def dead_menu(screen, player, background, walls_group, AI_group, bullets_group,
              all_dead_AI, all_spawners, all_dead_spawners, all_spawned_AI):
    """Dead menu loop."""
    global clickSound
    paused = True
    font1 = get_font(36)
    recommencer = utils.Button("Try Again", font1, 512, 220, (200, 0, 0))
    quitter = utils.Button("Return to Menu", font1, 512, 350, (200, 0, 0))
    font2 = get_font(50)
    you_died = font2.render("You died!", 1, (200, 0, 0))
    you_died_pos = you_died.get_rect(centerx=512, centery=150)
    cursor = Cursor()
    c = pygame.time.Clock()
    deadimg = load.image('tank_destroyed.png')

    while paused:
        c.tick(60)
        screen.blit(background.image, (0, 0))

        cursor.update()

        screen.blit(deadimg, player.body.rect)

        for IA in AI_group:
            screen.blit(IA.body.image, IA.body.rect)
            screen.blit(IA.canon.image, IA.canon.rect)
        for IA in all_dead_AI:
            screen.blit(IA.body.image, IA.body.rect)
        for IA in all_spawners:
            screen.blit(IA.image, IA.rect)
        for IA in all_dead_spawners:
            screen.blit(IA.image, IA.rect)
        for bullet in bullets_group:
            screen.blit(bullet.image, bullet.rect)
        for IA in all_spawned_AI:
            screen.blit(IA.body.image, IA.body.rect)
            screen.blit(IA.canon.image, IA.canon.rect)
        for wall in walls_group:
            screen.blit(wall.image, wall.rect)

        for event in pygame.event.get():
            if (event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and
                    recommencer.hover):
                clickSound.play()
                pygame.mixer.fadeout(200)
                return True
            if (event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and
                    quitter.hover):
                clickSound.play()
                pygame.mixer.music.fadeout(200)
                return False
            if event.type == pygame.QUIT:  # le player choisit de quitter
                clickSound.play()
                pygame.mixer.music.fadeout(200)
                c.tick(5)
                pygame.quit()
                return False
        screen.blit(you_died, you_died_pos)
        recommencer.update()
        quitter.update()
        pygame.display.flip()