Exemplo n.º 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()
Exemplo n.º 2
0
class Menu:
    def __init__(self, screen, stats, sb, play_button, maze):
        self.settings = Settings()
        self.screen = screen
        self.screen_rect = screen.get_rect()
        self.button = play_button
        self.stats = stats
        self.sb = sb

        self.maze = maze

        self.menu_color = (0, 0, 0)
        self.text_color = (250, 250, 210)
        self.font = pygame.font.SysFont(None, 150)

        self.title = "Pac-man"

        self.prep_screen()

    def prep_screen(self):
        self.title_image = self.font.render(self.title, True, self.text_color,
                                            self.menu_color)
        self.title_image_rect = self.title_image.get_rect()
        self.title_image_rect.centerx = self.screen_rect.centerx
        self.title_image_rect.centery = self.screen_rect.top + 100

        self.create_pacman()
        self.create_ghost()

    def draw_menu(self):
        self.screen.fill((0, 0, 0))
        self.screen.blit(self.title_image, self.title_image_rect)
        self.button.draw_button()
        self.animate_pacman()
        self.animate_ghost()

    def create_pacman(self):
        self.pacman = Player(self.settings, self.screen, self.stats, self.sb,
                             self.maze)

        self.pacman.centerx = self.screen_rect.left
        self.pacman.rect.centery = self.screen_rect.centery

        self.pacman.index = 4

    def create_ghost(self):
        self.red = Red(self.screen, self.stats, self.pacman, self.sb,
                       self.maze)

        self.red.centerx = self.screen_rect.left - 100
        self.red.rect.centery = self.screen_rect.centery

        self.red.index = 4

        self.blue = Blue(self.screen, self.stats, self.pacman)

        self.blue.centerx = self.screen_rect.left - 125
        self.blue.rect.centery = self.screen_rect.centery

        self.blue.index = 4

        self.orange = Orange(self.screen, self.stats, self.pacman)

        self.orange.centerx = self.screen_rect.left - 150
        self.orange.rect.centery = self.screen_rect.centery

        self.orange.index = 4

        self.pink = Pink(self.screen, self.stats, self.pacman)

        self.pink.centerx = self.screen_rect.left - 175
        self.pink.rect.centery = self.screen_rect.centery

        self.pink.index = 4

    def animate_pacman(self):
        self.pacman.screen_animate()
        self.pacman.blitme()

    def animate_ghost(self):
        self.red.screen_animate()
        self.red.blitme()

        self.blue.screen_animate()
        self.blue.blitme()

        self.orange.screen_animate()
        self.orange.blitme()

        self.pink.screen_animate()
        self.pink.blitme()
Exemplo n.º 3
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()