Esempio n. 1
0
def Game():
    pygame.init()

    gamesettings = Settings()
    screen = pygame.display.set_mode(
        (gamesettings.screen_width, gamesettings.screen_height))
    pygame.display.set_caption("Pacman Portal")

    # Start screen
    startScreen = StartScreen(screen, gamesettings)
    showgamestats = GameStats(screen, gamesettings)

    # Grouping blocks and pellets
    blocks = Group()
    powerpills = Group()
    shield = Group()
    portal = Group()

    thepacman = Pacman(screen, gamesettings)

    # Making the ghosts
    redghost = Ghosts(screen, "red")
    cyanghost = Ghosts(screen, "cyan")
    orangeghost = Ghosts(screen, "orange")
    pinkghost = Ghosts(screen, "pink")

    startScreen.makeScreen(screen)
    gf.readFile(screen, blocks, shield, powerpills, portal)

    screen.fill(BLACK)
    while True:
        screen.fill(BLACK)
        showgamestats.blitstats()
        gf.check_events(thepacman)
        gf.check_collision(thepacman, blocks, powerpills, shield)
        thepacman.update()
        for block in blocks:
            block.blitblocks()
        for theshield in shield:
            theshield.blitshield()
        for pill in powerpills:
            pill.blitpowerpills()
        for theportal in portal:
            theportal.blitportal()
        thepacman.blitpacman()
        redghost.blitghosts()
        cyanghost.blitghosts()
        orangeghost.blitghosts()
        pinkghost.blitghosts()

        pygame.display.flip()
Esempio n. 2
0
def Game():
    pygame.init()

    settings = Settings()
    screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Pacman Portal")

    startScreen = StartScreen(screen, settings)
    showgamestats = GameStats(screen, settings)

    bricks = Group()
    powerpellets = Group()
    pellets = Group()
    shield = Group()
    fruits = Group()
    portal = Group()

    thepacman = Pacman(screen, settings)

    blinky = Ghosts(screen, "red")
    inky = Ghosts(screen, "cyan")
    clyde = Ghosts(screen, "orange")
    pinky = Ghosts(screen, "pink")

    startScreen.makeScreen(screen)
    gf.readFile(screen, bricks, shield, pellets, powerpellets)

    screen.fill(BLACK)
    while True:
        screen.fill(BLACK)
        showgamestats.blitstats()
        gf.check_events(thepacman)
        gf.check_collision(thepacman, bricks, pellets, powerpellets, shield, fruits)
        thepacman.update()
        for brick in bricks:
            brick.blitbricks()
        for theshield in shield:
            theshield.blitshield()
        for power in powerpellets:
            power.blitpowerpills()
        for pellet in pellets:
            pellet.blitpellet()
        thepacman.blitpacman()
        blinky.blitghosts()
        inky.blitghosts()
        clyde.blitghosts()
        pinky.blitghosts()

        pygame.display.flip()
Esempio n. 3
0
def run_game():
    # 初始化游戏并创建一个项目
    pygame.init()
    gs_settings = Settings()
    screen = pygame.display.set_mode(
        (gs_settings.screen_width, gs_settings.screen_height))
    pygame.display.set_caption("Snake")

    snake_speed_clock = pygame.time.Clock()
    # 创建一个蛇头
    snake_head = SnakeHead(gs_settings, screen)
    food = Food(screen, gs_settings)

    #创建蛇的身体
    snakes = [snake_head]

    while True:
        #监视键盘和鼠标事件
        gf.check_events(snakes[0])
        gf.move_snake(snakes, gs_settings, screen)
        gf.check_collision(food, snakes)
        # 每次循环时都重绘制屏幕
        gf.update_screen(gs_settings, screen, snakes, food, snake_speed_clock)
Esempio n. 4
0
                bird_movement = 0
                pipe_list.clear()
                bird_rect.centerx = 288
                bird_rect.centery = 512
        elif event.type == PIPESPAWN:
            pipe_list.extend(create_pipe(pipe_surface, pipes_height))

    screen.blit(bg_surface, (0, 0))

    if game_active:
        pipe_list = move_pipes(pipe_list)
        draw_pipes(pipe_list, screen, pipe_surface)

        if base_surface_start_1 < -576:
            base_surface_start_1 = 0
            draw_base(screen, base_surface_1, base_surface_start_1)
        else:
            base_surface_start_1 -= 3
            draw_base(screen, base_surface_1, base_surface_start_1)

        bird_movement += gravity
        rotated_birt = rotate_bird(bird_surface, bird_movement)
        bird_rect.centery += bird_movement

        screen.blit(rotated_birt, bird_rect)

    game_active = check_collision(bird_rect, pipe_list)

    pygame.display.flip()
    clock.tick(50)
Esempio n. 5
0
def Game():
    pygame.init()

    gamesettings = Settings()
    screen = pygame.display.set_mode(
        (gamesettings.screen_width, gamesettings.screen_height))
    pygame.display.set_caption("Pacman Portal")

    # Start screen
    showgamestats = GameStats(screen, gamesettings)
    startScreen = StartScreen(screen, gamesettings, showgamestats)

    # Grouping blocks and pellets and ghosts
    blocks = Group()
    powerpills = Group()
    shield = Group()
    portals = Group()
    ghosts = Group()
    intersections = Group()
    fruit = Fruit(screen)

    thepacman = Pacman(screen, gamesettings)

    # Making the ghosts
    redghost = Ghosts(screen, "red")
    cyanghost = Ghosts(screen, "cyan")
    orangeghost = Ghosts(screen, "orange")
    pinkghost = Ghosts(screen, "pink")

    ghosts.add(redghost)
    ghosts.add(cyanghost)
    ghosts.add(orangeghost)
    ghosts.add(pinkghost)

    # Making the two portals
    orange = Portal(screen, "orange")
    blue = Portal(screen, "blue")

    portals.add(orange)
    portals.add(blue)

    startScreen.makeScreen(screen, gamesettings)
    fruit.fruitReset()
    gf.readFile(screen, blocks, shield, powerpills, intersections)

    frames = 0  # for the victory fanfare and death animation

    # play intro chime
    playIntro = True

    screen.fill(BLACK)
    while True:
        if (gamesettings.game_active):
            pygame.time.Clock().tick(120)  #120 fps lock
            screen.fill(BLACK)
            showgamestats.blitstats()
            gf.check_events(thepacman, powerpills, gamesettings, orange, blue)
            gf.check_collision(thepacman, blocks, powerpills, shield, ghosts,
                               intersections, showgamestats, gamesettings,
                               fruit, orange, blue)
            for block in blocks:
                block.blitblocks()
            for theshield in shield:
                theshield.blitshield()
            for pill in powerpills:
                pill.blitpowerpills()
            for portal in portals:
                portal.blitportal()
            for ghost in ghosts:
                ghost.blitghosts()
                ghost.update()
                if (ghost.DEAD):
                    ghost.playRetreatSound()
                elif (ghost.afraid):
                    ghost.playAfraidSound(
                    )  # if ghosts are afraid, loop their sound
            for intersection in intersections:
                intersection.blit()
            fruit.blitfruit()
            thepacman.blitpacman()
            thepacman.update()

            if (len(powerpills) == 0):
                gamesettings.game_active = False
                gamesettings.victory_fanfare = True
            if (playIntro and pygame.time.get_ticks() % 200 <= 50):
                mixer.Channel(2).play(
                    pygame.mixer.Sound('sounds/pacman_beginning.wav'))
                pygame.time.wait(4500)
                playIntro = False
        elif (gamesettings.victory_fanfare):
            if (frames <= 120):
                for block in blocks:
                    block.color = ((255, 255, 255))
                    block.blitblocks()
            elif (frames <= 240):
                for block in blocks:
                    block.color = ((0, 0, 255))
                    block.blitblocks()
            elif (frames <= 360):
                for block in blocks:
                    block.color = ((255, 255, 255))
                    block.blitblocks()
            elif (frames <= 480):
                for block in blocks:
                    block.color = ((0, 0, 255))
                    block.blitblocks()
            else:
                gamesettings.game_active = True
                gamesettings.victory_fanfare = False
                thepacman.resetPosition()
                for ghost in ghosts:
                    ghost.resetPosition()
                    ghost.speed += 1
                showgamestats.level += 1
                fruit.fruitReset()
                gf.readFile(screen, blocks, shield, powerpills, intersections)
                frames = 0
                pygame.time.wait(1000)
            frames += 1
        elif (thepacman.DEAD):
            thepacman.deathAnimation(frames)
            frames += 1
            if (frames > 600):
                gamesettings.game_active = True
                thepacman.DEAD = False
                thepacman.resetPosition()
                for ghost in ghosts:
                    ghost.resetPosition()
                frames = 0
                pygame.time.wait(1000)

        if (showgamestats.num_lives < 0):
            #reset game and save score
            screen.fill(BLACK)
            pygame.time.wait(2000)
            gamesettings.game_active = False
            thepacman.resetPosition()
            for ghost in ghosts:
                ghost.resetPosition()
                ghost.speed = 1
            showgamestats.num_lives = 3
            showgamestats.save_hs_to_file()
            showgamestats.score = 0
            showgamestats.level = 1
            fruit.fruitReset()
            playIntro = True  # reset the chime
            gf.readFile(screen, blocks, shield, powerpills, intersections)
            startScreen.makeScreen(screen, gamesettings)

        pygame.display.flip()
# gf.create_block(settings, display_screen, blocks)
# gf.create_pipe(settings, display_screen, pipes)
# gf.create_enemy(settings, display_screen, enemies)
gf.create_entities(settings, display_screen, blocks, pipes, enemies, poles,
                   flags)

# main loop
while True:
    gf.mario_move(mario, settings, display_screen, fireball)
    display_screen.blit(settings.bg_image, settings.bg_position())

    gf.mario_in_range(mario, enemies)
    gf.scroll_eveything_left(settings, mario, enemies, blocks, pipes, poles,
                             flags)
    gf.check_collision(settings, scoreboard, enemies, mario, blocks, pipes,
                       flags)

    scoreboard.update_screen()

    enemies.update()
    mario.update()
    blocks.update()
    blocks.draw(display_screen)
    pipes.update()
    pipes.draw(display_screen)
    poles.draw(display_screen)
    poles.update()
    flags.draw(display_screen)
    flags.update()

    if mario.death: