コード例 #1
0
    def start_settings(self):
        """
        This is the settings menu that controls the user actions
        """
        screen_title = Text(self.screen)
        back = SquareButton(self.screen, 100, 200, 150, 50, WHITE, LIGHT_GREY,
                            text_button_back)

        running = True

        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if back.is_hover():  # Quit settings
                        running = False

            self.screen.fill(WHITE)

            screen_title.draw_text_raw(text_button_settings, 540, 100, 50)
            back.draw_button()

            pygame.display.update()
コード例 #2
0
 def cars_dodged(self, count):
     """
     Displays to the user how many cars have been dodged
     """
     t = Text(self.screen)
     text_msg = " High Score: " + str(self.highscore) + " Score: " + str(count)
     t.draw_text_raw(text_msg, 120, 20, size=25, font_color=WHITE)
コード例 #3
0
    def crash(self):
        t = Text(self.screen)
        respawn_timer = Text(self.screen)

        seconds = 0
        while seconds < 3:
            self.screen.fill(WHITE)
            t.draw_text_raw(
                str(self.user) + " you crashed!", self.display_width / 2,
                self.display_height / 2, 100)
            respawn_timer.draw_text_raw(
                str(3 - seconds) + " seconds until respawn",
                self.display_width / 2, self.display_height / 2.5)
            pygame.display.update()
            time.sleep(1)
            seconds += 1

        self.run_game()
コード例 #4
0
 def __init__(self, screen, x_pos, y_pos, width, height, color, hover_color,
              text):
     self.screen = screen
     self.x_pos = x_pos
     self.y_pos = y_pos
     self.width = width
     self.height = height
     self.color = color
     self.hover_color = hover_color
     self.text = text
     self.text_object = Text(screen)
コード例 #5
0
    def crash(self, last_score, highscore):
        """
        Will display the crash screen for 3 seconds
        """
        t = Text(self.screen)
        respawn_timer = Text(self.screen)
        self.update_score(last_score, highscore)

        seconds = 0
        while seconds < 3:
            self.screen.fill(WHITE)
            msg = str(3 - seconds) + " seconds until respawn"

            t.draw_text_raw(str(self.user) + " you crashed!", self.display_width / 2, self.display_height / 2, 100)
            respawn_timer.draw_text_raw(msg, self.display_width / 2, self.display_height / 2.5)

            pygame.display.update()
            time.sleep(1)
            seconds += 1

        self.run_game()
コード例 #6
0
    def yes_no_popup(self, custom_text):
        running = True
        dialog = Text(self.screen)
        yes_button = SquareButton(self.screen, 440, 300, 100, 75, WHITE, LIGHT_GREY, "Yes")

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

            pygame.draw.rect(self.screen, WHITE, (365, 285, 350, 150))
            dialog.draw_text_raw(custom_text, 200, 250)
            yes_button.draw_button()

            pygame.display.flip()
コード例 #7
0
    def start_menu(self):
        """
        This is the menu that controls the user actions
        """
        global BACKGROUND
        running = True
        clock = pygame.time.Clock()

        start_button = SquareButton(self.screen, 100, 200, 150, 50, WHITE,
                                    LIGHT_GREY, text_button_start)
        multiplayer_button = SquareButton(self.screen, 100, 300, 150, 50,
                                          WHITE, LIGHT_GREY,
                                          text_button_multiplayer)
        settings_button = SquareButton(self.screen, 100, 400, 150, 50, WHITE,
                                       LIGHT_GREY, text_button_settings)
        quit_button = SquareButton(self.screen, 100, 500, 150, 50, WHITE,
                                   LIGHT_GREY, text_button_exit)
        game_title_object = Text(self.screen)

        color1 = [111, 168, 0]
        color2 = [215, 255, 137]

        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if quit_button.is_hover():  # Quit menu
                        pygame.quit()
                        quit()
                    if start_button.is_hover():  # Start game
                        running = False
                    if settings_button.is_hover():
                        # Settings(self.screen)
                        pass

            BACKGROUND = self.background_color(color1, color2)
            self.screen.fill(BACKGROUND)

            game_title_object.draw_text_raw(text_game_title, 540, 100, 50)
            start_button.draw_button()
            multiplayer_button.draw_button()
            settings_button.draw_button()
            quit_button.draw_button()

            clock.tick(60)
            pygame.display.flip()
コード例 #8
0
    def pause_menu(self):
        """
        This is the pause menu that controls the user actions
        """
        running = True

        screen_title = Text(self.screen)
        unpause_button = SquareButton(self.screen, 100, 200, 150, 50, WHITE,
                                      LIGHT_GREY, text_button_stop_pause)
        settings_button = SquareButton(self.screen, 100, 300, 150, 50, WHITE,
                                       LIGHT_GREY, text_button_settings)
        back_to_menu = SquareButton(self.screen, 100, 400, 150, 50, WHITE,
                                    LIGHT_GREY, text_button_back_to_menu)
        quit_button = SquareButton(self.screen, 100, 500, 150, 50, WHITE,
                                   LIGHT_GREY, text_button_exit)

        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        running = False
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if unpause_button.is_hover():
                        running = False
                    if settings_button.is_hover():
                        Settings(self.screen)
                    if back_to_menu.is_hover():
                        Menu(self.screen)
                    if quit_button.is_hover():
                        pygame.quit()
                        quit()

            screen_title.draw_text_raw(text_game_paused,
                                       540,
                                       100,
                                       50,
                                       font_color=WHITE)
            unpause_button.draw_button()
            settings_button.draw_button()
            back_to_menu.draw_button()
            quit_button.draw_button()

            pygame.display.update()
コード例 #9
0
    def yes_no_popup(self, custom_text):  # TODO: Fix this
        """
        Makes a popup window that displays a yes or no questions (would you like to quit?)
        """
        running = True
        dialog = Text(self.screen)
        yes_button = SquareButton(self.screen, 440, 300, 100, 75, WHITE,
                                  LIGHT_GREY, "Yes")

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

            pygame.draw.rect(self.screen, WHITE, (365, 285, 350, 150))
            dialog.draw_text_raw(custom_text, 200, 250)
            yes_button.draw_button()

            pygame.display.flip()