Beispiel #1
0
class Menu:
    def __init__(self, num_snows_scroll=50, background=BACKGROUNG_IMG, wind_power=50):
        pygame.init()
        self.num_snows_scroll = num_snows_scroll
        self.screen = pygame.display.set_mode((500, 500))
        self.btn_start = Button(pos=(150, 150), image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                                path=BUTTON_IMAGE_PATH, function=self.on_btn_start, text='Start! ', w=200)
        self.btn_settings = Button(pos=(150, 205),
                                   image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                                   path=BUTTON_IMAGE_PATH, function=self.on_btn_settings, text='Settings ', w=200)
        self.btn_exit = Button(pos=(150, 260), image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                               path=BUTTON_IMAGE_PATH, function=self.on_btn_exit, text='Exit ', w=200)
        self.work = True
        self.background = background
        self.background_image = pygame.transform.scale(load_image(self.background, 0, IMAGE_PATH), PLATFORM)
        self.wind_power = wind_power

    def on_btn_exit(self):
        sys.exit()

    def on_btn_start(self):
        self.work = False
        win_snow = Program(self.num_snows_scroll, background=self.background if self.background else None,
                           wind_power=self.wind_power)
        win_snow.run()
        # print('start')

    def on_btn_settings(self):
        self.work = False
        win_settings = Settings(background=self.background)
        win_settings.run()

    def render(self):
        self.btn_start.render(self.screen)
        self.btn_settings.render(self.screen)
        self.btn_exit.render(self.screen)

    def event(self, event):
        self.btn_start.event(event)
        self.btn_settings.event(event)
        self.btn_exit.event(event)

    def run(self):
        while self.work:
            self.screen.blit(self.background_image, (0, 0))

            for event in pygame.event.get():
                self.event(event)
                if event.type == pygame.QUIT:
                    sys.exit()

                    # self.update(0)
            self.render()

            pygame.display.flip()
Beispiel #2
0
class Menu:
    def __init__(self):
        pygame.display.set_mode((WIN_WIDHT, WIN_HEIGH))  # создание окна
        self.start_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
                              path=BUTTONS_PATH, pos=(410, 224), text='Start', function=self.start_game)
        self.top_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
                              path=BUTTONS_PATH, pos=(410, 287), text='Top Records', function=self.start_top)
        # self.setting_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
        #                       path=BUTTONS_PATH, pos=(410, 350), text='Setting', function=None)
        self.exit_b = Button(('button_on.png', 'button_hover.png', 'button_click.png'),
                              path=BUTTONS_PATH, pos=(410, 350), text='Exit', function=self.close)
        self.done = True

    def close(self):
        sys.exit()

    def update(self):
        pass

    def events(self, event):
        self.start_b.event(event)
        # self.setting_b.event(event)
        self.top_b.event(event)
        self.exit_b.event(event)

    def render(self, screen):
        self.start_b.render(screen)
        # self.setting_b.render(screen)
        self.top_b.render(screen)
        self.exit_b.render(screen)

    def start_game(self):
        pygame.font.init()
        snake = Snake((4, 4), (0, 0, 0), (255, 255, 255),
                  (pygame.K_a, pygame.K_d, pygame.K_w, pygame.K_s),
                  4, 4, menu=Menu())
        snake.run_snake()

    def start_top(self):
        top = Top()
        top.run()

    def run(self):
        pygame.init()
        pygame.font.init()
        pygame.display.set_caption('Menu')
        game_screen = pygame.Surface((WIN_WIDHT, WIN_HEIGH))
        screen = pygame.display.get_surface()
        clock = pygame.time.Clock()
        while self.done:  # главный цикл программы
            for event in pygame.event.get():  # цикл обработки очереди событий окна
                if event.type == pygame.QUIT:
                    sys.exit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        sys.exit()
                self.events(event)
            pygame.display.update()
            clock.tick(FPS)
            screen.fill((10, 20, 30))
            game_screen.fill((10, 20, 30))
            self.render(screen)
Beispiel #3
0
class Settings:
    def __init__(self, background=BACKGROUNG_IMG, pos=(0, 0), size=(20, 20)):
        pygame.init()
        self.screen = pygame.display.set_mode((500, 500))
        self.btn_select_background = Button(pos=(150, 275),
                                        image_names=('button_on.png', 'button_hover.png', 'button_click.png'),
                                        path=BUTTON_IMAGE_PATH,
                                        function=self.on_btn_select_background, text=' Background ', w=200)
        self.btn_back_to_menu = Button(pos=(150, 330), image_names=('button_on.png', 'button_hover.png',
                                                                    'button_click.png'),
                                       path=BUTTON_IMAGE_PATH,
                                       function=self.on_btn_back_to_menu, text='Back to menu', w=200)

        self.scrollbar = ScrollBar(150, 150, min_num=50, max_num=5000, text='Number snow') # изменение кол-ва снежинок
        self.scrollbar_wind = ScrollBar(150, 220, min_num=5, max_num=500, text='Wind power') # изменение силы ветра
        self.work = True
        self.num_snows_scroll = None
        self.background = background
        self.background_image = pygame.transform.scale(load_image(self.background, 0, IMAGE_PATH), PLATFORM)
        self.rect = pygame.Rect(pos, size)

    def on_btn_back_to_menu(self):
        from Classes.Menu import Menu

        self.work = False
        num_snows_scroll = self.scrollbar.get_num()  # кол-во снежинок = значение снежинок на скроллинге
        wind_power = self.scrollbar_wind.get_num()
        print("from sc = ", num_snows_scroll)
        win_snow = Menu(num_snows_scroll, wind_power=wind_power)
        win_snow.run()

    def on_btn_select_background(self):
        from Classes.Background import SelectBackground

        win_snow = SelectBackground(background=self.background)
        win_snow.run()
        print('Background')

    def draw(self):
        pygame.draw.rect(self.screen, (10, 100, 100), Rect((145, 127), (212, 140)))

    def render(self):
        self.screen.blit(self.screen, self.rect)
        self.btn_back_to_menu.render(self.screen)
        self.btn_select_background.render(self.screen)
        self.scrollbar.render(self.screen)
        self.scrollbar_wind.render(self.screen)

    def event(self, event):
        self.btn_back_to_menu.event(event)
        self.btn_select_background.event(event)
        self.scrollbar.event(event)
        self.scrollbar_wind.event(event)

    def run(self):
        while self.work:
            self.screen.blit(self.background_image, (0, 0))
            self.draw()

            for event in pygame.event.get():
                self.event(event)
                if event.type == pygame.QUIT:
                    sys.exit()

                    # self.update(0)
            self.render()

            pygame.display.flip()