Пример #1
0
    def update(self,dt):
        """Function which is used evry frame"""
        
        self.build_score_board()
        if self.flapped:
            arcade.play_sound(SOUNDS['wing'], 0.5)
            self.bird.flap()
            self.flapped = False

        # Check if bird is too high
        if self.bird.top > self.height:
            self.bird.top = self.height

        # Check if bird is too low
        if self.bird.bottom <= 0:
            self.bird.bottom = 0
        
        self.dx += PIPE_SPEED # how much pixels pipes move from last adding pipe 
        if self.dx > random.randrange(MIN_DISTACE_OF_PIPES, MAX_DISTACE_OF_PIPES):
            self.dx = 0
            new_pipe = Pipe.random_size_pipe(self.height, self.width, self.difficulty)
            self.pipe_sprites.extend(new_pipe)

        # Dalate pipes if they aren't on screen
        for pipe in self.pipe_sprites:
            if pipe.right <= 0:
                pipe.kill()

        self.pipe_sprites.update()
        self.bird.update()

        hit = arcade.check_for_collision_with_list(self.bird, self.pipe_sprites)
        if any(hit):
            arcade.play_sound(SOUNDS['hit'], 0.2)
            # if you have another life you lose it and delate two pieps (4 single pipes)
            if self.life > 1:
                self.life -= 1
                for pipe in self.pipe_sprites[:4]:
                    pipe.kill()
            else:
                # if you don't have any life you lost
                if self.high_scores[self.difficulty] < self.score : # save new best score
                    self.high_scores[self.difficulty] = self.score
                    
                    with open('data' + os.sep + 'high_score.json', 'w') as f:
                        json.dump(self.high_scores, f)

                self.bird.die()
                view = differents_views.GameOverView(self.score,  self.score_width, self.pipe_sprites, self.bird, self.difficulty, self.high_scores)
                self.window.show_view(view)
        
        # Couting points
        if self.bird.left >= self.pipe_sprites[0].right and not self.pipe_sprites[0].scored:
            arcade.play_sound(SOUNDS['point'], 0.5)
            self.score += 1
            self.pipe_sprites[0].scored = True
            self.pipe_sprites[1].scored = True
Пример #2
0
    def setup(self):
        """Method set some variables"""
        self.score = 0
        # Number of lives is connectet with dificulty level
        if self.difficulty == "easy":
            self.life = LIVES
        elif self.difficulty == "hard":
            self.life = 1

        self.score_board = arcade.SpriteList()
        self.number_width = arcade.load_texture(SCORE['1']).width 
        self.background = arcade.load_texture(BACKGROUNDS[0])
        self.instruction = arcade.load_texture(LABELS['how_to_jump'])
        self.pipe_sprites = arcade.SpriteList()
        self.bird =Bird(self.width // 5, self.height // 2, BIRDS[0]) 
        self.sprites = dict()
        self.sprites['background'] = self.background

        # Create starts pipes
        start_pipes = Pipe.random_size_pipe(self.height, self.width, self.difficulty)
        self.pipe_sprites.extend(start_pipes)