Exemplo n.º 1
0
    def __init__(self, player):
        Level.__init__(self, player)

        self.level_limit = -1500

        # Array with width, height, x, and y of platform
        level = [
            [210, 70, 500, 500],
            [210, 70, 800, 400],
            [210, 70, 1000, 500],
            [210, 70, 1120, 280],
        ]

        # Go through the array above and add platforms
        for platform in level:
            block = Platform(platform[0], platform[1])
            block.rect.x = platform[2]
            block.rect.y = platform[3]
            self.level_elements.add(block)

        trampoline = Trampoline()
        trampoline.rect.x = 400
        trampoline.rect.y = GROUND_HEIGHT - 3
        self.level_elements.add(trampoline)

        self.level_elements.add(coins.Coin((400, GROUND_HEIGHT - 100)))
        self.level_elements.add(coins.Coin((800, 350)))
Exemplo n.º 2
0
def create_pipes_and_coins(point, pipes_list, coins_list):
    if pipes_list[-1].rect.left + 202 < 400 and point < 15:
        pipes_list.append(pipes.Pipe([400, 512]))
        coins_list.append(coins.Coin(pipes_list[-1].get_mid_position()))
    elif pipes_list[-1].rect.left + 182 < 400 and 15 <= point < 35:
        pipes_list.append(pipes.Pipe([400, 512]))
        coins_list.append(coins.Coin(pipes_list[-1].get_mid_position()))
    elif pipes_list[-1].rect.left + 152 < 400 and point >= 35:
        pipes_list.append(pipes.Pipe([400, 512]))
        coins_list.append(coins.Coin(pipes_list[-1].get_mid_position()))
Exemplo n.º 3
0
def test_the_coin_constructor_takes_no_arguments():
    """
    Ensure that a developer does not accidentally overwrite the
    coin `value` by providing an argument.

    In other words, we must ensure that __init__ accepts no
    arguments.
    """
    with pytest.raises(TypeError):
        coins.Coin(100)  # Ensure that this isn't possible
Exemplo n.º 4
0
 def spawn_ennemies(self):
     coord = (random.randint(self.last_place, self.last_place + 60), 240)
     self.last_place = coord[0]
     ennemie = random.choice(self.all_ennemie_class)(self, coord,
                                                     self.difficulty)
     self.groupe_ennemies.add(ennemie)
     self.last_place = random.randint(self.last_place + 75,
                                      self.last_place + 120)
     self.all_coins.add(
         coins.Coin(self, (random.randint(
             self.last_place, self.last_place + 300), coord[1] - 10),
                    self.difficulty))
Exemplo n.º 5
0
def main():
    bg_day = Background('sprites/background-day.png', 'sprites/base.png',
                        [0, 0], [0, 512])
    bg_game_over = Background('sprites/game_over.png', 'sprites/game_over.png',
                              [0, 655], [0, 655])
    bgx = 0
    bgx2 = bg_day.image_landscape.get_width()
    score = 0
    point = points.Point([170, 100])
    pipes_list = []
    coins_list = []
    bird = birds.Bird([150, 300])
    pipes_list.append(pipes.Pipe([400, 512]))
    coins_list.append(coins.Coin(pipes_list[-1].get_mid_position()))
    while True:
        score = collision_detection(bird, pipes_list, score, coins_list,
                                    bg_game_over, bg_day)
        create_pipes_and_coins(score, pipes_list, coins_list)
        for ev in pygame.event.get():
            if ev.type == pygame.QUIT:
                pygame.quit()
            elif ev.type == pygame.KEYDOWN:
                if ev.key == pygame.K_SPACE:
                    bird.jump()
                    audio.play_fly()

        screen.fill([255, 255, 255])
        bgx, bgx2 = set_landscape(bgx, bgx2, bg_day)
        draw_coins(coins_list)
        bird.falling()
        draw_pipes(pipes_list)
        bird.update()
        screen.blit(bird.image, [bird.rect.left, bird.rect.top])
        set_base(bgx, bgx2, bg_day)
        point.draw(score, screen)
        pygame.display.update()
        clock.tick(60)