예제 #1
0
파일: Niveau.py 프로젝트: ykhen/New-Ball
    def __init__(self, window):
        Scene.__init__(self, window)

        #Bar principale
        self.bar = Bar(pygame.Rect(100, 450, 75, 20), self.window)
        self.sprites.append(self.bar)

        #Timer pour les apparitions des balles
        self.last_time_show_balle = pygame.time.get_ticks()


        #Les balles apparaissent toutes les self.show_ball_time en milliseconde
        self.show_ball_time = 1000

        #Timer pour avancer la difficulter
        self.last_time_advance_difficult = pygame.time.get_ticks()

        #Difficulté du niveau 1
        #Elle représente l'avancement des balles
        self.difficulties = 1

        #Font pour le label qui affiche les scores
        self.font_scores = pygame.font.SysFont("Colibri", 50)

        #Score
        self.scores = 0

        #Call back qui appelle le game over
        self.call_back_game_over = None
예제 #2
0
파일: Niveau.py 프로젝트: ykhen/New-Ball
    def __init__(self, window):
        Scene.__init__(self, window)

        #Bar principale
        self.bar = Bar(pygame.Rect(100, RECT_WINDOW.height / 2 - 20 / 2, 75, 20), self.window)
        self.sprites.append(self.bar)

         #Ajout de la line pour séparer les zones
        self.sprites.append(LineLimite(pygame.Rect(0, RECT_WINDOW.height / 2, RECT_WINDOW.width, 2), self.window))

        #Timer pour les apparitions des balles
        self.last_time_show_balle = pygame.time.get_ticks()

        #Les balles apparaissent toutes les self.show_ball_time en milliseconde
        self.show_ball_time = 1000

        #Timer pour avancer la difficulter
        self.last_time_advance_difficult = pygame.time.get_ticks()

        #Difficulté du niveau 1
        #Elle représente l'avancement des balles
        self.difficulties = 1

        #Cache la souris
        #pygame.mouse.set_visible(False)

        #Boolean qui permet de savoir si on affiche la ball en haut ou en bas
        self.show_ball_up = True

        #Scores
        self.scores = 0

        #Police de caractère du label scores
        self.font_scores = pygame.font.SysFont("Colibri", 50)
예제 #3
0
파일: Niveau.py 프로젝트: ykhen/New-Ball
    def update_screen(self):
        #Appèle de la super class
        Scene.update_screen(self)

        pygame.time.delay(8)

        now_time = pygame.time.get_ticks()
        if now_time - self.last_time_show_balle >= self.show_ball_time:
            self.last_time_show_balle = now_time
            self.sprites.append(Ball(pygame.Rect(random.randint(SIZE_BALL, RECT_WINDOW.width - SIZE_BALL), 0, SIZE_BALL, SIZE_BALL), self.window))

        if now_time - self.last_time_advance_difficult >= 10000:
            self.last_time_advance_difficult = now_time
            if self.difficulties <= 10:
                self.show_ball_time -= 65
                self.difficulties += 1




        #Fais descendre les bales
        for sprite in self.sprites:
            if isinstance(sprite, Ball):

                #Collision avec la bar
                if self.bar.rect.colliderect(sprite.rect):
                    sprite.move_up = True
                    self.scores += 1
                if sprite.move_up:
                    sprite.rect.y -= self.difficulties + 2
                else:
                    sprite.rect.y += self.difficulties
                #Quand la barre sort de la fenêtre
                if sprite.rect.colliderect(RECT_WINDOW) != True:
                    #La ball sort du haut de l'écran
                    if sprite.rect.y <= 0:
                        self.sprites.remove(sprite)
                    else:
                        #On perd
                        if self.call_back_game_over is not None:
                            self.call_back_game_over()

                        self.sprites.remove(sprite)
                        pass
        #Affiche le score
        self.window.blit(self.font_scores.render("{}".format(self.scores), 1, LABEL_SCORE_COLOR), (20, 20))
예제 #4
0
    def __init__(self, window):
        Scene.__init__(self, window)
        #Instance du niveau 1
        self.niveau_1 = None

        #Instance du niveau 2
        self.niveau_2 = None

        #Delegate, mecanisme permettant d'appeler en arrière
        self.delegate = None

        #Instance du button play
        size_button = pygame.Rect(0, 0, 300, 100)
        size_button.x = RECT_WINDOW.width / 2 - size_button.width / 2
        size_button.y = RECT_WINDOW.height / 2 - size_button.height / 2

        self.button_play = ButtonPlay(size_button, self.window)
        self.sprites.append(self.button_play)

        self.button_play.action = self.start_niveau_action
예제 #5
0
파일: Niveau.py 프로젝트: ykhen/New-Ball
    def __init__(self,  window):
        Scene.__init__(self, window)
        #Font pour le label
        self.font_game_over = pygame.font.SysFont("Colibri", 50)

        #Font pour le label d'informationn
        self.font_info = pygame.font.SysFont("Colibri", 25)

        #Font pour le label du button de retour
        self.font_back_button = pygame.font.SysFont("Colibri", 25)

        #Pour sortir du game over
        self.call_back = None

        #Call_back pour retourner au menu
        self.call_back_menu = None

        #Rect pour le button
        self.rect_button =  pygame.Rect(20, 20, 75, 30)
        self.score = 0
예제 #6
0
파일: menu.py 프로젝트: ykhen/New-Ball
    def __init__(self, window):
        Scene.__init__(self, window)
        #Instance du niveau 1
        self.niveau_1 = None

        #Instance du niveau 2
        self.niveau_2 = None

        #Delegate, mecanisme permettant d'appeler en arrière
        self.delegate = None


        #Instance du button play
        size_button = pygame.Rect(0, 0, 300, 100)
        size_button.x = RECT_WINDOW.width / 2 - size_button.width / 2
        size_button.y = RECT_WINDOW.height / 2 - size_button.height / 2

        self.button_play = ButtonPlay(size_button, self.window)
        self.sprites.append(self.button_play)

        self.button_play.action = self.start_niveau_action
예제 #7
0
파일: menu.py 프로젝트: ykhen/New-Ball
 def update_screen(self):
     Scene.update_screen(self)
예제 #8
0
 def update_screen(self):
     Scene.update_screen(self)
예제 #9
0
파일: Niveau.py 프로젝트: ykhen/New-Ball
    def update_screen(self):
        pygame.draw.rect(self.window, BACKGROUND_COLOR, pygame.Rect(0, 0, RECT_WINDOW.width, RECT_WINDOW.height))
        #Appèle de la super class
        Scene.update_screen(self)


        pygame.time.delay(8)

        now_time = pygame.time.get_ticks()
        #Ajoute la ball
        if now_time - self.last_time_show_balle >= self.show_ball_time:
            self.last_time_show_balle = now_time

            #Si la ball doit être envoyé dans haut puis descendre
            if self.show_ball_up:
                self.sprites.append(TopBall(pygame.Rect(random.randint(10, RECT_WINDOW.width - SIZE_BALL), 0, SIZE_BALL, SIZE_BALL), self.window))
            else:
                self.sprites.append(BottomBall(pygame.Rect(random.randint(10, RECT_WINDOW.width - SIZE_BALL), RECT_WINDOW.height - 10, SIZE_BALL, SIZE_BALL), self.window))
            self.show_ball_up = not self.show_ball_up


        #Augmente la difficultée
        if now_time - self.last_time_advance_difficult >= 10000:
            self.last_time_advance_difficult = now_time
            if self.difficulties <= 10:
                self.show_ball_time -= 65
                self.difficulties += 1




        #Fais descendre les bales
        for sprite in self.sprites:
            if isinstance(sprite, Ball):

                #Collision avec la bar
                if self.bar.rect.colliderect(sprite.rect):
                    sprite.move_up = not sprite.move_up
                    self.scores += 1


                #Si la class est une instance d'une ball qui part vers le haut
                if isinstance(sprite, TopBall):
                    #Détermine quand on perd pour la ball qui démarre en haut
                    if sprite.rect.y + sprite.rect.width >= RECT_WINDOW.height / 2:
                        self.sprites.remove(sprite)
                        self.scores = 0
                        self.difficulties = 1
                        self.show_ball_time = 1000

                        #-------------------
                        #      Game Over
                        #-------------------
                    else:
                        if sprite.move_up:
                            sprite.rect.y -= self.difficulties + 3
                        else:
                            sprite.rect.y += self.difficulties

                elif isinstance(sprite, BottomBall):
                    #Détermine quand on perd pour la ball qui démarre en bas
                    if sprite.rect.y <= RECT_WINDOW.height / 2:
                        self.sprites.remove(sprite)
                        self.scores = 0
                        self.difficulties = 1
                        self.show_ball_time = 1000

                        #-------------------
                        #      Game Over
                        #-------------------

                    else:
                        if sprite.move_up:
                            sprite.rect.y -= self.difficulties
                        else:
                            sprite.rect.y += self.difficulties + 3

                #Quand la barre sort de la fenêtre
                if not sprite.rect.colliderect(RECT_WINDOW):
                    #La ball sort de l'écran
                    self.sprites.remove(sprite)

        #Affiche le score
        self.window.blit(self.font_scores.render("{}".format(self.scores), 1, LABEL_SCORE_COLOR), (20, 20))