Beispiel #1
0
class Game:
    BLACK = (0, 0, 0)

    def __init__(self):
        pygame.init()
        pygame.mixer.pre_init(44100, 16, 2, 4096)
        self.settings = Settings()
        self.settings.start_intro_music()
        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("Pacman Portal")
        self.clock = pygame.time.Clock()
        self.radius = 1
        self.start = 1
        self.end = 10
        self.begin = pygame.time.get_ticks()
        self.wait = 800

        self.startup = Start(self.screen, self.settings)
        self.stats = Stats(self.settings)
        self.sb = Scoreboard(self.settings, self.screen, self.stats)

        self.maze = Maze(self.screen, mazefile='images/pacman_portal_maze.txt',
                         brickfile='square', orangeportalfile='portal_orange', blueportalfile='portal_blue',
                         shieldfile='shield', pointfile='point_pill', gatefile="gate")
        self.pacman = Pacman(self.screen, mazefile='images/pacman_portal_maze.txt')

        self.red = Red(self.screen, mazefile='images/pacman_portal_maze.txt')
        self.blue = Blue(self.screen, mazefile='images/pacman_portal_maze.txt')
        self.orange = Orange(self.screen, mazefile='images/pacman_portal_maze.txt')
        self.pink = Pink(self.screen, mazefile='images/pacman_portal_maze.txt')
        self.inc = 0

    def __str__(self): return 'Game(Pacman Portal), maze=' + str(self.maze) + ')'

    def open_portal(self, x, y, color):
        for r in range(self.start, self.end):
            pygame.gfxdraw.circle(self.screen, x, y, r, color)
        now = pygame.time.get_ticks()
        if now < self.begin + self.wait:
            self.inc = 1
        elif now < self.begin + 4 * self.wait:
            self.inc = 0
        else:
            self.inc = -1
        self.start += self.inc
        self.start = max(1, self.start)
        self.end += self.inc

    def play(self):
        clock = pygame.time.Clock()
        eloop = EventLoop(finished=False)
        while not eloop.finished:
            eloop.check_events(self.screen, self.pacman, self.startup)
            if self.startup.playing:
                pygame.mixer.music.stop()
                if not self.settings.flag_chomp:
                    self.settings.chomp_music()
                    self.settings.flag_chomp = True
                self.settings.chomp_music()
                self.pacman.update(self.maze, self.settings, self.stats, self.sb, self.red, self.blue, self.orange,
                                   self.pink)
                self.red.update(self.maze, self.settings, self.stats, self.pacman, self.startup, self.blue, self.pink,
                                self.orange, self.sb)
                self.blue.update(self.maze, self.settings, self.stats, self.pacman, self.startup, self.red, self.pink,
                                 self.orange, self.sb)
                self.orange.update(self.maze, self.settings, self.stats, self.pacman, self.startup, self.blue,
                                   self.pink, self.red, self.sb)
                self.pink.update(self.maze, self.settings, self.stats, self.pacman, self.startup, self.blue, self.red,
                                 self.orange, self.sb)

            self.update_screen()
            clock.tick(155)

    def update_screen(self):
        if not self.startup.playing:
            self.startup.draw_bg()
            self.startup.draw_button()
        else:
            self.screen.fill(Game.BLACK)
            self.maze.blitme()
            self.pacman.blitme()
            self.red.blitme()
            self.blue.blitme()
            self.orange.blitme()
            self.pink.blitme()
            self.open_portal(100, 100, (240, 100, 20))
            self.sb.show_score()
        pygame.display.flip()
Beispiel #2
0
class Game:
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode((735, 800))
        pygame.display.set_caption("Pac-man")
        self.settings = Settings()

        self.radius = 1
        self.start = 2
        self.end = 10
        self.begin = pygame.time.get_ticks()
        self.wait = 800

        self.stats = Stats(self.settings)

        self.pb = Button(self.screen)

        self.maze = Maze(self.screen, 'images/maze.txt', 'images/cube0.png',
                         'images/gate0.png', 'images/dot0.png')

        self.sb = Scoreboard(self.settings, self.screen, self.stats, self.maze,
                             self.pb)

        self.player = Player(self.settings, self.screen, self.stats, self.sb,
                             self.maze)
        self.red = Red(self.screen, self.stats, self.player, self.sb,
                       self.maze)
        self.blue = Blue(self.screen, self.stats, self.player)
        self.orange = Orange(self.screen, self.stats, self.player)
        self.pink = Pink(self.screen, self.stats, self.player)

        self.menu = Menu(self.screen, self.stats, self.sb, self.pb, self.maze)

    def open_portal(self, x, y, color):
        for r in range(self.start, self.end):
            pygame.gfxdraw.circle(self.screen, x, y, r, color)
        now = pygame.time.get_ticks()
        if now < self.begin + self.wait:
            self.inc = 1
        elif now < self.begin + 4 * self.wait:
            self.inc = 0
        else:
            self.inc = -1

        self.start += self.inc
        self.start = max(1, self.start)
        self.end += self.inc

    def play(self):
        clock = pygame.time.Clock()
        eloop = EventLoop(finished=False)

        self.menu.prep_screen()

        while not eloop.finished:
            eloop.check_events(self.settings, self.screen, self.stats, self.sb,
                               self.player, self.pb, self.maze)

            if self.stats.game_active:
                self.player.update(self.maze)
                self.red.update()
                self.blue.update()
                self.orange.update()
                self.pink.update()

            self.display_game()
            clock.tick(20)

    def display_game(self):
        self.screen.fill((0, 0, 0))
        self.maze.blitme()
        self.open_portal(365, 550, (240, 100, 20))
        self.player.blitme()
        self.red.blitme()
        self.blue.blitme()
        self.orange.blitme()
        self.pink.blitme()
        self.sb.show_score()

        if not self.stats.game_active:
            self.menu.draw_menu()
            if self.stats.HS_active:
                self.display_HS_menu()

        pygame.display.flip()

    def display_HS_menu(self):
        self.screen.fill((0, 0, 0))
        self.sb.prep_list()
        self.sb.display_list()