示例#1
0
 def toggle_debug(self):
     debug = not FileManager.instance().get(FileName.Setting, 'debug')
     FileManager.instance().set(FileName.Setting, 'debug', debug)
     self._buttons[0].text = 'Debug:{0}'.format((lambda x: "Вкл"
                                                 if x else "Выкл")(debug))
     Core.instance().update_settings()
     UIManager.instance().set_screen(DebugSettingsMode())
示例#2
0
 def toggle(self):
     fps = not FileManager.instance().get(FileName.Setting, 'fps')
     FileManager.instance().set(FileName.Setting, 'fps', fps)
     self._buttons[2].text = 'Счетчик fps:{0}'.format(
         (lambda x: "Вкл" if x else "Выкл")(fps))
     Core.instance().update_settings()
     UIManager.instance().set_screen(SettingsMode())
示例#3
0
 def reset(self, i):
     if i in self._resolutions:
         FileManager.instance().set(FileName.Setting, "width",
                                    self._resolutions[i][0])
         FileManager.instance().set(FileName.Setting, "height",
                                    self._resolutions[i][1])
         Core.instance().update_settings()
         UIManager.instance().set_screen(ResolutionMode())
示例#4
0
 def toggle_music_down(self):
     volume = FileManager.instance().get(FileName.Setting, "music_volume")
     if volume > 0:
         volume -= 0.01
     volume = int(100 * volume) / 100
     self._buttons[0].text = 'Громкость музыки:{0}'.format(volume)
     FileManager.instance().set(FileName.Setting, 'music_volume', volume)
     Core.instance().update_settings()
     UIManager.instance().set_screen(VolumeMode())
     AudioManager.instance().set_volume()
示例#5
0
 def toggle_wall(self):
     debug = FileManager.instance().get(FileName.Setting, 'debug')
     wall_debug = not FileManager.instance().get(FileName.Setting,
                                                 'wall_debug')
     if not debug and wall_debug:
         debug = not debug
     FileManager.instance().set(FileName.Setting, 'debug', debug)
     FileManager.instance().set(FileName.Setting, 'wall_debug', wall_debug)
     self._buttons[1].text = 'Wall_debug:{0}'.format(
         (lambda x: "Вкл" if x else "Выкл")(wall_debug))
     Core.instance().update_settings()
     UIManager.instance().set_screen(DebugSettingsMode())
示例#6
0
 def call(self, event):
     if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
         UIManager.instance().set_screen(SettingsMode())
     if event.type == pygame.MOUSEMOTION:
         mouse_pos = pygame.mouse.get_pos()
         for button in self._buttons:
             button.update(mouse_pos)
     if event.type == pygame.MOUSEBUTTONDOWN:
         mouse_pos = pygame.mouse.get_pos()
         for b in self._buttons:
             if b.contain(mouse_pos):
                 b.clicked()
示例#7
0
    def update(self, delta: float):
        if self._zoom > 0 and self._camera.zoom < self._camera.max_zoom:
            self._camera.zoom += 0.01
        elif self._zoom < 0 and self._camera.zoom > self._camera.min_zoom:
            self._camera.zoom -= 0.01

        self._player.move(self._direction)
        self._world.step(delta)
        self._camera.pos = self._player.body.position

        if self._player.life <= 0:
            UIManager.instance().set_screen(MenuMode())
        self._playerUI.update()
示例#8
0
 def call(self, event):
     if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
         UIManager.instance().set_screen(MenuMode())
     if event.type == pygame.MOUSEMOTION:
         mouse_pos = pygame.mouse.get_pos()
         for button in self._buttons:
             button.update(mouse_pos)
     if event.type == pygame.MOUSEBUTTONDOWN:
         mouse_pos = pygame.mouse.get_pos()
         for i in range(0, len(self._buttons)):
             if self._buttons[i].contain(mouse_pos):
                 self._buttons[i].clicked(i)
                 break
示例#9
0
 def toggle_up(self):
     volume = FileManager.instance().get(FileName.Setting, "volume")
     if volume < 1:
         volume += 0.01
     volume = int(100 * volume) / 100
     if volume == 0.06:
         volume = 0.07
     if volume == 0.57:
         volume = 0.58
     self._buttons[0].text = 'Громкость эффектов:{0}'.format(volume)
     FileManager.instance().set(FileName.Setting, 'volume', volume)
     Core.instance().update_settings()
     UIManager.instance().set_screen(VolumeMode())
     AudioManager.instance().set_volume()
示例#10
0
 def __init__(self):
     self._resolutions = {
         0: [800, 600],
         1: [1280, 720],
         2: [1600, 900],
         3: [1920, 1080]
     }
     self._screen_h = pygame.display.Info().current_h
     self._screen_w = pygame.display.Info().current_w
     self._buttons = [
         Button(int(self._screen_w / 3), int(self._screen_h / 10),
                int(self._screen_w / 3), int(self._screen_h / 8), '800x600',
                self.reset),
         Button(int(self._screen_w / 3),
                int(self._screen_h / 5) + int(self._screen_h / 8 * 0.29),
                int(self._screen_w / 3), int(self._screen_h / 8),
                '1280x720', self.reset),
         Button(
             int(self._screen_w / 3),
             int(3 * self._screen_h / 10) +
             2 * int(self._screen_h / 8 * 0.29), int(self._screen_w / 3),
             int(self._screen_h / 8), '1600x900', self.reset),
         Button(
             int(self._screen_w / 3),
             int(4 * self._screen_h / 10) +
             3 * int(self._screen_h / 8 * 0.29), int(self._screen_w / 3),
             int(self._screen_h / 8), '1920x1080', self.reset),
         Button(
             int(self._screen_w / 3),
             int(5 * self._screen_h / 10) +
             4 * int(self._screen_h / 8 * 0.29), int(self._screen_w / 3),
             int(self._screen_h / 8), 'Назад',
             lambda x: UIManager.instance().set_screen(MenuMode()))
     ]
示例#11
0
    def start(self, screen: Mode):
        """
            начало main_loop
            :param screen: начальный экран приложения
        """

        manager = UIManager.instance()
        manager.set_screen(screen)  # start game

        # время в секундах
        delta = 1 / 60
        delta_time = -1
        while manager.done:

            t = time.clock()

            for event in pygame.event.get():
                manager.get_screen().call(event)

            manager.update(delta)
            manager.render()

            if self.fps_counter and delta_time != -1:
                self.fps_counter.add_delta(delta_time)
                self.fps_counter.draw(self._window)

            self._clock.tick(60)
            pygame.display.flip()
            self._window.fill((0, 0, 0))
            delta_time = time.clock() - t

        FileManager.instance().save()
        pygame.quit()
示例#12
0
 def __init__(self):
     # pygame.mixer.music.set_volume(1)
     self._screen_h = Core.instance().info().current_h
     self._screen_w = Core.instance().info().current_w
     self._buttons = [
         Button(
             int(self._screen_w / 3), int(self._screen_h / 8),
             int(self._screen_w / 3), int(self._screen_h / 8), 'Новая игра',
             lambda: UIManager.instance().set_screen(
                 (lambda: DebugMode() if FileManager.instance().get(
                     FileName.Setting, 'debug') else GameMode())())),
         Button(int(self._screen_w / 3),
                int(self._screen_h / 4) + int(self._screen_h / 8 * 0.29),
                int(self._screen_w / 3), int(self._screen_h / 8),
                'Настройки',
                lambda: UIManager.instance().set_screen(SettingsMode()))
     ]
示例#13
0
 def __init__(self):
     self._screen_h = Core.instance().info().current_h
     self._screen_w = Core.instance().info().current_w
     self._buttons = [
         Button(int(self._screen_w / 3), int(self._screen_h / 8),
                int(self._screen_w / 3), int(self._screen_h / 8),
                'You win!',
                lambda: UIManager.instance().set_screen(MenuMode()))
     ]
示例#14
0
    def call(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE or event.type == pygame.QUIT:
                UIManager.instance().set_screen(MenuMode())
            else:
                if event.key == pygame.K_r:
                    self.reset()
                if event.key == pygame.K_w:
                    self._direction |= 1
                if event.key == pygame.K_d:
                    self._direction |= 2
                if event.key == pygame.K_s:
                    self._direction |= 4
                if event.key == pygame.K_a:
                    self._direction |= 8
                if event.key == pygame.K_MINUS:
                    self._zoom = -1
                if event.key == pygame.K_EQUALS:
                    self._zoom = 1
        if event.type == pygame.MOUSEMOTION:
            mouse_pos = pygame.mouse.get_pos()
            p = self._camera.transform_coord(self._player.pos.x,
                                             self._player.pos.y)
            self._player.set_direction(-math.atan2(mouse_pos[1] -
                                                   p[1], mouse_pos[0] - p[0]))

        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                self._player.shot(True)
        if event.type == pygame.MOUSEBUTTONUP:
            if event.button == 1:
                self._player.shot(False)

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_w:
                self._direction &= ~1
            if event.key == pygame.K_d:
                self._direction &= ~2
            if event.key == pygame.K_s:
                self._direction &= ~4
            if event.key == pygame.K_a:
                self._direction &= ~8
            if event.key == pygame.K_MINUS or event.key == pygame.K_EQUALS:
                self._zoom = 0
示例#15
0
 def _key(self, event):
     if event.type == pygame.KEYDOWN:
         if event.key == pygame.K_ESCAPE or event.type == pygame.QUIT:
             FileManager.instance().save_level()
             UIManager.instance().set_screen(MenuMode())
         else:
             if event.key == pygame.K_f:
                 self.save()
             if event.key == pygame.K_1:
                 self._class = StupidEnemy
             elif event.key == pygame.K_3:
                 self._class = SetterItem
             elif event.key == pygame.K_4:
                 self._class = Barrel
             elif event.key == pygame.K_5:
                 self._class = Box
             elif event.key == pygame.K_2:
                 self._class = Player
             elif event.key == pygame.K_w:
                 self._direction |= 1
             elif event.key == pygame.K_d:
                 self._direction |= 2
             elif event.key == pygame.K_s:
                 self._direction |= 4
             elif event.key == pygame.K_a:
                 self._direction |= 8
             elif event.key == pygame.K_q and self._target is not None:
                 self._target.type_item += 1
             elif event.key == pygame.K_MINUS:
                 self._zoom = -1
             elif event.key == pygame.K_EQUALS:
                 self._zoom = 1
     if event.type == pygame.KEYUP:
         if event.key == pygame.K_w:
             self._direction &= ~1
         if event.key == pygame.K_d:
             self._direction &= ~2
         if event.key == pygame.K_s:
             self._direction &= ~4
         if event.key == pygame.K_a:
             self._direction &= ~8
         if event.key == pygame.K_MINUS or event.key == pygame.K_EQUALS:
             self._zoom = 0
示例#16
0
 def call(self, event):
     if event.type == pygame.KEYDOWN:
         if event.key == pygame.K_ESCAPE:
             UIManager.instance().set_screen(MenuMode())
         if event.key == pygame.K_g:
             self._press_g += 1
             if self._press_g == 3:
                 self._press_g = 0
                 FileManager.instance().set(
                     FileName.Setting,
                     "god_mode", not FileManager.instance().get(
                         FileName.Setting, "god_mode"))
     if event.type == pygame.MOUSEMOTION:
         mouse_pos = pygame.mouse.get_pos()
         for button in self._buttons:
             button.update(mouse_pos)
     if event.type == pygame.MOUSEBUTTONDOWN:
         mouse_pos = pygame.mouse.get_pos()
         for i in range(0, len(self._buttons)):
             if self._buttons[i].contain(mouse_pos):
                 self._buttons[i].clicked()
                 break
示例#17
0
 def __init__(self):
     self._screen_h = pygame.display.Info().current_h
     self._screen_w = pygame.display.Info().current_w
     self._buttons = [
         Button(int(self._screen_w / 3), int(self._screen_h / 8),
                int(self._screen_w / 3), int(self._screen_h / 8),
                'Громкость',
                lambda: UIManager.instance().set_screen(VolumeMode())),
         Button(int(self._screen_w / 3),
                int(self._screen_h / 4) + int(self._screen_h / 8 * 0.29),
                int(self._screen_w / 3), int(self._screen_h / 8),
                'Выбрать разрешение',
                lambda: UIManager.instance().set_screen(ResolutionMode())),
         Button(
             int(self._screen_w / 3),
             int(3 * self._screen_h / 8) +
             2 * int(self._screen_h / 8 * 0.29), int(self._screen_w / 3),
             int(self._screen_h / 8), 'Счетчик fps:{0}'.format(
                 (lambda x: "Вкл"
                  if x else "Выкл")(FileManager.instance().get(
                      FileName.Setting, "fps"))), self.toggle),
         Button(
             int(self._screen_w / 3),
             int(3 * self._screen_h / 8) +
             2 * int(self._screen_h / 8 * 0.29), int(self._screen_w / 3),
             int(self._screen_h / 8), 'Счетчик fps:{0}'.format(
                 (lambda x: "Вкл"
                  if x else "Выкл")(FileManager.instance().get(
                      FileName.Setting, "fps"))), self.toggle),
         Button(
             int(self._screen_w / 3),
             int(4 * self._screen_h / 8) +
             3 * int(self._screen_h / 8 * 0.29), int(self._screen_w / 3),
             int(self._screen_h / 8), 'Debug',
             lambda: UIManager.instance().set_screen(DebugSettingsMode()))
     ]
     self._press_g = 0
示例#18
0
 def reset(self):
     self.destroy()
     UIManager.instance().set_screen(GameMode())
示例#19
0
 def update_level(level):
     from game.ui_manager.modes import GameMode as gm
     from game.ui_manager.ui_manager import UIManager as ui
     ui.instance().get_screen().destroy()
     ui.instance().set_screen(gm(level))
示例#20
0
 def remove_boss(self, actor):
     from game.ui_manager.modes import EndGame as eg
     from game.ui_manager.ui_manager import UIManager as ui
     ui.instance().set_screen(eg())
     self._w.remove_actor(actor)